神刀安全网

Detecting Incognito Mode and Using It in Google Tag Manage

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.

What is incognito mode?

Detecting Incognito Mode and Using It in Google Tag Manage 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!

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Detecting Incognito Mode and Using It in Google Tag Manage

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址