In my GTM site, I need to fire a tag only after entire page completely loaded in my website which is SPA.
I have created on JavaScript variable:
And created Trigger:
And tagged this trigger to my tag. But tag is not firing.
Do I need to configure in a different way to fire a tag?
Not sure what exactly is wrong with your setup but this seems like re-inventing the wheel. You can use built-in triggers DOM Ready or Window Loaded
Related
I have a page with a lot of links. I would like to determine if it is worth keeping all of them or removing those that users don't click on. So I would like to see what links are clicked on a page. Is this possible without Google Tag Manager?
You can set an event on click on each link with code in page, without GTM, so you can use i.e. a JavaScript function onclick.
See the documentation for event syntax (for gtag.js): https://developers.google.com/analytics/devguides/collection/gtagjs/events
I have an id being pushed to my data layer via dataLayer.push() and there is no event key at the moment.
I know the best practice is to use an event key like 'event': 'idPush' and then in Google Tag Manager UI, have a trigger that activates when the custom event idPush occurs.
Is there is a way that I can still get the trigger to activate upon seeing a generic 'Message'?
I can't be 100% sure because I haven't read the GTM source code and I couldn't find any articles that talk about this, but I'm reasonably certain that this can't be done.
I tried:
creating a Custom Event trigger with a regex match of .* which would match anything, including nothing.
matching undefined, because according to the preview pane, the _event variable is set to undefined for Message events.
Unfortunately neither of these worked, and preview mode just says No tags were evaluated for the Message. This leads me to think that GTM only checks to see if any triggers should fire when an event is pushed into the dataLayer.
No. Until there was an event, GTM does not know about the content of the message - the message is just the debugger telling you that something has been added to the global dataLayer variable (which exists in the global namespace of the browser, not the confined namespace of GTM). The even is what updates GTM's internal state to make it aware of changes and additions to the dataLayer.
Depending on your use case you might be able to use a trigger type that creates it's own event - e.g. setting a visibility trigger to an element that you know will be at the viewport after your message, which will then take the new values of the dataLayer into account. Or create a custom HTML tag with a setInterval functions that periodically pushes an event to the dataLayer.
While these solutions may work, I do not think they are actually good. Finding a solution to change your page code will almost certainly be less headache in the long run than using a workaround.
I am so confused,
I let front-end developer put the GTM tracking script,
then I want to do "dataLayer.push" things,
Am I still need to talk front-end developer:
"please put this: [dataLayer.push(...)] code when the user clicked the buttons, thanks."
I am not sure GTM platform can push/update the dataLayer array or I still need to talk front-end developer to do this code...
thanks,
Terry
There are various triggers provided to you in GTM that won't require a developer to add additional code to the page.
For your specific example, you'll create a "click trigger" based on the CSS class (this is just one way of doing this) of the button and attach it to an GA Event tag with the event category, action and label you desire.
I have a javascript code for pushing an event with diffrent action to data layer for google tagmaneger.In google tag maneger i have a tag for google analytic with my custom event and all action.Which is working very good.But now i want to create another tag with same custom event but this time with only one specific action.but my both tag is firing for same time.event with specific action also firing .I will be very appreciate for a good answer.
You can use trigger exceptions.
Essentially if the trigger is TRUE/Will trigger, it will prevent the tag from triggering.
If you provide more information on exactly what you want to trigger on, event names, etc I can provide more implementation details.
I need to keep track of CSS class change with GTM (GA behind).
Of course I could fire a javascript event and take this as a trigger. But then I would have to deploy new code.
So is there a way to track certain CSS classes when they appear after the "DOM ready"-event?
You always need a GTM event (i.e. a push to the dataLayer with the key "event" and an event as value) to trigger tags in GTM (also variables in GTM will only be updated as response to a GTM event).
If you do not want to deploy new code via conventional means you can set up a custom html tag that uses a function wrapped in a setInterval call (or possibly uses mutation observers, which I think can track changes to attributes) to check if the class has changed and then pushes an event to the datalayer that you can respond to.
So yes, there is a way, but it is certainly more elegant (and better for performance) to add the datalayer.push to the function that changes the CSS class.
If the problem is doing a code push, you can adda a tag like the "Dom Change Listener" described in this tutorial
https://www.simoahava.com/analytics/google-tag-manager-dom-listener/
You may want to change the part that checks for the change from "display" to whatever change you need to react to.