Here’s a great addition to your bag of tricks: a custom HTML / Javascript Tag to detect if a visitor is browsing your site in anonymous or incognito mode.
Update: this turns out to be very Chrome specific. I will dive into this more deeper. If you have additions yourself, please leave a reply or tweet to @zjuul
What is incognito mode?
Browsing Incognito, or Private mode allows you to visit a website as normal, with the exception that your browsing software tries to wipe all permanent information from your computer after the session is done.
- It doesn’t leave any cookies
- Browser history is not stored
- Caching is disabled
Very useful if you are shopping for gifts for your spouse on a shared computer and you don’t want to spoil the surprise by being retargetted ;-)
Why should I care?
Users browsing incognito come and leave without cookies, so you cannot measure loyalty (return visits), and its essentialy fruitless to try to retarget them for anything. They will definitely not be recognised again when they re-visit your site.
For some sites, this analytics problem might be bigger than for others, but it’s always nice to know how big the potential problem is.
How to detect it?
This answer on stackoverflow learned me that the window.RequestFileSystem function exists, but returns an error in incognito mode. Which is great, so we can use the error-handling bit of that function to fill the dataLayer.
A useful thing to do e.g. is to fire a Google Analytics non-interactive event that also sets a custom session dimension, so you can easily make an advanced segment or custom report in Google Analytics.
Here’s the code. Put this between <script> tags in a custom HTML tag, and a few milliseconds later, a dataLayer event is filled, which you can use as a trigger to fire any other tag you like.
var fs = window.RequestFileSystem || window.webkitRequestFileSystem; if (!fs) { // no such function, ignore } else { fs(window.TEMPORARY, 100, function(fs) { dataLayer.push( { 'event': 'browsermode normal' }); }, function(err) { dataLayer.push( { 'event': 'browsermode incognito' }); } ); };
Questions, additions, tip?
Please leave a reply to this post or send a tweet to @zjuul – much appreciated. Like it? Please share, thanks!
[bctt tweet=”How to detect browsers that are in incognito mode. #measure #gtm – with code snippet” username=”zjuul”]
Photo credit: https://flic.kr/p/bysUmx
Pedro Magalhaes says
So its not possible to track custom dimensions in GA using the default code? Tnx.
jules says
In general, it is. In this case, however, the detection of incognito mode is too slow to use in a Custom Javascript variable for easy inclusion in the pageview tag (as Custom Dim).
In the code I posted, there is an custom event trigger you can use in an event tag. In this event tag, you can fill a custom dimension.
Pedro Magalhães says
Nice tips, thanks. Was this code tested in major desktop and mobile browsers? Regards
jules says
The code is tested and executes without errors.
However.. the requestFileSystem call is nor per se available in all browsers. It’s not W3C standard. https://www.w3.org/TR/file-system-api/
Gilly says
Very helpful post! Would you mind sharing as well the configuration for the trigger as I’m having issues setting it up?
Benoit Mobibot says
Hi, after more than one year. Is this still working on other browser than Chrome ?
Benjamin says
Seems so, I am testing it now and it gives back browsers like Chrome, Firefox or Edge.
Lior says
That’s weird because for me (just months later) it only Detects Chrome.
Philippe Côté-Léger says
Thank you for this!
For an affiliate website in a personal niche, it’s important to know the % of visitors that use private browsing. Those 30-days cookies won’t do any good for your affiliate commission when the visitor is in private browsing, the sale has to occur in the same browsing session.
Pablo says
Hey,
Is there anything you can do to combat this? If not I don’t see a purpose to track something just to track it.
Thanks,
Pablo