CMS Development

LHobbs
メンバー

HubSpot Form Listener Not Tracking in GTM

解決

Hi,

 

I have a form embedded on my website and I am trying to send an event when the form loads on my page. 

 

I've added this script to GTM to track when the form has loaded.

 

This is the javascript I am using. Any thoughts on why I wouldn't be seeing when the form has loaded?

 

<script type="text/javascript">
window.addEventListener("message", function(event) {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
    window.dataLayer.push({
      'event': 'hubspot-form-ready',
      'hs-form-guid': event.data.id
     });
   }
});
</script>

 

0 いいね!
2件の承認済みベストアンサー
stefen
解決策
キーアドバイザー | Solutions Partner
キーアドバイザー | Solutions Partner

HubSpot Form Listener Not Tracking in GTM

解決

@LHobbs it could be because the script is running too later (after that event has already happened). For instance, if the google tag manager script is in the footer below the HubSpot form embed.

Stefen Phelps, Community Champion, Kelp Web Developer

元の投稿で解決策を見る

miljkovicmisa
解決策
トップ投稿者 | Platinum Partner
トップ投稿者 | Platinum Partner

HubSpot Form Listener Not Tracking in GTM

解決

Hello @LHobbs , it seems you are using global events for embedded form. Have you tried binding the event directly to the embedded form like explained in this article?

Basically you would do something like this:

hbspt.forms.create({
  portalId: '',
  formId: '',
  onFormReady: function($form) {
    window.dataLayer.push({
      'event': 'hubspot-form-ready',
      'hs-form-guid': 'the form id' //this is also going to be available somewhere in $form
    });
  } 
}); 



If my answer was helpful please mark it as a solution.

元の投稿で解決策を見る

3件の返信
miljkovicmisa
解決策
トップ投稿者 | Platinum Partner
トップ投稿者 | Platinum Partner

HubSpot Form Listener Not Tracking in GTM

解決

Hello @LHobbs , it seems you are using global events for embedded form. Have you tried binding the event directly to the embedded form like explained in this article?

Basically you would do something like this:

hbspt.forms.create({
  portalId: '',
  formId: '',
  onFormReady: function($form) {
    window.dataLayer.push({
      'event': 'hubspot-form-ready',
      'hs-form-guid': 'the form id' //this is also going to be available somewhere in $form
    });
  } 
}); 



If my answer was helpful please mark it as a solution.

stefen
解決策
キーアドバイザー | Solutions Partner
キーアドバイザー | Solutions Partner

HubSpot Form Listener Not Tracking in GTM

解決

@LHobbs it could be because the script is running too later (after that event has already happened). For instance, if the google tag manager script is in the footer below the HubSpot form embed.

Stefen Phelps, Community Champion, Kelp Web Developer
Jaycee_Lewis
コミュニティーマネージャー
コミュニティーマネージャー

HubSpot Form Listener Not Tracking in GTM

解決

Hi, @LHobbs 👋 Thanks for reaching out. Hey, @miljkovicmisa @stefen, do you have any experience or troubleshooting tips you can share with @LHobbs?

 

Thank you! — Jaycee


Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success.
Don't miss this opportunity to connect and grow—reserve your spot today!


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
0 いいね!