diff --git a/nuxt.config.js b/nuxt.config.js index 83d88d3..551b2c9 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -4,6 +4,22 @@ export default { // Global page headers: https://go.nuxtjs.dev/config-head head: { title: 'buddysCloud', + script: [ + { + src: 'https://www.googletagmanager.com/gtag/js?id=G-PMXV6BN06E', + async: true, + }, + { + innerHTML: ` + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', 'G-PMXV6BN06E'); + `, + type: 'text/javascript', + }, + ], + __dangerouslyDisableSanitizers: ['script'], // 允许内联脚本 htmlAttrs: { lang: 'en' }, @@ -44,15 +60,26 @@ export default { 'bootstrap-vue/nuxt', '@nuxt/content', '@nuxtjs/axios', - '@nuxtjs/gtm', + // '@nuxtjs/google-analytics' + '@nuxtjs/gtm' ], + // buildModules:[ + // '@nuxtjs/google-analytics' + // ], gtm: { - id: 'G-PMXV6BN06E', + id: 'GTM-PL75JP66', layer: 'dataLayer', - pageTracking: true, // 自动发送页面事件 + pageTracking: false, // ✅ 关闭 GTM 的自动页面跟踪,避免和 GA 冲突 enabled: true // enabled: process.env.NODE_ENV === 'production' }, + // googleAnalytics: { + // id: 'G-PMXV6BN06E', + // debug: true, + // autoTracking: { + // screenview: true, // GA 自己管理页面跟踪 + // }, + // }, // Build Configuration: https://go.nuxtjs.dev/config-build build: { } diff --git a/package-lock.json b/package-lock.json index 681ef36..fdcb625 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,9 @@ "vue": "^2.7.10", "vue-server-renderer": "^2.7.10", "vue-template-compiler": "^2.7.10" + }, + "devDependencies": { + "@nuxtjs/google-analytics": "^2.4.0" } }, "node_modules/@ampproject/remapping": { @@ -3842,6 +3845,16 @@ "integrity": "sha512-EPS1carKg+dkEVy3qNTqIdp2qV7mUP08nIsupfwQpz++slCVRw7qbQyWvSTig+kFPwz2XXp5/kIIkH+CwrJKkQ==", "license": "MIT" }, + "node_modules/@nuxtjs/google-analytics": { + "version": "2.4.0", + "resolved": "https://registry.npmmirror.com/@nuxtjs/google-analytics/-/google-analytics-2.4.0.tgz", + "integrity": "sha512-rDQTwHIjyjVrx8GywHPuWykJ3jRFGaHl5Iqji/y8tQWUc0yGEeHxOoR0yimzxnTS1Ph2/PubQYpgnVeEPEdL/A==", + "dev": true, + "license": "MIT", + "dependencies": { + "vue-analytics": "^5.22.1" + } + }, "node_modules/@nuxtjs/gtm": { "version": "2.4.0", "resolved": "https://registry.npmmirror.com/@nuxtjs/gtm/-/gtm-2.4.0.tgz", @@ -17798,6 +17811,14 @@ "csstype": "^3.1.0" } }, + "node_modules/vue-analytics": { + "version": "5.22.1", + "resolved": "https://registry.npmmirror.com/vue-analytics/-/vue-analytics-5.22.1.tgz", + "integrity": "sha512-HPKQMN7gfcUqS5SxoO0VxqLRRSPkG1H1FqglsHccz6BatBatNtm/Vyy8brApktZxNCfnAkrSVDpxg3/FNDeOgQ==", + "deprecated": "Sorry but vue-analytics is no longer maintained. I would suggest you switch to vue-gtag, with love, the guy who made the package.", + "dev": true, + "license": "MIT" + }, "node_modules/vue-client-only": { "version": "2.1.0", "resolved": "https://registry.npmmirror.com/vue-client-only/-/vue-client-only-2.1.0.tgz", diff --git a/package.json b/package.json index dfad43b..38b3708 100644 --- a/package.json +++ b/package.json @@ -21,5 +21,8 @@ "vue": "^2.7.10", "vue-server-renderer": "^2.7.10", "vue-template-compiler": "^2.7.10" + }, + "devDependencies": { + "@nuxtjs/google-analytics": "^2.4.0" } } diff --git a/yarn.lock b/yarn.lock index f2a338c..cce801b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1709,6 +1709,13 @@ consola "^2.15.3" defu "^5.0.0" +"@nuxtjs/google-analytics@^2.4.0": + version "2.4.0" + resolved "https://registry.npmmirror.com/@nuxtjs/google-analytics/-/google-analytics-2.4.0.tgz" + integrity sha512-rDQTwHIjyjVrx8GywHPuWykJ3jRFGaHl5Iqji/y8tQWUc0yGEeHxOoR0yimzxnTS1Ph2/PubQYpgnVeEPEdL/A== + dependencies: + vue-analytics "^5.22.1" + "@nuxtjs/gtm@^2.4.0": version "2.4.0" resolved "https://registry.npmmirror.com/@nuxtjs/gtm/-/gtm-2.4.0.tgz" @@ -9819,6 +9826,11 @@ vm-browserify@^1.0.1: resolved "https://registry.npmmirror.com/vm-browserify/-/vm-browserify-1.1.2.tgz" integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ== +vue-analytics@^5.22.1: + version "5.22.1" + resolved "https://registry.npmmirror.com/vue-analytics/-/vue-analytics-5.22.1.tgz" + integrity sha512-HPKQMN7gfcUqS5SxoO0VxqLRRSPkG1H1FqglsHccz6BatBatNtm/Vyy8brApktZxNCfnAkrSVDpxg3/FNDeOgQ== + vue-client-only@^2.1.0: version "2.1.0" resolved "https://registry.npmmirror.com/vue-client-only/-/vue-client-only-2.1.0.tgz"