1

I'm trying to introduce Google Analytics in a sort of desktop app that all loading files are done through file:// not http or localhost (because most of the time it works offline). Any attempt to track app uses with Google Analytics or Google Tag Manager wasn't work.

For example, I've used:

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'checkProtocolTask', null);
ga('set', 'checkStorageTask', null);
ga('send', 'pageview');

As explained here (adding ga('set', 'checkStorageTask', null); ) with no results.

Has anybody deal with this situation?

Community
  • 1
  • 1
RFG
  • 2,880
  • 3
  • 28
  • 44
  • You need to set an explicit page as well, and might want to use localStorage for user identity tracking. I tried to detail all aspects in an answer on a different question: https://stackoverflow.com/a/47251006/1090166 – Cedric Reichenbach Nov 12 '17 at 16:18

1 Answers1

4

I run a very quick test. ga('set', 'checkStorageTask', null); did nothing for me, instead I found it necessary to set storage to none on tracker creation (which makes sense, since you cannot set cookies with the file protocol). This also means that you probably won't have session tracking, since each hit generates a new ID.

ga('set', 'checkProtocolTask', null) seems necessary - else the debugger complains (naturally) that file is not a valid protocol.

After that data was sucessfully sent, but did not show up in the realtime view. I suspected that maybe the reporting engine does not like the file protocol and set the "location" field with a correct protocol. So I ended up with:

  ga('create', 'UA-XXXXXX-5' , {'storage':'none'});
  ga('set', 'checkProtocolTask', null);

   ga('send', 'pageview' , {'location' : document.location.href.replace('file','http') });

and that displayed in the realtime reports. This was a real quick test, so you need to verify this independently. Notice that you do not need to set a cookie domain (the "auto" argument in your code example) since you cannot set a cookie in any case (there is no domain to set the cookie to).

Also if you work offline for most of the time GA will not work (you need to load the analytics.js file and you need sent calls to the tracking server), but then you are probably aware of that.

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
  • `since you cannot set cookies with the file protocol` it does not have to be truth, e.g. in android webview it is possible to store cookies on file:// protocol thanks to `CookieManager.setAcceptFileSchemeCookies(true)` it is possible for each app because each app has own cookie storage for file:// protocol. Another interesting info is that with new GA4 properties (G-XXXXXXXX) there is no aleternative to `ga('set', 'checkProtocolTask', null)` so for GA4 it is not possible to track file:// protocol (so far?). GA4 is new and is missing many many features from GA3 (Universsal Analytics) – mikep Dec 07 '20 at 10:31