google-analyticsgoogle-tag-manageruniversal-analyticsconversion-tracking

Fire Event once per session - Implementation problems


Please I'm looking to set up tags on GTM to fire only once per GA session. However, I'm unable to do so.The tags end up firing multiple times in the same sessions.

Would appreciate it if anyone can help.

Many Thanks :)


Solution

  • So let's assume you have two conditions, that have to be checked for a session to be high quality. What I would do ist create a session cookie (see https://www.analyticsmania.com/post/cookies-with-google-tag-manager/), that contains a stringyfied object:

    {
    "condition 1": "true", //has been fullfilled
    "condition 2": "false",//has yet to be fullfilled
    "event_fired": "false"//flag to fire event only once per session
    }
    

    Whenever a user acts in a way, that should update this cookie, you fire a custom HTML Tag, that reads & updates it. If all conditions are met and the key "event_fired" equals "false", the tag also executes a dataLayer.push event, that you can use to trigger an event, that marks the session as high quality. In addtion to the dataLayer.push event, the HTML Tag then sets "event_fired" as "true" - thus preventing the dataLayer.push event to be executed again.