MauricioRobayo / nextjs-google-analytics

Google Analytics for Next.js
MIT License
515 stars 48 forks source link

[Feature Request] Would you consider using PartyTown to load the gtm script? #282

Open carlos-algms opened 1 year ago

carlos-algms commented 1 year ago

To get better performance and higher Lighthouse scores, it is possible to delegate the third-party scripts to web workers.

That's where PartyTown comes into place.

https://partytown.builder.io/nextjs

MauricioRobayo commented 1 year ago

Hello @carlos-algms , this is a great idea. Let's leave the issue open to see if it gathers some traction, and if so, I'll be happy to work on it or let anyone else do it.

M1ck0 commented 1 year ago

This should definitely be done, as the script will be offloaded to the service-worker on a different thread.

+1

SushiWaUmai commented 1 year ago

I think this is not really necessary, since Next.js scripts already have experimental support for PartyTown.

https://nextjs.org/docs/basic-features/script#offloading-scripts-to-a-web-worker-experimental

Edit: I just found out that we need to change some things in order for partytown to communicate with google analytics, so there needs to be some minor changes in order for it to work with webworkers.