News for hackers. Stuff that matters.
Re:Show HN: Minimal Google Analytics Snippet by davidkuennen on Thursday December 13, 2018 @12:31PM (#18674160)
Created this, cause I hated having to slow down my websites by adding the gigantic Google Tag Manager and Analytics libraries, combined with their randomly slow CDN, just to track some basic page views.
Re:Show HN: Minimal Google Analytics Snippet by onion2k on Friday December 14, 2018 @09:02AM (#18680815)
Both of Google's recommended methods of adding Analytics to a website load Google's JS library asynchronously[1]. Including it has no meaningful impact a site's time to first paint or interactivity.

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

Re:Show HN: Minimal Google Analytics Snippet by shift8 on Friday December 14, 2018 @12:02PM (#18682357)
Really good point and I agree. This was intriguing at first glance because who doesn't want less JS on their site?! Of course! However, missing out on other events being tracked, advanced demographic information(?), and what else?? That's a huge miss - especially if you work with Google Ads and have your Analytics linked. Your ad campaigns won't be as effective and could potentially cost more money to save someone an unknown amount of loading time.

This is pretty creative though.

Re:Show HN: Minimal Google Analytics Snippet by dwild on Friday December 14, 2018 @11:07AM (#18681780)
Wouldn't the 70kb would be most likely already cached too? Which make it even more lightweight than this minimal script.
Re:Show HN: Minimal Google Analytics Snippet by dorgo on Friday December 14, 2018 @01:53PM (#18683462)
My firefox never cache anything. Going forth and back in history always reloads the page. That's the reason I have many tabs open - to prevent reloading and waiting.

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

Re:Show HN: Minimal Google Analytics Snippet by tuananh on Monday December 17, 2018 @02:33AM (#18697464)
no because expiration of google analytics is really low (30m or 2h i think)
Re:Show HN: Minimal Google Analytics Snippet by awirth on Friday December 14, 2018 @10:15AM (#18681327)
<script async> does still block the document onload event from firing until it's been executed.
Re:Show HN: Minimal Google Analytics Snippet by scratchnsniff on Friday December 14, 2018 @10:29AM (#18681463)
What about defer?
Re:Show HN: Minimal Google Analytics Snippet by jopsen on Friday December 14, 2018 @08:04AM (#18680507)
I'm not an expert, just curious... But aren't these files cached on most users computers?
Re:Show HN: Minimal Google Analytics Snippet by jasonkester on Friday December 14, 2018 @08:11AM (#18680546)
Nothing is ever really cached anymore, meaningfully at least.

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.

Re:Show HN: Minimal Google Analytics Snippet by jefftk on Friday December 14, 2018 @09:14AM (#18680902)
For what it's worth, I run a/b tests in my work where I consistently see large caching effects. For example, when we compare an experimental version of something to the currently deployed version it's critical that we cache-bust the control group. And changes that improve caching generally make things significantly better.

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)

Re:Show HN: Minimal Google Analytics Snippet by reaperducer on Friday December 14, 2018 @11:28AM (#18681990)
8mb JavaScript bundles to display their static homepage to a mobile browser that has maybe a couple hundred MB allocated to caching things

Thanks for that. It explains why even on very high-end new phones, switching between complicated web sites in different tabs causes a reload.

Re:Show HN: Minimal Google Analytics Snippet by onlyrealcuzzo on Friday December 14, 2018 @11:16AM (#18681872)
AFAIK, GTM is specifically designed that it can only be cached on your website and it expires every 15 minutes.

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.

Re:Show HN: Minimal Google Analytics Snippet by bzbarsky on Friday December 14, 2018 @10:04AM (#18681239)
It depends. Browsers that care about user privacy and tracking are moving to first-party-isolated caching. So GA will be cached for a user on your site only if the user has visited _your_ site before.
Re:Show HN: Minimal Google Analytics Snippet by niel on Friday December 14, 2018 @08:10AM (#18680540)
analytics.js as served by Google is only cached for two hours.
Re:Show HN: Minimal Google Analytics Snippet by yayana on Friday December 14, 2018 @08:29AM (#18680625)
So a browser checks its hash up to 12 times a day for the surfer who never sleeps, no matter how many sites they visit..

If you are that concerned then your page views should be sent from the server side.

Re:Show HN: Minimal Google Analytics Snippet by C1sc0cat on Friday December 14, 2018 @07:01AM (#18680232)
Compared to all the other stuff that gets puts on websites these days most sites wont notice.
Re:Show HN: Minimal Google Analytics Snippet by spiderfarmer on Friday December 14, 2018 @07:35AM (#18680355)
You're getting downvoted, probably because your comment is whataboutery at best. You're only relevant when you asume someone with a 6Mb homepage is starting with replacing his Analytics code. A usecase that will probably never occur.
Re:Show HN: Minimal Google Analytics Snippet by C1sc0cat on Friday December 14, 2018 @09:37AM (#18681051)
Ah you mean 99.99% of the real websites I consult on then - and those are all major brands.