Thursday , March 13 2025

On_sent_ok not working in Contact Form 7

If your site uses the old version of WordPress and the Contact Form 7 plugin, it is enough to use the code in the Advanced settings tab:

on_sent_ok: "yaCounterXXXXXXXX.reachGoal('mygoal');"

Where XXXXXXXX is the counter ID in Yandex Metrika, mygoal is the name of the goal that was previously created in Yandex Metrika.

For the Contact Form version 5+, the old method does not work, and you need to use the following code:

<script type="text/javascript">
  document.addEventListener(
    'wpcf7mailsent',
    function(event) {
      yaCounterXXXXXXXX.reachGoal('mygoal');
    },
    false);
</script>

Similarly, XXXXXXXX is the counter id in Yandex Metrika, mygoal is the name of the goal that was previously created in Yandex Metrika.

Edit and place this code in header.php or footer.php in your website theme folder.

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

How to remove 404 //fonts.gstatic.com and //fonts.googleapis.com from WordPress head section

I tried solutions with functions that should remove from head and , but a very …

Leave a Reply

Your email address will not be published. Required fields are marked *