Reporting & Analytics

markv
Membre | Partenaire solutions Gold
Membre | Partenaire solutions Gold

Tracking multiple Hubspot forms on a single page through Tag Manager

Résolue

I recently used this tutorial to set up form tracking via an event listener through GTM: https://www.3whitehats.com/knowledge/tracking-hubspot-forms-google-tag-manager/

 

I'm now at a point where I need to differentiate between 2 forms on one page. With the current set-up, a tag fires on both a standard contact form submit and a newsletter sign up. Anyone deal with this issue before/have any tips?

0 Votes
1 Solution acceptée
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Tracking multiple Hubspot forms on a single page through Tag Manager

Résolue

Welcome, @markv.

 

You can modify the Custom HTML Tag with a JavaScript conditional statement to distinguish between the two form guid values:

 

<script type="text/javascript">
  window.addEventListener("message", function(event) {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
    	if (event.data.id == 'CONTACT-FORM-GUID-HERE') {
    		window.dataLayer.push({
        		'event': 'event-for-contact-form',
        		'hs-form-guid': event.data.id
     		 });
    	} else {
    		window.dataLayer.push({
        		'event': 'event-for-newsletter-signup',
        		'hs-form-guid': event.data.id
     		 });
    	}
    }
  });
</script>

Replace CONTACT-FORM-GUID-HERE with your contact form's guid. If you're not sure how to find it, check out this article.

 

Hope this helps!

Isaac Takushi

Associate Certification Manager

Voir la solution dans l'envoi d'origine

0 Votes
3 Réponses
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Tracking multiple Hubspot forms on a single page through Tag Manager

Résolue

Welcome, @markv.

 

You can modify the Custom HTML Tag with a JavaScript conditional statement to distinguish between the two form guid values:

 

<script type="text/javascript">
  window.addEventListener("message", function(event) {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
    	if (event.data.id == 'CONTACT-FORM-GUID-HERE') {
    		window.dataLayer.push({
        		'event': 'event-for-contact-form',
        		'hs-form-guid': event.data.id
     		 });
    	} else {
    		window.dataLayer.push({
        		'event': 'event-for-newsletter-signup',
        		'hs-form-guid': event.data.id
     		 });
    	}
    }
  });
</script>

Replace CONTACT-FORM-GUID-HERE with your contact form's guid. If you're not sure how to find it, check out this article.

 

Hope this helps!

Isaac Takushi

Associate Certification Manager
0 Votes
markv
Membre | Partenaire solutions Gold
Membre | Partenaire solutions Gold

Tracking multiple Hubspot forms on a single page through Tag Manager

Résolue

This works great! Thanks!

0 Votes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Tracking multiple Hubspot forms on a single page through Tag Manager

Résolue

Glad I could help, @markv!

Isaac Takushi

Associate Certification Manager
0 Votes