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.85k stars 426 forks source link

[๐Ÿž] Fetch failed loading: POST https://www.google-analytics.com/g/collect?v=2 #470

Open tcetin opened 9 months ago

tcetin commented 9 months ago

Describe the bug

We are trying to load and trigger google tag manager events by using partytown. It doesn't trigger the gtm events. It is implemented in NextJS.

Here is the configuration in _document.tsx

<Partytown
                        debug
                        logCalls
                        logGetters
                        logSetters
                        logImageRequests
                        logMainAccess
                        logSendBeaconRequests
                        logStackTraces
                        logScriptExecution
                        forward={["dataLayer.push"}
                    />

Here is the google tagmanager script:

<script
                type="text/partytown"
                dangerouslySetInnerHTML={{
                    __html: `
                    (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','tag-manager-id');`
                }}
            />

I tried to find the issue by debugging. I am just able to see this log:

partytown-ww-sw.js:1611 Fetch failed loading: POST "https://www.google-analytics.com/g/collect?v=2..."

Reproduction

We reverted it on the prod. We test it locally.

Steps to reproduce

Browser Info

Chrome

Additional Information

No response

gioboa commented 9 months ago

Thanks for opening this issue. I will try to spin up a NextJS app to reproduce the issue

tcetin commented 9 months ago

It seems the same issue happens on the https://partytown.builder.io/google-tag-manager .