DavidWells / analytics

Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors
https://getanalytics.io
MIT License
2.39k stars 241 forks source link

Usage with Partytown #328

Open oddnavy opened 1 year ago

oddnavy commented 1 year ago

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.

kylemh commented 1 year ago

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

DavidWells commented 1 year ago

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!

kylemh commented 1 year ago

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.