Stuifbergen.com

Analytics & Growth Hacking

  • About
  • Contact
  • Professional Services

Find me here

  • Mastodon (social)
  • Mastodon (measure)
  • No more Twitter
You are here: Home / Blog / Detecting Incognito Mode and using it in Google Tag Manager

Detecting Incognito Mode and using it in Google Tag Manager

16 June 2016 by jules 10 Comments

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?

fawkesBrowsing 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

Related posts:

Catch exit-intent with a Google Tag Manager trigger GTM testing logoReview and demo of GTMtesting.com Default ThumbnailSet up A/B tests using the Google Tag Manager Properly Analyze A/B Test results with Advanced Segments

Filed Under: Blog Tagged With: Google Tag Manager, howto, Javascript

Comments

  1. Pedro Magalhaes says

    20 June 2016 at 11:53

    So its not possible to track custom dimensions in GA using the default code? Tnx.

    Reply
    • jules says

      20 June 2016 at 13:36

      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.

      Reply
  2. Pedro Magalhães says

    20 June 2016 at 14:03

    Nice tips, thanks. Was this code tested in major desktop and mobile browsers? Regards

    Reply
    • jules says

      21 June 2016 at 15:04

      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/

      Reply
  3. Gilly says

    30 May 2017 at 08:52

    Very helpful post! Would you mind sharing as well the configuration for the trigger as I’m having issues setting it up?

    Reply
  4. Benoit Mobibot says

    6 February 2018 at 13:03

    Hi, after more than one year. Is this still working on other browser than Chrome ?

    Reply
    • Benjamin says

      20 April 2018 at 15:50

      Seems so, I am testing it now and it gives back browsers like Chrome, Firefox or Edge.

      Reply
      • Lior says

        1 October 2018 at 12:51

        That’s weird because for me (just months later) it only Detects Chrome.

        Reply
  5. Philippe Côté-Léger says

    20 September 2018 at 17:37

    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.

    Reply
  6. Pablo says

    23 May 2021 at 16:51

    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

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • How to use a pre-hashed email address in GA4 tags in GTM
  • GA4 intraday exports and cookieless pings
  • July 2024 change in collected_traffic_source in GA4 Big Query
  • srsltid parameter, GA4 and Big Query
  • Smart incremental GA4 tables in Dataform

Need help?

  • Contact me

Search

© Copyright Jules Stuifbergen · Powered by Genesis ·