analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Usage with Partytown

Open oddnavy opened this issue 2 years ago • 3 comments

Has anyone explored using analytics.js with Partytown? It can significantly improve performance by moving third-party analytics tools off the main thread.

It would be cool to run Google Analytics / Facebook Pixel / other tools in Partytown whilst using analytics.js. It looks like it should be possible, but I'm interested to know if anyone has tried it.

oddnavy avatar Oct 14 '22 00:10 oddnavy

somewhat related https://github.com/DavidWells/analytics/issues/46#issuecomment-991750249

kylemh avatar Oct 19 '22 21:10 kylemh

People have requested this in the past. https://twitter.com/larsbuur/status/1516788082967822349

I'd love to see if this would work or not. Have at it!

DavidWells avatar Oct 20 '22 00:10 DavidWells

Obviously, one way it can be done is like so:

(assuming you have enabled the experimental feature in your next.config file):

<Script src="https://unpkg.com/analytics/dist/analytics.min.js" strategy="worker" />

but then you'd opt into automatic versioning and need do a lot of conditional code around the relevant global.

kylemh avatar Oct 20 '22 14:10 kylemh