partytown icon indicating copy to clipboard operation
partytown copied to clipboard

Access to fetch at 'https://www.google-analytics.com/analytics.js' from origin

Open dbelouslv opened this issue 1 year ago • 2 comments

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..

image

dbelouslv avatar Jul 31 '24 07:07 dbelouslv

you might need a reverse proxy

muhsin-life avatar Dec 09 '24 13:12 muhsin-life

you might need a reverse proxy

How is it done? Do you have an example?

oooFreaKooo avatar May 06 '25 08:05 oooFreaKooo