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

GoogleTagManager: custom gtm.js source #152

Closed
endorfin opened this issue Jul 14, 2024 · 3 comments
Closed

GoogleTagManager: custom gtm.js source #152

endorfin opened this issue Jul 14, 2024 · 3 comments

Comments

@endorfin
Copy link

Describe the feature

In one of our client projects we use a self hosted GoogleTagManager Instance + Matomo (GDPR).
So we need the possibility to specify a custom source for the gtm.js script.

  scripts: {
    registry: {
      googleTagManager: {
        url: 'https://analytics.domain-xyz.de/gtm.js',
        id: 'GTM-123456'
      }
    }
  },

Additional information

just a quick idea for implementation ... tpc/utils.ts:98

src: withQuery('${mainScript.params?.url || mainScript.url}', {${mainScript.params?.filter(p => p !== 'url').map(p => `${p}: options?.${p}`)}})
harlan-zw added a commit that referenced this issue Jul 15, 2024
@harlan-zw
Copy link
Collaborator

harlan-zw commented Jul 15, 2024

Hi, the best way to do this is to just provide the entire src yourself.

  scripts: {
    registry: {
      googleTagManager: {
        id: 'GTM-123456',
        scriptInput: { src: 'https://analytics.domain-xyz.de/gtm.js?id=GTM-123456' }
      }
    }
  },

The types don't fully support this but they will in the next version.

@endorfin
Copy link
Author

The source replacement works, but fails with CORS header 'Access-Control-Allow-Origin' missing

@harlan-zw
Copy link
Collaborator

harlan-zw commented Jul 15, 2024

You either need to serve the CORS headers from your domain or disable the crossorigin defaults, see https://unhead.unjs.io/usage/composables/use-script#referrerpolicy-and-crossorigin

scripts: {
    registry: {
      googleTagManager: {
        id: 'GTM-123456',
        scriptInput: {
           src: 'https://analytics.domain-xyz.de/gtm.js?id=GTM-123456',
           crossorigin: false,
        }
      }
    }
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants