Mobile app version of vmapp.org
Login or Join
Tiffany637

: How does GTM work and why aren't events firing? I have Google Tag Manager set up on a website and want to manually trigger an event when a button is clicked (by manually I mean from Javascript).

@Tiffany637

Posted in: #Analytics #EventTracking #GoogleTagManager

I have Google Tag Manager set up on a website and want to manually trigger an event when a button is clicked (by manually I mean from Javascript).

All tutorials say that pushing into the dataLayer variable will result in the event being recorded, however I don't see any requests made in the Network tab, so I don't think that's working.

My code is simple:

jQuery('.sign-up-action').on('click', function (e) {
dataLayer.push({'event': 'signup-btn-click'});
});


After clicking the button, dataLayer does have a new item, but since I don't see a request made to the GTM servers, I don't believe the event is saved.

Please note that I don't have access to the GTM admin panel, so I can't really check.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Tiffany637

1 Comments

Sorted by latest first Latest Oldest Best

 

@Hamm4606531

[I'll only speak to the event handling aspect of GTM, but you can find many more resources about GTM in general]

How come you are not doing this with the built in click listener (and possibly setting your trigger to fire when the Click Classes variable equals sign-up-action)? That may be easier than having to push to the dataLayer.

But anyway, if you absolutely must use a dataLayer push, then read on. Part of how GTM works is by listening for certain things to happen via the dataLayer such as clicks, link clicks, page loads, form submissions, and custom events. When any of these happen, an event gets pushed into the dataLayer, eg. gtm.dom for when the DOM has loaded, or gtm.click when the mouse is clicked on the page, or in your case when the signup-btn-click event gets pushed. When any event happens via the ever-magical dataLayer, GTM can react and fire off tags. In your case, you have defined the custom event, but you haven't defined the tag to fire yet. So what you'll need to do is to create a new event tag, populate it with appropriate event parameters, and, here's the key part, enable it to fire based on a trigger of signup-btn-click. This last part is important. And that's all there is to it. Once you've done that, you can add other fancy parameters to the tag, like custom dimensions or metrics and such.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme