Google Analytics in Atom Shell


Hey all,

I managed to figure out an Evil Hack to get Google Analytics to work in the renderer process of Atom Shell, despite it being a file:// URL. Hope it’s useful for everyone:


Looks cool, but doesn’t this prevent anyone else from using the same URL for GA? Can the shell.local href be changed (sorry haven’t done much atom shell yet)


I don’t believe so because they don’t share the same client token. If you’re worried about it though, it doesn’t actually matter, you can set that URL to any valid (i.e. parses properly) HTTP / HTTPS URL. The important part is that it appears to GA as not a file:// URL.


This is super helpful! I modified your script to support persistence of cookies in localStorage, so analytics providers don’t think every request is from a new user.


Nice, that’s awesome


Hello @hstove,

Can you please explain how to use Google analytics along with electron-cookies? I have included electron-cookies and added default GA tracking code and its reporting a new visitor every time I open the app.

Also, what should I set as default URL in analytics dashboard?



Slap me on the wrist for bumping a dead thread (if such a thing exists any more), but I thought I’d share my solution here, as I’ve been having trouble with this recently too (I almost dove into the Measurement Protocol). I found a few bits lying around in the analytics.js documentation indicating how to both swap out cookies for local storage and ignore file:

This is all entirely ripped from Google’s own tomes, the one change is specifically setting a.src to include https:

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

var GA_LOCAL_STORAGE_KEY = 'ga:clientId';

ga('create', _id, 'auto', {
   'storage': 'none',
   'clientId': localStorage.getItem(GA_LOCAL_STORAGE_KEY)

ga(function(tracker) {
   localStorage.setItem(GA_LOCAL_STORAGE_KEY, tracker.get('clientId'));

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


Hey, thanks for this! I’ve been searching for a working solution for this also.

Pardon the dumb question, but I’m guessing _id is a local var that represented your actual tracking id? (i.e. UA-12345678-6)


Correct, I’m building an app across both Electron and Cordova, so I have an Angular module handling all my analytics stuff with a function passing in my tracking ID, so if I ever have to change it, I only have to change it in one place.


In google analytics, ‘real time’ still gives me nothing, so I have added this line
ga(‘set’, ‘location’, ‘’);
now it works well :smile:


Ah, yes. My code snippet sets it all up, but doesn’t do any page view or event calls.

My app is an Angular SPA, so I’m only ever running that snippet once, then doing page calls for each view separately.


I created a library for this purpose nwjs-analytics, any help is greatly appreciated :smile:


hi everyone, I’m one of the devs for Neutrino Metrics, an analytics solution for electron apps.
It is in beta right now. Would love to hear your thoughts on it!

#14 Wonderful timing. I am trying to release a public beta of an app I’ve been working on and this seems worth a try. I’ll drop a line with any feedback or question I have.


Hi all!
For those looking for an alternative to GA and the now defunct Neutrino, I built a simple analytics solution for Electron, Nucleus. Along with basic analytics it supports offline tracking and custom events. Feedback welcome :slight_smile: