1st party cookie and user session/visit activity google tag manager - google-analytics

I am new to GA & GTM. I want to track users session/visit activity like page views,document download etc. whatever activity user performs during the session/visit. In Omniture I do activity using evar variable. How can I do the same with GA & GTM.
Going through the document on internet I tried to do this using 1st party cookie variable in GTM. but it is not working. when i see the value for cookie variable it showing undefined and also for return type.
A

You don't need to set a 1st party cookie as GA will do this itself when you put the tag on the website. Its a lot less setup and has more metrics out of the box than Adobe Analytics. In an aggregated fashion the activites you mention can be tracked via event tracking.
If you are looking to also track this on an individual level, then also set a user custom dimension or the userId parameter unique for each user. This will then be associated with the out of the box metrics as above, that you can access via a custom report.

Logical for your question is:
When users authenticate, the user ID should be stored in dataLayer
When subsequent Universal Analytics tags are fired, the &uid key
should first check if the User ID is in dataLayer
If it is, then a cookie is written in the user’s browser with this
User ID, and finally the value is returned to the tag
If the User ID is not in dataLayer, GTM checks if it’s stored in a
cookie, and if it is, the cookie value is returned
If there is no such cookie, nothing is returned and the User ID
parameter will not get sent
Check this post

Related

User's google calendar ID changes when primary email is updated

