How to Add Google AdWords "Event Snippet" to Pro's Email Form

I’m using Pro’s Email Forms to capture leads coming through from Google AdWords, and trying to add an event snippet from Google to track a lead capture/email submission. I can’t find anywhere to add the necessary code. Any help would be appreciated, thanks. I’ve attached a screenshot from the Google AdWords instructions on the snippet itself, which I’ll also add here:

<!-- Event snippet for Lead Capture conversion page
In your html page, add the snippet and call gtag_report_conversion when someone clicks on the chosen link or button. -->
<script>
function gtag_report_conversion(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
      window.location = url;
    }
  };
  gtag('event', 'conversion', {
      'send_to': 'AW-795522347/vX7wCIe_rIsBEKvqqvsC',
      'event_callback': callback
  });
  return false;
}
</script>

Hi there,

Please install and activate the child theme then add this code in the functions.php file of the child theme:

add_action('wp_head', 'add_code_header');

function add_code_header() { ?>
    <!-- Add the code here -->
<?php }

Hope this helps.

1 Like

Thank you. Two questions: first, I don’t see anything in your code that would specify that it applies to the Email Form I’ve installed on the homepage and that the event snippet should be tied to, so I don’t know how to call gtag_report_conversion when the email submit button is pressed.

And Second, I’m not sure where to start and stop the code paste into your code from Google’s script: do I start/stop it at bracket/script/bracket or function?

Thanks again.

Hey Rob,

For your 1st question, yes, it does not apply to the Email Form. But, it is the first step. That snippet @Jade gave will output code inside the <head></head> as per the instruction given by Google.

The calling of gtag_report_conversion function is different and was not provided in your post and screenshot. The instruction could be found at https://support.google.com/google-ads/answer/6331304?co=ADWORDS.IsAWNCustomer%3Dtrue&hl=en

You can’t however follow that exact instruction for the Email Form’s button because there is no interface to add attributes to it like onlick. What you could do instead is use the button’s selector in a script to call the function. To see how to do that, please watch the screencast at https://youtu.be/KezQ0G8Ihfg

For your 2nd question, you just need to change the <!-- Add the code here --> line with all of your code. Just be sure to copy all parts of the code to avoid errors. If you’re still having trouble with this part, please see this additional guide at https://kinsta.com/knowledgebase/add-code-wordpress-header-footer/

Please just note that this requires developer level knowledge and this has the potential to break your site or might be a cause of frustration because the code won’t work. With that said, it’s strongly recommended that you consult with a third party developer to do this for you because we do not have support for custom integrations.

Hope that helps and thank you for understanding.

1 Like

Thank you, I understand. I appreciate the help, and if I can’t hack it together I’ll call in some pros.

You are most welcome. :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.