Reputation: 147
I'm trying to fire a tag in Google Tag Manager only once after some first user interactions, such as mouse click, scroll, key press etc.
I managed it to fire the tag with a proper GTM setup, but now the tag fires every time I scroll or click on the page - and I don't want to fire the tag that often.
Is there a proper solution to do that? Thanks
Upvotes: 0
Views: 5553
Reputation: 11
#1 Set a custom cookie.
#2 Add the custom cookie as a User-Defined Variable.
#3 Create Trigger to run if test_cookie is true.
#4 Create new Tag to do whatever you want once per session. In my case I am showing a modal.
Publish and it should work provided your JS is correct for setting the cookie is is set to expire after each session.
This guy explains how to set cookies in GTM pretty well https://www.analyticsmania.com/post/cookies-with-google-tag-manager/
Upvotes: 1
Reputation: 32760
If you mean only once per page, then you can look in the advanced settings for your tags, where you can choose between "fire unlimited", "once per event" and "once per page", and select the "once per page" setting. Unlimited means it fires on every applicable trigger, "once per event" means if fires on every trigger for a distinct event, and "one per page" means it fires only once for the given url.
If you mean "fire only once per session", then there is no built-in mechanism. You would have to set a cookie (maybe using a custom template for a "create cookie tag", you could fire that in a tag sequence after your one-time tag has fired) and then create an exception trigger that prevents the tag from firing when the cookie is set. However by storing data on the users device (by cookies, local storage or basically any other means) your website has to follow the ePrivacy directive, so check if you have to obtain user consent.
Upvotes: 0