QwikDev / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. šŸŽ‰
https://partytown.qwik.dev
MIT License
13.09k stars 437 forks source link

[šŸž] CORS error for Google Tag Manager Service Worker #635

Open brandonfredericksen opened 3 weeks ago

brandonfredericksen commented 3 weeks ago

Describe the bug

I'm getting the following CORS error when using Partytown and Google Tag Manager.

Access to XMLHttpRequest at 'https://www.googletagmanager.com/static/service_worker/4al0/sw_iframe.html?origin=https%3A%2F%2Fwww.url.com' from origin 'https://www.url.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

image

Error happens in production as well.

Current implementation:

<Partytown
  debug={false}
  forward={['dataLayer.push']}
  loadScriptsOnMainThread={[
    'https://googleads.g.doubleclick.net/pagead/viewthroughconversion',
  ]}
/>

I'm using Remix. I've tried adding the url to the loadScriptsOnMainThread without success:

<Partytown
  debug={false}
  forward={['dataLayer.push']}
  loadScriptsOnMainThread={[
    'https://googleads.g.doubleclick.net/pagead/viewthroughconversion',
    'https://www.googletagmanager.com/static/service_worker', // doesn't work
  ]}
/>

Reproduction

private

Steps to reproduce

Use Partytown with Google Tag Manager

Browser Info

Chrome

Additional Information

No response

andreja-migles-sm commented 2 weeks ago

Having the same issue.

jrood commented 2 weeks ago

Indeed, when gtm.js tries to create this iframe, Partytown seems to be proxying this behavior and doing something else (perhaps requesting the iframe src) instead. Since, this src matches loadScriptsOnMainThread, I would expect Partytown to allow gtm.js to create the iframe in the dom normally, but it does not.

Even if Google were to return cors headers for sw_iframe.html or if this is mitigated with a reverse proxy, I anticipate another issue. Google's code within this iframe seems to be attempting to register a service worker itself, and I'm not sure if Partytown will allow this type of service worker inception.

jrood commented 1 week ago

It's also not clear if sw_iframe.html is even necessary. Tags still seem to load without it.

tcp2 commented 3 days ago

@jrood The page_view data collected from Google Analytics, originating from Facebook, has decreased by half.