Firebase + Tag Manager: Fetch variable from previously sent event - firebase

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.

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.

sending offline measurment data - does cid have to match the original cid?

I need to send a cart status update based on an offline activity. My customers will add items to their cart online via the website but the final checkout and purchase happen offline.
Here is my question: In the example below, a checkout step is updated. Does the client_id provided in this step have to match the original client_id used when the web user started their cart originally?
Measuring Checkout Options
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
**&cid=555 // Anonymous Client ID.**
&t=event // Event hit type
&ec=Checkout // Event Category. Required.
&ea=Option // Event Action. Required.
&pa=checkout_option // Product action (checkout_option).
&cos=2 // Checkout step.
&col=FedEx // Checkout step option.
Client ID is how Google Analytics tracks each individual user throughout their multiple sessions. So, yes- if you want that payload to be associated with the same user, then the CID will need to match- otherwise you'll be artificially inflating your user count (as well as severing the contextual data from that user).
You can parse the cookie that GA stores in the browser to obtain the CID and then fill it there. Not sure what language you're writing in, but there are plenty of snippets out there for parsing the GA cookie. You could also store the CID when it is initially generated in your own session data to be used later while offline. For example:
ga(function(tracker) {
var clientId = tracker.get('clientId');
console.log(clientId);
});
You could also provide your own CID from the start that you generate yourself and tell Google Analytics to use. This might be overkill for your situation, but I wanted to mention it as an option.

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

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

Google Analytics: How to associate an event with an individual session

I have a variable that's being laoded on my page and then being reported back to GA via the event tracking api. Is there a way for this "event" to be associated with the flow of an individual session?
For example: If I have a variable that gets reported as "eligible", can I then associate this event with the session and page flows?
Yes, you can create an advanced segment. That is a way to filter sessions (visits) according to certain criteria. In this case, your criterion would be "Include: Event Label = 'the name of the label of your event'".
Note that it is against the terms of use of GA though to report data on an indidivual basis, i.e. it is not allowed to create an event label that allows you to identify each single session.

Resources