Show HN: Minimal Google Analytics Snippet
minimalanalytics.com
minimalanalytics.com
There's a good argument to say loading 70Kb of JS you're not using is a bad idea, and if that's the case then your smaller script is an improvement, but there's also a good argument to say Google Analytics is powerful and useful and maybe you should be using the features that those 70Kb give you in order to improve you site in ways the user would notice. I guess it's down to your specific use case.
[1] https://developers.google.com/analytics/devguides/collection...
This is pretty creative though.
about.cache says:
Number of entries: 418
Maximum storage size: 30720 KiB
Storage in use: 12698 KiB
Storage disk location: none, only stored in memory
We're in an age where websites happily serve up 8mb JavaScript bundles to display their static homepage to a mobile browser that has maybe a couple hundred MB allocated to caching things. Sure, it may be there if you immediately load another page on that site (and the devs aren't using a bundler that serves a different 8mb next time).
But if they leave and come back, they'll get the same full download experience.
Caching effects are much smaller on Safari with its per-domain cache, but even there if something broke caching for us it would be a high priority to fix.
(I work at Google on ad tags)
Thanks for that. It explains why even on very high-end new phones, switching between complicated web sites in different tabs causes a reload.
This is because your UAID is part of the URL to download the GTM snippit.
The old-school analytics.js file can be cached, though.
Someone correct me if this isn't true.
If you are that concerned then your page views should be sent from the server side.
Sad to see that Tag Manager and the currently tracking JS are big enough to force website owners to compromise.
In other surveilance news, I've been adding Matomo[1] for web analytics to my site for the first time. Used to be called Piwik? It's free/selfhostable web analytics, which is more than enough for small projects and landing pages.
I've been pleasantly surprised with how it works so far, but I had to write some code to trigger it in the right part of my react-router initialization.
[1] https://permanent.cloud/apps/matomo
(and its cool I'm not helping Google spy on people who visit and help me out)
window["_gaUserPrefs"] = { ioo : function() { return true; } }
I used CRX Viewer extension by Rob Wu[1] to just look up the extension code in Chrome store.[1] https://github.com/Rob--W/crxviewer#chrome-extension-source-...
Interstingly, copying/pasting the code into https://www.minifier.org/ gains 69b of savings, but https://jscompress.com/ shows an error: `Invalid regular expression: /+/: Nothing to repeat (line: 3, col: 48)`
Would you expect Google's API to change often? My biggest concern with something like this is their /collect endpoint changing and analytics data stops being tracked.
So I think they won't change it or just add a different version with the old version still working.
ga('set', 'anonymizeIp', true);
> SyntaxError: nothing to repeat
The line seems to be this:
> return l?l[2]?decodeURIComponent(l[2].replace(/+/g,' ')):void 0:void 0},
Might it be related to AdBlock? I'm using Firefox with AdBlockPlus, Cookiebro and the default Privacy settings turned up in Firefox.
Edit: oops, it's clearly coming from the regex: /+/g → /\+/g
If users spend a bit of time navigating your site, you might get better caching by adding this to your JS file and caching for longer.
This seems to me like one real problem that is pretty trivial to fix leading to a lot of over tuning for some kind of ideal.. and then being stuck if you need to support anything else.
Now using navigator.sendBeacon if available (not even GA does that by default yet), ability to track events and ability to track exceptions.
All of that by keeping it tiny.
So I think it's a totally legit way to use GA, since you don't always have the ability to add libraries. For example if you want to track GA server side.