In the course of the increased implementation of consent tools on websites, the question arises for the hoped-for consent case of how to achieve a subsequent assignment of the source of the visit if consent is only given on a subsequent page after entry. For this purpose, the referrer and URL of the initial page are usually stored. But how do you transfer the stored data to Analytics later?
Most consent tools offer a callback function that is executed when consent is given, denied or the settings are changed. In the case of consent, most Google Analytics users strive to attribute the session to the correct source, if possible, before tracking the current or subsequent pages. For this purpose, the URL of the entry page is relevant, for example, because parameters here can influence the attribution to a source (Click IDs from Google Ads, Bing, or other systems) or an affiliate, etc. The referrer can also contain relevant information or, in the case of an incoming link, determine from which domain a visitor arrived at one’s own site.
Save entry information
In the simplest case, a small script like this one is sufficient, e.g. to store the data in a session cookie, if this has not happened yet (so it can be executed on all pages). Note: Instead of the complete URL of the landing page, this script only saves the path and possibly parameters to pass them to Analytics as “page” instead of “referrer” but in the end, this is more or less a matter of taste.
Subsequent transfer via Google Tag Manager
In the case of the Google Tag Manager, the stored data can be used in accordance with these instructions or you can forego a custom task and simply trigger an Analytics tag intended specifically for the subsequent first-page call via the callback function of the Consent Manager with a page call in which the page and referrer fields are filled with the stored values. The values come from the cookie or sessionStorage or, for example, the dataLayer when stored in the session. For example, if you read the cookie values from the script above, which is simply played out as an HTML tag on all pages via GTM, you can see that the fields for such a separate tag are filled with the values.
An event written in the dataLayer in the callback of the Consent Tool serves as a trigger, for example. It is only important that this fires before further hits are sent or the page is reloaded with active tracking.
Sending the subsequent page call in case of direct implementation.
If Google Analytics is implemented directly in the page as Universal Analytics or gtag.js tracking code, the subsequent page call of the first page is passed in the Consent Callback by reading in the cookie values and processing them as fields on page call, just as in the case of the Tag Manager.
Differing from the normal tracking code, the referrer must be set from the cookie before the pageview is sent. The page view gets as a parameter the path of the entry page (also from the cookie). Using the above function to read a cookie value.
That’s it “already”. How and at what point the transfer of the first-page call is implemented depends entirely on the options offered by the Consent Manager used. Here (hopefully) the documentation of the respective provider will help. With that: Good luck with the implementation! If you have any questions, please do not hesitate to contact us.