修改谷歌gtm配置

This commit is contained in:
frankkeres 2025-02-28 18:08:01 +08:00
parent add68a5b72
commit a521dba313
3 changed files with 106 additions and 17 deletions

View File

@ -13,11 +13,11 @@ export default {
lang: 'en' lang: 'en'
}, },
script: [ script: [
{ // {
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-T4DJXJTT');`, // 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-T4DJXJTT');`,
type: 'text/javascript', // type: 'text/javascript',
body: false // body: false
}, // },
{ {
innerHTML: `(function(d,w,c){if(w[c])return;var s=d.createElement("script");w[c]=function(){(w[c].z=w[c].z||[]).push(arguments);};s.async=true;s.src="https://static.ahc.ink/hecong.js";if(d.head)d.head.appendChild(s);})(document,window,"_AIHECONG");_AIHECONG("ini",{channelId:"9BgJ9p"});`, innerHTML: `(function(d,w,c){if(w[c])return;var s=d.createElement("script");w[c]=function(){(w[c].z=w[c].z||[]).push(arguments);};s.async=true;s.src="https://static.ahc.ink/hecong.js";if(d.head)d.head.appendChild(s);})(document,window,"_AIHECONG");_AIHECONG("ini",{channelId:"9BgJ9p"});`,
type: 'text/javascript', type: 'text/javascript',
@ -39,12 +39,12 @@ export default {
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.png' } { rel: 'icon', type: 'image/x-icon', href: '/favicon.png' }
], ],
// 谷歌tag manger // 谷歌tag manger
noscript: [ // noscript: [
{ // {
innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T4DJXJTT" height="0" width="0" style="display: none; visibility: hidden;"></iframe>`, // innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T4DJXJTT" height="0" width="0" style="display: none; visibility: hidden;"></iframe>`,
}, // },
], // ],
__dangerouslyDisableSanitizers: ['script', 'noscript'], // 允许渲染原始 HTML __dangerouslyDisableSanitizers: ['script'], // 允许渲染原始 HTML
}, },
// 全局CSS // 全局CSS
@ -69,14 +69,21 @@ export default {
// 模块 // 模块
modules: [ modules: [
'@nuxtjs/axios' '@nuxtjs/axios',
'@nuxtjs/gtm'
], ],
body: { gtm: {
innerHTML: `<!-- Google Tag Manager (noscript) --><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T4DJXJTT" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->` id: 'GTM-T4DJXJTT',
}, layer: 'dataLayer',
__dangerouslyDisableSanitizersByTagID: { pageTracking: true, // 自动发送页面事件
'bodyAttrs-0': ['innerHTML'] enabled: process.env.NODE_ENV === 'production'
}, },
// body: {
// innerHTML: `<!-- Google Tag Manager (noscript) --><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T4DJXJTT" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->`
// },
// __dangerouslyDisableSanitizersByTagID: {
// 'bodyAttrs-0': ['innerHTML']
// },
// Axios 模块配置 // Axios 模块配置
axios: { axios: {
baseURL: '/' baseURL: '/'

81
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@nuxtjs/axios": "^5.13.6", "@nuxtjs/axios": "^5.13.6",
"@nuxtjs/gtm": "^2.4.0",
"core-js": "^3.25.3", "core-js": "^3.25.3",
"element-ui": "^2.15.14", "element-ui": "^2.15.14",
"nuxt": "^2.15.8", "nuxt": "^2.15.8",
@ -4259,6 +4260,86 @@
"defu": "^5.0.0" "defu": "^5.0.0"
} }
}, },
"node_modules/@nuxtjs/gtm": {
"version": "2.4.0",
"resolved": "https://registry.npmmirror.com/@nuxtjs/gtm/-/gtm-2.4.0.tgz",
"integrity": "sha512-Of5KuBBFwRjyJ6AuRrIQsh8J6ksIN2UegJDE8nBiTAanbwQBsAJ0hZibV9SjhKdGvGvWpbShQ4yR2bmQgY6XKA==",
"license": "MIT",
"dependencies": {
"chalk": "^4.1.0",
"semver": "^7.3.2"
}
},
"node_modules/@nuxtjs/gtm/node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/@nuxtjs/gtm/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@nuxtjs/gtm/node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/@nuxtjs/gtm/node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
},
"node_modules/@nuxtjs/gtm/node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/@nuxtjs/gtm/node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"license": "MIT",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@nuxtjs/proxy": { "node_modules/@nuxtjs/proxy": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmmirror.com/@nuxtjs/proxy/-/proxy-2.1.0.tgz", "resolved": "https://registry.npmmirror.com/@nuxtjs/proxy/-/proxy-2.1.0.tgz",

View File

@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"@nuxtjs/axios": "^5.13.6", "@nuxtjs/axios": "^5.13.6",
"@nuxtjs/gtm": "^2.4.0",
"core-js": "^3.25.3", "core-js": "^3.25.3",
"element-ui": "^2.15.14", "element-ui": "^2.15.14",
"nuxt": "^2.15.8", "nuxt": "^2.15.8",