Successfully Tracking HubSpot Interactive CTA Buttons with GTM
Hello everyone,
I wanted to share a solution that worked for me in tracking HubSpot’s new interactive CTA buttons using Google Tag Manager (GTM). I noticed that many of us are struggling with getting these buttons to fire the correct tags, especially since they are dynamically loaded.
After some trial and error, I found that using a MutationObserver to detect these dynamically added elements and attach event listeners to them was effective. Here's the detailed solution:
Attach this Custom HTML tag to trigger on all click; then target "click classes: interactive-button".
If you have other dynamically loaded elements or different classes, you can adjust the script accordingly. (Such as "hs-image-widget" for the image based CTAs, etc.)
I hope this helps others facing similar issues. Upvote if it worked for you! Happy tracking!
Successfully Tracking HubSpot Interactive CTA Buttons with GTM
Hello everyone,
I wanted to share a solution that worked for me in tracking HubSpot’s new interactive CTA buttons using Google Tag Manager (GTM). I noticed that many of us are struggling with getting these buttons to fire the correct tags, especially since they are dynamically loaded.
After some trial and error, I found that using a MutationObserver to detect these dynamically added elements and attach event listeners to them was effective. Here's the detailed solution:
Attach this Custom HTML tag to trigger on all click; then target "click classes: interactive-button".
If you have other dynamically loaded elements or different classes, you can adjust the script accordingly. (Such as "hs-image-widget" for the image based CTAs, etc.)
I hope this helps others facing similar issues. Upvote if it worked for you! Happy tracking!
hey @sbinkley this looks fantastic. I tried to deploy this code, but with no success. Maybe i am missing out on something, would you mind sharing couple of GTM screenshots ? 🙂
I gave this a try but I believe it may only apply to CTA buttons (which I've never used). I've been using the Pop-up form on Hubspot which still seems untrackable through GTM, although other users have reported having more success using the custom HTML CTA solution.
Hello, we are having the same issue aswel. Im trying to listen for the onBeforeSubmit event but as others confirmed, the form is on an Iframe so listening for the events is not possible.
How can we listen to these events on the new CTAs with forms?
We're struggling with this as well and the HubSpot support team hasn't been able to help us yet either. The first suggested solution referred to injecting an event listener into the iframe, but this does not work if the parent window and iframe are hosted on different domains (which is the case here. iframe domain is 4038620.hs-sites.com). We think the iframe is the issue. Is there a solution in the works for this?
Ah! I didn't know the new tool is loaded in an iframe, that's why GA isn't picking it up then. Unfortunately that would mean it's not possible to target it with GA. A workaround might be to us custom URLs with UTM parameters as the submission/redirect urls on these ctas https://support.google.com/analytics/answer/1033863?hl=en#zippy=%2Cin-this-article
Tom Mahon Technical Consultant | Solutions Engineer | Community Champion Baskey Digitial
Unfortunately, that presents an unideal user experience as the reader would be redirected away from the page/content they are reading onto a 'thank you' page. The ideal UX is that the user can submit their email and continue reading on the page they are on.
It's a major bummer with the new CTAs. We want to be able to track traffic source, page, etc., in GA, but it seems at the moment, we cannot.
Hey @Ryan_G_Thompson it looks like the new CTA beta uses the class "interactive-button" for it's buttons, have you tried setting up an event to track clicks based on this class?
Tom Mahon Technical Consultant | Solutions Engineer | Community Champion Baskey Digitial
Looks like you're right for the forms, that class I mentioned is just on the button pop-ups. It looks like the submit button on these forms is "hs-form__actions__submit"
Tom Mahon Technical Consultant | Solutions Engineer | Community Champion Baskey Digitial
Ah! My apologies! Hmm, that's about as far as I can think of without having access to the tools to troubleshoot to be honest! I don't see any reason why GA wouldn't trigger on these classes.
Tom Mahon Technical Consultant | Solutions Engineer | Community Champion Baskey Digitial