How to track an intranet or an hybrid app

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'});


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', 
  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.


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.



Author: David Vallejo

Google Analytics Consultant and implementer. I have some experience with Google Tag Manager Follow me: @thyng

2 thoughts on “How to track an intranet or an hybrid app”

  1. En un reciente proyecto de medición de una app para SmartTV me ha sucedido exactamente lo mismo. Por si ayuda y dado lo sencillo de medir las interacciones con este tipo de apps (screens y eventos básicamente), opté por usar Google Tag Manager. Eso sí. Los hits a Google Analytics los envío con el protocolo de medición y en vez de la cookie es sencillo acceder mediante el SDK que facilitaba en este caso Samsung, a un indentificador único del usuario basado en la mac del dispositivo.
    El resultado a primera vista funciona bien, y eso de tener un contenedor de GTM dentro de una app la verdad parece buena idea.
    ¿Qué opinas?
    Y gracias por compartir.

Leave a Reply

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