partytown
partytown copied to clipboard
Access to fetch at 'https://www.google-analytics.com/analytics.js' from origin
nuxt.config.ts:
ssr: true,
modules: ['@nuxtjs/partytown']
partytown: {
forward: ['dataLayer.push'],
debug: false
},
app: {
head: {
title: '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width,initial-scale=1.0' },
{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
],
script: [
{
type: 'text/partytown',
innerHTML: `(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','GTM-XXXXXX');`
}
]
}
}
I got this error:
Access to fetch at 'https://www.google-analytics.com/analytics.js' from origin 'https://stage.mysite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
By the way with gtm script everything is ok, but with analytics..
you might need a reverse proxy
you might need a reverse proxy
How is it done? Do you have an example?