Skip to main content
  1. Blog Post/

How to track an intranet or an hybrid app

2 min · 618 words
Table of Contents

As we all know (do we?) Google Analytics uses cookies in order to work. This is, if for some reason the cookie can't be set it won't give any error but hits won't be fired at all. A cookie is usually set for a FQHN (Fully Qualified Host Name). So if for example we're going to track our intranet and we access it using an URL like : http://intranet/ Google Analytics is likely not going to work (it will depend on the browser that is accessing the page.

There's another situation where we may have problems using the official analytics.js. For example when using a different protocol than http/https, an example of this if when we load an html file from the local file system ( file://index.html ). You may think this is not a usual way to access a webpage, but it's the way the most Hybrid Apps work.
A native app for a mobile is usually build using some wellknown web technologies like: HTML5, JavaScript and CSS, and uses a browser engine (not the browser itself) to load the main content locally (using the file:// protocol), and here we'll hit the second issue, Universal Analytics has an internal task named checkProtocolTask, it basically aborts the request if the current protocol does match http/https.

Another example of devices using html files loaded from the local filesystem will be the SmartTV's  for example.

Fortunately Universal Analytics gives us the possibility to change those behaviours in order to manage those situations.

Tracking a non FQHN domain name

Even if it may work for some domains we better assure that it will run for all browsers, for this we need to set cookie's domain to 'none' ,

ga('create', 'UA-XXXXXXX-YYY','none'});

or

ga('create', 'UA-XXXXXXX-YYY', {'cookieDomain': 'none'});

Tracking a locally loaded page

In this case we'll need to set the storage engine to none, and disabling the protocol check:

   ga('create', 'UA-123123123-123',{
      'storage': 'none', 
      'clientId':'{{UUIDv4}}'
  });
  ga('set', 'checkProtocolTask', null);
  ga('set', 'appName', 'MyApp Name');
  ga('set', 'appVersion', '1.2.2');
  ga('send', 'appview', {
        'screenName': 'My Home Screen'
  });

Let's take to the 2 important line in the code above;

'storage': 'none'

This line disables the default cookie storage system, and set's it to none.

 'clientId':'{{UUIDv4}}'

As we have disabled the storage engine, we'll need to manually set the clientId (the cid parameter within our hits) , usually most devices offers a way to gan Unique Identifier, or we could grab the mac address and convert it to a UUIDv4 value :)

  ga('set', 'checkProtocolTask', null);

This last line disables the protocol checking task, so the requests are not aborted because it doesn't match the http/https protocols.