Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐞] CORS error for Google Tag Manager Service Worker #635

Open
brandonfredericksen opened this issue Oct 31, 2024 · 6 comments
Open

[🐞] CORS error for Google Tag Manager Service Worker #635

brandonfredericksen opened this issue Oct 31, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@brandonfredericksen
Copy link

brandonfredericksen commented Oct 31, 2024

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

@brandonfredericksen brandonfredericksen added the bug Something isn't working label Oct 31, 2024
@andreja-migles-sm
Copy link

Having the same issue.

@jrood
Copy link

jrood commented Nov 4, 2024

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
Copy link

jrood commented Nov 14, 2024

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

@tcp2
Copy link

tcp2 commented Nov 19, 2024

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

@jrood
Copy link

jrood commented Nov 25, 2024

Ok yes, sw_iframe seems necessary for running sandboxed code. If Partytown could honor loadScriptsOnMainThread for iFrames (as it does currently for scripts), I believe this would resolve the issue.

@hnsxxscyx
Copy link

@jrood @brandonfredericksen @tcp2
Hi guys, have you solved this issue? Any advice for this iframe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants