The FPID
cookie is what server-side Google Tag Supervisor would like to make use of on your Google Analytics 4 monitoring.
It’s a cookie set within the HTTP response from the server, and it’s flagged as HttpOnly
, which implies it’s solely accessible by an internet server working on the area on which it was set.
There’s nothing incorrect with the know-how, and I do advocate that server-side setups toggle it on by default.
Nevertheless, there may be instances the place you need the server-side GA4 shopper (which handles the incoming GA4 requests) to sometimes not use the FPID
cookie. Maybe it’s as a result of you will have a customized consent system in place, or maybe you need some GA4 measurement IDs to make use of the common JavaScript cookies and others to make use of the FPID
.
On this brief article, I’ll present you how one can conditionally stop the GA4 shopper from setting or accessing the FPID
cookie.
X
The Simmer E-newsletter
Subscribe to the Simmer e-newsletter to get the newest information and content material from Simo Ahava into your e-mail inbox!
Tip 136: Conditionally stop SGTM from accessing the FPID
cookie
Observe! If you happen to’re utilizing Google’s consent mode, then
FPID
entry is robotically prevented when consent shouldn’t be granted foranalytics_storage
.
The operational logic is straightforward. If the worth of the Identify discipline within the Server-managed cookie settings of the GA4 shopper is ever empty (clean string), then the shopper will not write the FPID
cookie within the HTTP response, nor will it entry an current FPID
cookie to generate the client_id
worth for outgoing GA4 requests.
So the trick is to conditionally set it to clean everytime you don’t need GA4 to set or entry the FPID
cookie. In Google Tag Supervisor, conditional logic is managed by variables.
Instance utilizing the GA4 measurement ID
Usually, you’ll need the identical GA4 shopper to deal with the info streams for a number of totally different GA4 measurement IDs.
However maybe you need solely a few of these to make use of FPID
and others to maintain on utilizing the JavaScript cookie _ga
. There are situations the place this is smart. For instance, if you happen to’re utilizing Measurement Protocol to ship some hits to an information stream, it would make sense to maintain utilizing the _ga
cookie worth, as a result of the server-set Shopper ID can have unpredictable values if the Migrate from JavaScript Managed Shopper ID possibility is enabled.
Whatever the purpose, setting this up requires a brand new Lookup Desk variable in server-side GTM. That is what it might appear to be:
Right here you possibly can see that if the incoming request has the GA4 measurement IDs G-123456789
or G-ABCDEFGHI
, the variable returns the string FPID
.
For all different measurement IDs, the variable returns an empty string (the worth of the Default Worth discipline).
The {{Request MID}}
variable is a Question Parameter variable, which fetches the worth of the &tid
question parameter from the incoming request (that is the place the measurement ID worth is held in GA4 streams):
Within the Server Cookie Settings of the GA4 shopper, we will then make the most of the Lookup Desk because the Identify of the server cookie:
This fashion FPID
will solely be set and accessed for the 2 measurement IDs listed above. For every other ID, server-side GTM will not make use of FPID
for setting the Shopper ID.
You possibly can prolong this instance simply by changing the {{Request MID}}
with another variable that returns FPID
when the cookie must be accessed and a clean string in different situations. For instance, you would use the Question Parameter or the Cookie Worth variable sorts to test if a customized consent parameter or cookie is about, by which case the clean string could be returned and no cookies could be set or accessed by the GA4 shopper.
I hope this trick is beneficial to these of you who need to exert this kind of management over server-side Google Tag Supervisor.