Skip to content

Commit edff411

Browse files
committed
feat: add Cookie Consent
1 parent 2e8e17c commit edff411

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

app/app.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ useHead({
88
return titleChunk ? `${titleChunk} - Nuxt Commerce` : 'Nuxt Commerce'
99
},
1010
})
11-
12-
// Uncomment and adjust when you need Google Analytics
13-
// const { load } = useScriptGoogleAnalytics(
14-
// { id: 'G-1234567', scriptOptions: { trigger: 'manual' } },
15-
// )
16-
17-
// load()
1811
</script>
1912

2013
<template>
@@ -35,6 +28,7 @@ useHead({
3528

3629
<NuxtPage />
3730

31+
<LayoutCookieConsent />
3832
<LazyLayoutTheFooter class="mt-5" />
3933
</main>
4034
</UApp>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script setup lang="ts">
2+
const toast = useToast()
3+
const consent = useCookie('consent', { maxAge: 31536000, path: '/' })
4+
5+
// Load Google Analytics Script after consent
6+
// https://scripts.nuxt.com/docs/guides/consent
7+
8+
onMounted(() => {
9+
if (document.cookie.includes('cookie-consent')) return
10+
11+
toast.add({
12+
'id': 'welcome',
13+
'title': 'Welcome to Nuxt Commerce',
14+
'description': 'A high-performance, server-rendered E-commerce app built with Nuxt & Shopify',
15+
'duration': Infinity,
16+
'onClick': () => {},
17+
'onUpdate:open': () => {
18+
consent.value = 'cookie-consent'
19+
toast.remove('welcome')
20+
},
21+
})
22+
})
23+
</script>
24+
25+
<template>
26+
<span />
27+
</template>

0 commit comments

Comments
 (0)