Essentially I've noticed that when a user's primary email is updated on their google account, their calendar ID will also change (e.g. ID will change from john#company.com to john_new#company.com).
This is a problem because I work on an application that relies on the calendar ID being a stable identifier for users. For example, lets say user A at a company schedules an event to their calendar through my application. We'll save metadata related to that event in our own database along with user A's calendar ID to denote that the event was scheduled to that calendar. This is important because we use this information to ensure that only users with write access to this calendar ID can edit this event from our application (important for security purposes).
Lets say user A gets their primary email updated, which causes their calendar ID to also change. Now, when I query the CalendarList endpoint to get a list of user A's calendars, I get back the new calendar ID, which makes my application think that user A should not have access to edit the event they just scheduled since that event was scheduled to a calendar ID that user A no longer has access to.
Is there a way around a problem like this? I can't find an endpoint that will return user A's "archived" calendar ID in addition to their new one. More deeply, I don't understand why their calendar ID changes as it feels like IDs should be stable identifiers...
In this case, by testing and working with the calendar API and Google Workspace it's a fact that the Calendar ID will always be the email address of the user account it’s associated with. I wish there was actual documentation but this is only from testing that I have verified this. There are other threads that explain the same, in this case with your situation you should modify your app in a way that the CalendarID is not based in a stable ID, as this depends on your email address.

Send User ID from Google Tag Manager to Google Analytics 4

I have set up google tag manager with my GA4 property
(NOT legacy Universal Analytics)
according to the official guide:
https://support.google.com/tagmanager/answer/6103696?hl=en&ref_topic=3441530#zippy=%2Cweb-pages
and I have figured out how to send custom/recommended events to GA4 using
dataLayer.push({}) objects, using their "event" field in triggers and tags,
based on a Universal Analytics guide
(https://www.analyticsmania.com/post/track-logins-with-google-tag-manager/),
because this appears to be a black hole in the official guide:
https://support.google.com/tagmanager/answer/9442095
only describes, briefly, the GTM-side of the story.
Same goes for sending User ID: the docs only tell
when creating a Google Analytics 4 Configuration tag:
To set a user ID, add a row to Fields to Set.
Set the Field Name to user_id, and the Value to
a Tag Manager Variable that returns the user ID.
and I only take the knowledge from the external UA guides
to use a Data Layer Variable that reads the user_id field from the dataLayer,
and also create a corresponding user_id User Property on Google Analytics,
which in Universal Analytics used to
have related settings that don't exist anymore
(https://www.analyticsmania.com/post/google-analytics-user-id-with-google-tag-manager/).
So I have deployed my GA4 Events with the user_id data layer variable
referenced in their Configuration (and it is visible on the datalayer in Debug View),
created the corresponding User Property in GA, and enabled User-ID reporting.
Yet, in my real-time view, the user_id fields always get some weird "gtm.js" value
(as if my data layer variable value was replaced by the event name
from the default dataLayer.push({event:"gtm.js",user_id:"ignored value")).
What in the world is missing for my user_id field to be recognised?
Thanks!
Thanks #bpstrngr! Was going around in circles for a while before finding your answer.
To clarify the step by step in case anyone else bumps into this;
When sending userId in dataLayer add an event name:
window.dataLayer.push({
'userId' : '{{ myUserId }}',
'event': 'userIdSet',
})
In GTM, create a Custom Event trigger that listens to that event (set event name equal to whatever event you wrote in step 1):
Add this event as a firing trigger into your tag:
So at long last it turned out,
that since the configuration tag was fired by the Page View event,
that happened before I pushed the user_id to the dataLayer,
so it filled the non-existing value with the event name instead.
I gave the user_id event a name to create a custom event trigger,
that re-triggers the configuration tag.
This way the user_id-s are finally visible.

Built-in user-id status is set to "Unassigned" in predefined user id view

If I apply a session-based custom segment defined as user-id status matches exactly "Unassigned" in the standard user-id view the segment is matched by several sessions / users.
Since the user id view should only encompass sessions where the user id is set this shouldn't be the case.
I can't find any proper documentation on how the built-in dimension user-id status gets populated, but I would assume that it is derived from the uid parameter sent with the server calls.
How can the value of dimension user-id status ever be "Unassigned" within the user id view?
Taking the reversed segment defined as status=Assigned there are users that never had a userid assigned to them and are still in the user-id view.
How can user without an assigned userid be part of the user-id view?
Side note:
Implemented via GTM
Session Unification is active
user-id status is a Google-intern dimension automatically created when setting up the userid feature.
Unassigned is not a value GA would set (when a value is not defined in GA it is set to (not set)), **so if it's there it's because someone set it.*
Now with regards to your segment, the question you are asking GA is:
give me users who during ANY session had status=Unassigned
this includes sessions prior to identification because Session Unification is active
So anybody who had status=Unassigned at some point and then identified will match that segment.
If you want to know users who have status=Unassigned as their latest status you want to make sure your custom dimension is set to User Scope and that you replace Sessions Include with Users Include in your filter.

Firebase + Tag Manager: Fetch variable from previously sent event

With the previous version of Tag Manager (dataLayer), it was easy to fetch variables sent within previous events, when those variables weren't sent with the current.
How to persist parameters with the Firebase version of GTM?
For example, previously, I could send an event with a user_id variable at the start of the session or as soon as the user logs in. I would then create a "Data Layer Variable" in GTM and use it to get this user_id at any subsequent point in the session. For instance, to send it as a GA custom dimension on a purchase event possibly made later.
Now, if I push a Firebase event with a custom parameter user_id and then create an "Event Parameter" variable in GTM, it will only be available within this event.
Same if I send a user property with Firebase and register a "Firebase User Property" variable in GTM. I won't be able to use this variable within an event at a later point in the session
Is there a way to persist user properties and event parameters?
Unfortunately, we all miss the data layer like approach.
I got a confirmation that the only way to "persist" data between events using Firebase SDK is to use user properties, which function like "sticky" events within Firebase. Otherwise, the parameter would need to be sent anew with a future event.
Combined with a limitation of only sending string and numbers but not dictionaries makes this a bit less convenient.

Custom metric to track email opens

I am trying to track the number of email opens of a mailing.
This mailing is not personalised, so each receiver will get exactly the same email contents.
So far I have found out that I can add a tracking pixel in the mailing, which will send data to GA that a user opened the mail (images were loaded).
Example code:
<img src=”http://www.google-analytics.com/collect?v=1&tid=UA-XXXXXX-X
&cid=EmailOpenTest&t=event&ec=email&ea=open&el=EmailOpenTest
&cs=newsletter&cm=email&cn=Email&cm1=1″ />
'tid' will be our custom tracking ID.
This all works, as when this link is opened the total number of hits increases.
But my question relates to parameter 'cid'. For testing purposes, I have set this here to "EmailOpenTest". But this should be a random/unique ID per user actually. But as the mailing is not personalised, I wonder if it would be possible to track individual users?
Does this mean I have to include javascript in the mail? Would that even work in all email clients? Or are there other options?
All suggestions are welcome.
Assumption: you are using a mail client like Mail Chimp
Assign a unique id to every email on the email list. lets say this unique id is uid
Create a custom dimension in GA, lets name it as Client Mail Id with index say 1
Create the same pixel just like you have created above in the OP.
Add a custom Dimension in the hit as
http://www.google-analytics.com/collect?v=1&tid=UA-XXXXXX-X
&cid=EmailOpenTest&t=event&ec=email&ea=open&el=EmailOpenTest
&cs=newsletter&cm=email&cn=Email&cm1=1&cd1=uid
In place of uid, you actually need to pass the mail list unique id for that email
How it will work
Once the user sends this hit, your unique id will be recorded in custom dimension 1.
Generate a custom report in GA with event category=email & event action=open and add a dimension custom dimension 1.
All the id's displayed there have actually opened the email ;)
PS: It's tried and tested, so won't cause any issue. Also if you don't want to use custom dimensions, you can also send this id in event label or event value
PPS: In any mail client, getting unique value for that email is pretty easy. You can actiually use its position number or add another column for the unique id, then grab that id win the template
The cid is the clientId, an identifier that is used to aggregate pageviews into sessions, and sessions into unique users.
The way to use that in email-tracking would be to capture the client id when a user subscribes to your newsletter and then insert it into the email links. Since your mails are not personalized this will not work.
If you use a random ID you will not be able to link the request from the mail to an existing user. So one way to deal with the problem would be to ignore it - using a constant userId would still give you an event count (the unique events metric might be a little of if users click the link multiple times within a session lifetime).
If for some reason you absolutely need to track these as different users you can set up a redirect - do not send data to ga directly from your mail, instead call a script on your server that inserts a random clientId and then sends the data to Google.

Resources