Blog, Website & Page Publishing

Ryan_G_Thompson
Participant

CTA (Beta) GTM Tracking

Hi,

 

I've recently started using the new CTAs (Beta) to replace our existing hubspot marketing pop-up form.

 

After building the new pop-up, I'm dismayed that it seems completely untrackable in GTM.

 

I've tried using the Hubspot form submission listener and a few other ideas but so far I haven't been able to push anything into the data layer.

 

Any help would be greatly appreciated.

16 Réponses
sbinkley
Participant

CTA (Beta) GTM 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:



  1. Create a Custom HTML Tag in GTM:
    • Go to the Tags section in GTM.
    • Click New and select Tag Configuration.
    • Choose Custom HTML.
  2. Add the Following Script to the Custom HTML Tag:

 

 

<script>
(function() {
  function trackInteractiveButtons() {
    var buttons = document.querySelectorAll('.interactive-button');
    buttons.forEach(function(button) {
      button.addEventListener('click', function() {
        window.dataLayer = window.dataLayer || [];
        window.dataLayer.push({
          event: 'hubspot-button-click',
          'button-class': 'interactive-button',
          'click-url': button.href
        });
        console.log('Interactive button clicked:', button.href);
      });
    });
  }

  // Initial call to track buttons present at page load
  trackInteractiveButtons();

  // MutationObserver to track dynamically added buttons
  var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
      mutation.addedNodes.forEach(function(node) {
        if (node.nodeType === 1 && node.classList.contains('interactive-button')) {
          node.addEventListener('click', function() {
            window.dataLayer = window.dataLayer || [];
            window.dataLayer.push({
              event: 'hubspot-button-click',
              'button-class': 'interactive-button',
              'click-url': node.href
            });
            console.log('Interactive button clicked:', node.href);
          });
        }
      });
    });
  });

  observer.observe(document.body, {
    childList: true,
    subtree: true
  });
})();
</script>
​

 

 

  • Set the Trigger for All Clicks:
    • 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!

0 Votes
sbinkley
Participant

CTA (Beta) GTM Tracking

0 Votes
RLeo
Contributeur | Partenaire solutions Diamond
Contributeur | Partenaire solutions Diamond

CTA (Beta) GTM Tracking

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?

0 Votes
TomM2
Conseiller clé | Partenaire solutions
Conseiller clé | Partenaire solutions

CTA (Beta) GTM Tracking

Hi all! I just created a new feature request in the ideas forum here! If this would be useful to you please give it an upvote 🙂 

Tom Mahon
HubSpot Expert | Digital Marketing Specialist | Community Champion
HubSpark

Book a meeting

Did my post help answer your query? Help the community (and me) by marking it as a solution.


PamCotton
Gestionnaire de communauté
Gestionnaire de communauté

CTA (Beta) GTM Tracking

Thank you for sharing @TomM2 just upvoted!

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


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




0 Votes
melissachowning
Participant | Partenaire solutions Platinum
Participant | Partenaire solutions Platinum

CTA (Beta) GTM Tracking

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? 

TomM2
Conseiller clé | Partenaire solutions
Conseiller clé | Partenaire solutions

CTA (Beta) GTM Tracking

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
HubSpot Expert | Digital Marketing Specialist | Community Champion
HubSpark

Book a meeting

Did my post help answer your query? Help the community (and me) by marking it as a solution.


melissachowning
Participant | Partenaire solutions Platinum
Participant | Partenaire solutions Platinum

CTA (Beta) GTM Tracking

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. 

0 Votes
TomM2
Conseiller clé | Partenaire solutions
Conseiller clé | Partenaire solutions

CTA (Beta) GTM Tracking

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
HubSpot Expert | Digital Marketing Specialist | Community Champion
HubSpark

Book a meeting

Did my post help answer your query? Help the community (and me) by marking it as a solution.


Ryan_G_Thompson
Participant

CTA (Beta) GTM Tracking

Hi Tom, thanks but where does this class occur? On email submission based pop ups like the one I've screenshotted I couldn't locate this class.

Screenshot 2023-06-13 at 4.28.41 pm.png

0 Votes
TomM2
Conseiller clé | Partenaire solutions
Conseiller clé | Partenaire solutions

CTA (Beta) GTM Tracking

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"

 

TomM2_0-1686655387461.png

 

Tom Mahon
HubSpot Expert | Digital Marketing Specialist | Community Champion
HubSpark

Book a meeting

Did my post help answer your query? Help the community (and me) by marking it as a solution.


Ryan_G_Thompson
Participant

CTA (Beta) GTM Tracking

No luck Tom, I tried creating this trigger and still nothing happened upon submission.

Ryan_G_Thompson_0-1687083922361.png

 

0 Votes
TomM2
Conseiller clé | Partenaire solutions
Conseiller clé | Partenaire solutions

CTA (Beta) GTM Tracking

@Ryan_G_Thompson it looks like you have double "_" characters in between the words, is that the case? It should just be one in between each word. 

Tom Mahon
HubSpot Expert | Digital Marketing Specialist | Community Champion
HubSpark

Book a meeting

Did my post help answer your query? Help the community (and me) by marking it as a solution.


0 Votes
Ryan_G_Thompson
Participant

CTA (Beta) GTM Tracking

@TomM2 I was following the exact convention you were using above:


@TomM2 wrote:

It looks like the submit button on these forms is "hs-form__actions__submit"


Upon inspecting the element you were indeed correct that the double "_" characters is used for this button class.

Ryan_G_Thompson_0-1687266235671.png

 

TomM2
Conseiller clé | Partenaire solutions
Conseiller clé | Partenaire solutions

CTA (Beta) GTM Tracking

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
HubSpot Expert | Digital Marketing Specialist | Community Champion
HubSpark

Book a meeting

Did my post help answer your query? Help the community (and me) by marking it as a solution.


0 Votes
PamCotton
Gestionnaire de communauté
Gestionnaire de communauté

CTA (Beta) GTM Tracking

Hello @Ryan_G_Thompson Happy Friday!

I want to invite our top experts to this conversation, @Ben_M, and @alyssamwilie any recommendations to @Ryan_G_Thompson?

 

Thank you,

Pam

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


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