Need to Add Code for Google Enhanced Tracking for Google Ads

Hi there,

I am working with Google Support to get Enhanced Tracking set up on our Hubspot landing pages to work with our Google Ads account.

Below is the code that needs to be installed within the footer of our “Thank You” landing page; however, Google support mentioned that we need to replace ‘yourEmailVariable’ with whatever our email variable is. I am wondering if someone could advise on what the email variable would be that I need to input here? I have tried contact.email but that is not correct.

<script>
dataLayer.push({
‘event’:‘form_submit’,
‘enhanced_conversion_data’: {
“email”: ‘yourEmailVariable’ // get User email dynamically //
}
})
</script>

Hi @Cpuller ,

This can be easily achieved by changing your form embed code. The form embed code is shown when you publish your form.

It has an callback function available that is triggered when you submit the form. You can use that to push your data to the dataLayer.

It should look something like this:

hbspt.forms.create({

portalId: ‘’,

formId: ‘’,

onFormSubmitted: function($form) {

dataLayer.push({
‘event’:‘form_submit’,
‘enhanced_conversion_data’: {
“email”: $(‘input[name=“email”]’).val()

}
})

}

});

If you do not use jQuery, try this instead: document.querySelector(‘input[name=“email”]’).value instead of: $(‘input[name=“email”]’).val()

I am using the form on a Hubspot landing page, so how would I make the edit?

Would someone from the Dev team be able to call me to walk me through this?

Thanks so much,

Hi @Cpuller ,

It’s probably best if you contact HubSpot support from your portal for this.

Here is an alternative solution:

You can set personalization tokens in the URL of the page you are redirecting.

So if you change your redirect URL to something like this: Example Domain}

This allows you to do this in your script:

<script>
dataLayer.push({
‘event’:‘form_submit’,
‘enhanced_conversion_data’: {
“email”: {{request.query_dict.email}}

}
})
</script>

You can add the above script to your landing page by editing the page, navigating to the ‘Advanced options’ and posting it in the footer.

Hey Teun -

I implemented the alternate solution and just tested the form submission and noticed that it is showing the email on URL after submission but not the correct email id.

Do you have any suggestions for this?

Hi @Cpuller! I’m running into the same issue. I think that the email variable is the same thing as the internal name of the contact property. Going to be trying this on my end. Thanks!

Let me know if it works for you and, if you don’t mind, sharing the code you used :slightly_smiling_face: I am still having trouble with it showing the correct email id.

Sure! “Google Tag Manager URL” should be the URL unique to you.

And my internal name for emails was just “email” so that’s why you see that near the bottom. Hope this helps!

<script async src=“Google Tag Manager URL”></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’,‘AW-948930476’, {‘allow_enhanced_conversions’:true});
</script>

<script>
var enhanced_conversion_data = {
“email”: ‘email’,
};
</script>