Google Conversion Tracking

Formidable Forms Google Conversion Tracking

  • January 22, 2019
  • Code
  • 0 Comments
  • melissaSpiegel

Implementing conversion tags to track clicks on a website as conversions can be tricky.  Follow the instructions below for a site a using WordPress and Formidable forms.

1. The first part is simple, add the conversions code to the header between the opening and closing head tags <head></head>

2.  Install the event snippet on the page that has the button or link you’d like to track. Open the header to the theme you are using and use is_page() function.

<?php if (is_page(294)){
//id of specific page you want to track for example my contact page has the id 294
?>
<!-- Event snippet for Contact Form Submission 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': 'XX-somenumber', 'event_callback': callback }); return false; } </script>	
  
<?	
} ?>

3. Installing tracking on a specific button using WordPress plugin formidable forms. Use add action hook to add HTML to the submit button.  The tricky thing here is the quotation marks.  Be sure to change example.com to the URL you are tracking conversions for.

add_action('frm_submit_button_action', 'googleTracking');
function googleTracking($form){
  if($form->id == 2){ //change 5 to the ID of the form you would like this inserted in
  $link = "'https://example.com/contact/'"; 
  echo 'onclick="return gtag_report_conversion(' . $link . ');"';
    
  }
}

 

 

 

melissaSpiegel