Streaming live at 10am (PST)

How to embed google tracking code for a form button?

Hi All,

I’ve been sent some google code by my clients marketing agency who want to track conversions when a form has been submitted.

How would I go about embedding the code so it works with one of the forms on the site below?

Any help would be really appreciated. This is what I’ve been sent from Google:

  1. Add an onclick attribute directly to the code for the button or link that you’d like to track. The code that you use will depend on how the link or button is displayed on your site: as a text link, button or button image.

Add the code to a button: This code shows you how to add click tracking functionality to a button using the <button> tag. Replace ‘http://example.com/your-link’ with the URL for your website.

<button onclick="return gtag_report_conversion('http://example.com/your-link')">Submit</button>

cheers
David Lewis
1960 Creative


Here is my site Read-Only: Webflow - Steven Hale Watch Restoration 2
(how to share your site Read-Only link)

One option is to add some code to your page settings and give your button a corresponding Id.

document.getElementById('yourButtonId').addEventListener('click',(event) => { 
  return gtag_report_conversion('http://example.com/your-link'
}

Thanks Gail. Where would I include the code as there are several forms I need to be able to add this function? And where it says /your-link is that the page the form is on?

Sorry as I’m not a coder :frowning:

You would add the code in the page settings. For multiple forms you need 1 function per form.

Would definitely recommend you deploy event/conversion tracking via GTM rather than hardcoding events. It’s much more scalable + easy to manage.

Hi, does this look correct?

document.getElementById(‘Tag-Heuer-Send-Message’).addEventListener(‘click’,(event) => {
return gtag_report_conversion(‘https://www.shwr.co.uk/button’}

Sure, but you can only confirm on published site.

Thanks! Yeah, I’m awaiting confirmation from the client that it’s working in Google Analytics.

I seem to be having an issue when I embed the tracking code to my forms.

The problem is the added code seems to disable all previous functions of the form ie. any prompt labels to tell me that I need to fill in that field etc.

Any ideas on how to fix this?