From 512da2cdaffcc15b08afef3e3c4ffadee98d6b97 Mon Sep 17 00:00:00 2001 From: Atheer Alotaibi Date: Thu, 25 Jan 2024 14:49:26 +0300 Subject: [PATCH] adding google analytics tag --- nuxt.config.js | 1 + plugins/google-analytics.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 plugins/google-analytics.js diff --git a/nuxt.config.js b/nuxt.config.js index 711484e..2a0e8a2 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -62,6 +62,7 @@ export default { src: '~/plugins/facebook.js', mode: 'client' }, { src: '~/plugins/gtag-conversion.js', mode: 'client' }, + { src: '~/plugins/google-analytics.js', mode: 'client' } ], buildModules: [ diff --git a/plugins/google-analytics.js b/plugins/google-analytics.js new file mode 100644 index 0000000..8f8bf81 --- /dev/null +++ b/plugins/google-analytics.js @@ -0,0 +1,12 @@ +if (process.client) { + window.dataLayer = window.dataLayer || []; + function gtag() { dataLayer.push(arguments); } + gtag('js', new Date()); + gtag('config', 'AW-11170063115'); + + let script = document.createElement('script'); + script.async = true; + script.src = 'https://www.googletagmanager.com/gtag/js?id=AW-11170063115'; + document.head.appendChild(script); + } + \ No newline at end of file