Hi ALL, I thought I would post the solution I ended up with because it's in response to @salih question around gtag and I really struggled with this for a while... Guessing a few folks have also. This is an elegant fix, that doesn't use tag template edits Firstly... Passing clientID into GA through the mapping tool is always problematic, because on first page view on a new browser/client, the GA call needs to generate both the clientID and issue a pageview at the same time. Therefore requesting the clientID (or lifting it from the cookie) is an issue, because this information is only available after the first pageview. It needs to occur internally within the tag generated call. HOWEVER, using the mapping is also the fix for this situation AND any GA generated values that needs to be passed to Custom Dimensions/Metrics with the tag generated hit (pageview/event or other), see https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets (for background) The fix goes like this; If you are using Audience Stream, you will need to surface the clientID to the datalayer anyway. My recomendation is to do this with the first party cookie element in the Datalayer, use this script to acquire the raw clientID if ( b.hasOwnProperty("cp._ga") ) {
b.ga_cid = b["cp._ga"].split(".")[2]+"."+b["cp._ga"].split(".")[3];
} PRO: asside from first pageview, the cookie is already browser-side, and can be executed straight away. CON: on first pageview, this script wouldn't execute (cookie won't be present yet). However, I'll post a cookie listener in this thread that solves this, AND I've timed getting the id from the GA object over cookie generation and they are within 30ms of each other. Even if you don't need the clientID for any other solution, I would still encourage you to collect it in the datalayer anyway (as we at least need a placeholder for the mapping). For the sake of this example, let's call it "ga_cid" (use something that supports you naming convension). Now, in the Google Analytics (gtag.js) Tag, go to Data Mappings and select the "ga_cid" variable, and press select destination Select Dimensions from the Category list in left column. For ClientID we will select All Page Hits from the Event Type drop down NOTE: You can use this method for other internal GA vars, and may scope the beacon type differently here Select the Dimension number you choose to fill NOTE: If you need to fill a number higher than 20, select the last option and manually edit the result at top, after you have pressed +Add For the name, you must type clientId (case sensitive). NOTE: The Tealium tag template places this string in the custom_map object within the gtag object, and even though it will create a corresponding key/value pair for it in gtag, Google ignores it for the internal var called 'clientID'.... This is the magic of this solution :-) Save, publish, beer o'clock!
... View more