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

Not loading scripts from GTM tags #127

Open yeslad opened 2 years ago

yeslad commented 2 years ago

I've added the partytown snippet, defined forwards, and I see the GTM script is being fetched by the service worker. I also see debug messages being written to the console. However, I do not see the google analytics script being fetched. I setup a proxy server and wrote a resolver function. Here is what my config looks like:

<script>
  window.partytown = {
    debug: true,
    logScriptExecution: true,
    logCalls: true,
    logGetters: true,
    logSetters: true,
    forward: ['dataLayer.push', 'ga', 'ga.getAll'],
    resolveUrl(url) {
      if (typeof url == 'string') url = new URL(url);
      const resolver = {
        'www.google-analytics.com'(url) {
          url.hostname = 'example.com';
          url.pathname = `/gascript${url.pathname}`
          return url
        }
      };
      if (url.hostname in resolver) {
        url = resolver[url.hostname](url);
      }
      return url;
    }
  }
  // inlined partytown script
</script>

Additionally, there is a GTM tag that adds the following script:

<script src="https://cookie-cdn.cookiepro.com/scripttemplates/otSDKStub.js"  type="text/javascript" charset="UTF-8" data-domain-script="..." ></script>

Instead of fetching this script, partytown adds the script tag to the DOM, with a type of 'text/partytown'. image

Is this expected behavior?

adamdbradley commented 2 years ago

Sorry but this is not enough information to be able to debug what could be going on. Would you be able to create a PR which recreates the issue you're seeing with a minimal amount of code? A good example to emulate is the Google Tag Manager test: https://github.com/BuilderIO/partytown/tree/main/tests/integrations/gtm

Some more information can be found here: https://github.com/BuilderIO/partytown/blob/main/DEVELOPER.md#submitting-issues-and-writing-tests

Thank you for your help!

yeslad commented 2 years ago

@adamdbradley I've created this PR which reproduces the issue that I've described here.