How to Detect and Track Incognito Users with Google Analytics and Google Tag Manager

Google Analytics Incognito Browser

Depending on the type of website you are working with, it is likely that some percentage of your users are using their browser in incognito or private mode.

Since using incognito mode can skew the numbers you see in analytics, it is really good to know the estimated percentage of visitors that prefer to stay incognito.

What kind of implications does incognito mode cause?

  • Inaccurate user count – every session is a new user
  • Inaccurate sessions per user count – incognito users will always have only one session
  • Broken A/B testing logic – users in incognito are likely to see different variation every time they visit
  • Broken promotions – users are likely to see “only once” popups and other elements in every session

Tracking incognito users in Google Analytics

Unfortunately, browsers don’t have a default solution for detecting whether users are in incognito or not. Nor are they making it easy to figure it out using custom Javascript.

For every browser, the solution is a bit different and they might be changing when a new version of the browser is released. We are doing our best to keep this post up to date.

Here’s the Google Tag Manager setup that we are using to track incognito visitors to Reflective Data blog.

Google Tag Manager custom HTML tag

Name: Detect Incognito Browser

Type: Custom HTML

Trigger: All Pages

Code:

<script>
(function (cb) {
    var db,
    on = cb.bind(null, 'true'),
    off = cb.bind(null, 'false')

    function tryls() {
        try {
            localStorage.length ? off() : (localStorage.x = 1, localStorage.removeItem("x"), off());
        } catch (e) {
            // Safari only enables cookie in private mode
            // if cookie is disabled then all client side storage is disabled
            // if all client side storage is disabled, then there is no point
            // in using private mode
            navigator.cookieEnabled ? on() : off();
        }
    }

    // Blink (chrome & opera)
    window.webkitRequestFileSystem ? webkitRequestFileSystem(0, 0, off, on)
    // FF
    : "MozAppearance" in document.documentElement.style ? navigator.serviceWorker ? off() : on()
    // Safari
    : /constructor/i.test(window.HTMLElement) || window.safari ? tryls()
    // IE10+ & edge
    : !window.indexedDB && (window.PointerEvent || window.MSPointerEvent) ? on()
    // Rest
    : off()
})(function (isPrivateMode) { window.dataLayer.push({event: 'detected_incognito', is_incognito: isPrivateMode}); });
</script>

Credit: This code is a slightly modified version of the snippet posted on Stack Overflow by the user Endless.

Works in the following browsers:

  • Chrome
  • Firefox
  • Safari
  • IE 10+
  • Edge

Google Tag Manager Data Layer variable

Name: DLV – Is Incognito

Data Layer Variable Name: is_incognito

Data Layer Version: Version 2

Google Tag Manager Is Incognito Data Layer Variable
Google Tag Manager Is Incognito Data Layer Variable

Google Tag Manager Custom Event trigger

Name: CE – Detected Incognito

Event name: detected_incognito

This trigger fires on: All Custom Events

Google Tag Manager Detected Incognito Custom Trigger
Google Tag Manager Detected Incognito Custom Trigger

Google Tag Manager Google Analytics tag

Name: UA – Is Incognito Browser

Type: Event

Category: browser_info

Action: incognito

Label: {{DLV – Is Incognito}}

Non-Ineraction Hit: True

Google Tag Manager Is Incognito Browser Tag
Google Tag Manager Is Incognito Browser Tag

Bonus: sending data to a custom dimension

The previous setup sends incognito usage info to Google Analytics as a custom event. In some cases, having it as a custom dimension could be more useful. Here’s how you set that up.

  1. Go to Admin panel of your Google Analytics account
  2. In property settings, choose Custom Dimensions under Custom Definitions
  3. Add a new Custom Dimension

Name: Is Incognito
Scope: Session

Now, remember the index your newly created dimension has. In our case, it is 12.

Modify your Google Tag Manager tag “UA – Is Incognito Browser” to include a Custom Dimension and set its value equal to {{DLV – Is Incognito}}.

Google Tag Manager Is Incognito in a Custom Dimension
Google Tag Manager Is Incognito in a Custom Dimension

Using this in reports

Congratulations! If you did everything correctly, you will soon see data about incognito users flowing into Google Analytics.

There are several ways how you can include this data in your reports but perhaps you will find using it in custom segments the most useful. This allows you to see how regular vs incognito users perform based on any metric you track in Google Analytics.

Also, you could build all kinds of custom reports. Here’s a very basic one that’s good for testing if your setup works as expected.

Incognito vs Regular Users Custom Report Setup
Incognito vs Regular Users Custom Report Setup

And here’s how it will look like.

Incognito vs Regular Users Custom Report Results
Incognito vs Regular Users Custom Report Results

As we can see from the custom report above, our demo site received 794 sessions, out of which 4.3% came from browsers turned into incognito mode.


That’s it – now you have information about users that have turned their browser into incognito or private mode and how big impact they might have on your metrics and A/B testing program.

If you have any questions or ideas for improvement, please let us know in the comments below.

6 thoughts on “How to Detect and Track Incognito Users with Google Analytics and Google Tag Manager

    1. Hello,

      Unfortunately, we haven’t found a working solution for Google Chrome, yet.

      Will update the post as soon as we manage to find one.

Leave a Reply

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

Sign up for Reflective Data

5,000 sessions / month ×

Please enter your email

Submit

After submitting your email, we will send you the registration form.