diff --git a/app.vue b/app.vue
index 0db4dd2b..259b50ae 100644
--- a/app.vue
+++ b/app.vue
@@ -19,6 +19,7 @@
diff --git a/composables/useStatefullCookie.ts b/composables/useStatefullCookie.ts
index 504de511..1311dd39 100644
--- a/composables/useStatefullCookie.ts
+++ b/composables/useStatefullCookie.ts
@@ -1,4 +1,4 @@
-import { CookieOptions } from 'nuxt/app'
+import type { CookieOptions } from 'nuxt/app'
const COOKIES_OPTS: CookieOptions = {
path: '/',
@@ -11,9 +11,13 @@ const COOKIES_OPTS: CookieOptions = {
* https://github.com/nuxt/nuxt/issues/13020
* Solution based on https://github.com/nuxt/nuxt/issues/13020#issuecomment-1397282738
*/
-export const useStatefulCookie = (name: string, opts: CookieOptions = COOKIES_OPTS) => {
+export const useStatefulCookie = (
+ name: string,
+ opts: CookieOptions = COOKIES_OPTS,
+) => {
const key = `cookies:${name}`
- const cookie = useCookie(name, opts)
+ // @ts-ignore
+ const cookie = useCookie(name, opts)
const state = useState(key, () => cookie.value)
if (process.client)
diff --git a/consts/cookiesKeys.ts b/consts/cookiesKeys.ts
index 5e0719a7..b55e6b24 100644
--- a/consts/cookiesKeys.ts
+++ b/consts/cookiesKeys.ts
@@ -1,3 +1,5 @@
+import type { CookieOptions } from 'nuxt/app'
+
/**
* Names of the cookies used by the application.
*/
@@ -8,4 +10,15 @@ export const IDENTITY_TOKEN_KEY = 'h_identity_token'
export const REFRESH_TOKEN_KEY = 'h_refresh_token'
-export const COOKIE_ACCEPTED_KEY = 'h_cookies_accepted'
+export const COOKIE_REQUIRED_ACCEPTED_KEY = 'h_cookies_required_accepted'
+
+export const COOKIE_FUNCTIONAL_ACCEPTED_KEY = 'h_cookies_functional_accepted'
+
+export const COOKIE_ANALYTICS_ACCEPTED_KEY = 'h_cookies_analytics_accepted'
+
+export const COOKIE_ADS_ACCEPTED_KEY = 'h_cookies_ads_accepted'
+
+export const COOKIES_CONFIG: CookieOptions = {
+ maxAge: 365 * 24 * 60 * 60,
+ path: '/',
+} as const
diff --git a/nuxt.config.ts b/nuxt.config.ts
index e33174ad..243cfadc 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -12,6 +12,7 @@ const {
APP_HOST,
RECAPTCHA_PUBLIC,
GOOGLE_TAG_MANAGER_ID,
+ GOOGLE_ANALYTICS_ID,
CENEO_GUID,
LEASLINK_ID,
CALLPAGE_ID,
@@ -92,6 +93,7 @@ export default defineNuxtConfig({
isProduction,
recaptchaPublic: RECAPTCHA_PUBLIC,
googleTagManagerId: GOOGLE_TAG_MANAGER_ID,
+ googleAnalyticsId: GOOGLE_ANALYTICS_ID,
ceneoGuid: CENEO_GUID,
leaslinkId: LEASLINK_ID,
callpageId: CALLPAGE_ID,
diff --git a/package.json b/package.json
index 52dc3c64..f53f6623 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
},
"dependencies": {
"@directus/sdk": "^10.3.5",
+ "@gtm-support/vue-gtm": "^2.2.0",
"@heseya/store-core": "5.2.0",
"@kyvg/vue3-notification": "^3.0.2",
"@pinia-plugin-persistedstate/nuxt": "1.1.2",
@@ -32,8 +33,7 @@
"nodemailer": "^6.9.7",
"nuxt-swiper": "^1.2.2",
"swiper": "^10.3.1",
- "vee-validate": "4.9.6",
- "vue-gtag-next": "^1.14.0"
+ "vee-validate": "4.9.6"
},
"devDependencies": {
"@commitlint/cli": "^17.7.2",
diff --git a/plugins/google-analytics.client.ts b/plugins/google-analytics.client.ts
new file mode 100644
index 00000000..3457d95c
--- /dev/null
+++ b/plugins/google-analytics.client.ts
@@ -0,0 +1,19 @@
+export default defineNuxtPlugin(() => {
+ const config = usePublicRuntimeConfig()
+ if (!config.googleAnalyticsId) return
+
+ useHead({
+ script: [
+ {
+ hid: 'google-analytics-src',
+ defer: true,
+ src: `https://www.googletagmanager.com/gtag/js?id=${config.googleAnalyticsId}`,
+ },
+ {
+ hid: 'google-analytics-init',
+ defer: true,
+ children: `window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '${config.googleAnalyticsId}');`,
+ },
+ ],
+ })
+})
diff --git a/plugins/vue-gtag.client.ts b/plugins/vue-gtag.client.ts
index 31f80bb3..d05719f1 100644
--- a/plugins/vue-gtag.client.ts
+++ b/plugins/vue-gtag.client.ts
@@ -1,59 +1,132 @@
import { HeseyaEvent } from '@heseya/store-core'
-import VueGtag, { trackRouter, isTracking, useGtag } from 'vue-gtag-next'
-import { Pinia } from '@pinia/nuxt/dist/runtime/composables'
+import { createGtm, useGtm } from '@gtm-support/vue-gtm'
-import { mapCartItemToItem, mapProductToItem } from '~/utils/google'
-import { useConfigStore } from '@/store/config'
+import {
+ COOKIE_ADS_ACCEPTED_KEY,
+ COOKIE_ANALYTICS_ACCEPTED_KEY,
+ COOKIE_FUNCTIONAL_ACCEPTED_KEY,
+ COOKIES_CONFIG,
+} from '@/consts/cookiesKeys'
+
+import { mapCartItemToItem, mapProductToItem } from '@/utils/google'
export default defineNuxtPlugin((nuxtApp) => {
const { googleTagManagerId, isProduction } = usePublicRuntimeConfig()
if (!googleTagManagerId) return
- nuxtApp.vueApp.use(VueGtag, {
- property: {
+ nuxtApp.vueApp.use(
+ createGtm({
id: googleTagManagerId,
- },
- useDebugger: !isProduction,
- })
+ defer: true,
+ debug: !isProduction,
+ vueRouter: useRouter() as any,
+ loadScript: true,
+ enabled: false,
+ }),
+ )
+
+ /**
+ * * TRACKING
+ */
+ const gtm = useGtm()
+ const pushEventsQueue = useState