Missing referrer with cookie-consent tools

Modified on Mon, 31 Oct 2022 at 12:40 PM

Retrieving referrer data after user has given consent

If a cookie-consent tool is used correctly it usually means that no tracking code (aka: 'TAG') is allowed to run at all when a visitor visits the site for the first time.

That also means that all information about the source of the visit is lost.

Why? The source of the visit is only kept by the visitor's browser once, for instance the source could be Facebook, or Google Ads, or a newsletter.

So, when a visitor agrees (or not) to the cookie statement, the webpage may reload and then use the analytics tracking code. In that case the referrer (where the traffic comes from) is the website itself as that is the previous page, showing as 'Undefined'.

There's a lot of analytics detail lost in that case.

Snoobi has built a specific code snippet that maintains the referrer data. It works unrelated to any tracking code, is automatically removed on a next click or next page.

It means we can analyse referrer data even when the cookie-consent tool doesn't run any tracking code initially.

In order to handle this, you will need to add this to the cookie consent function.

if(document.referrer && sessionStorage.getItem('__snbref')===null ) 
{ window.sessionStorage.setItem('__snbref',document.referrer)}

The exact implementation on your website may be different due to differences in cookie consent tools. 

Snoobi can be consulted when needed to assist in implementing.
Updated: October 2

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article