How to set `ga_session_id` with google tag manager (gtm)?
@vinnie
To set ga_session_id
with Google Tag Manager (GTM), you can create a custom JavaScript variable that retrieves the session ID and then use that variable in your tags.
Here are the steps to set it up:
1 2 3 4 5 6 7 8 |
function() { // Generate a new session ID if one doesn't exist if (!sessionStorage.getItem('ga_session_id')) { var sessionID = Math.random().toString(36).substr(2, 16); sessionStorage.setItem('ga_session_id', sessionID); } return sessionStorage.getItem('ga_session_id'); } |
Now, whenever the tag fires, it will include the ga_session_id
value generated by the custom JavaScript variable. Make sure to test your implementation to ensure the variable is being set correctly.