BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.88k stars 427 forks source link

Partytown throws errors when GTM script is integrated #330

Open JoeLim13 opened 1 year ago

JoeLim13 commented 1 year ago

This is the GTM script I integrated:

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>

and partytown throws errors as below:

Screenshot 2022-12-22 at 9 08 40 PM
jonathan-dejong commented 1 year ago

Hi!

Your issue isn't actually GTM itself but that you're loading in other third party services through it that wont work or needs extra work.

I (and some others) found that Hotjar does not work with Partytown. Facebook Pixel needs a reverse proxy to work, and I'm guessing the same then goes for Google ads (not tried that one myself).

So to run GTM through Partytown you'd need to:

Note: I'm not a dev on this project, just another user

JoeLim13 commented 1 year ago

Hi @jonathan-dejong, thanks for replying! May I know how to move other third party services out of GTM? I was given this GTM script, should I modify the script?

jonathan-dejong commented 1 year ago

No you would remove those tags from within the Google tag Manager interface. Then you would add the scripts you removed in some other way. For example by placing them in an appropriate file location in your website codebase. However if you aren't comfortable with that I'd recommend hiring a developer or not using Partytown for GTM.

I've now implemented Partytown on two of our client sites and it really is not a plug-and-play thing. Make sure you're up for the challenge if you want to play with it ☺️