Skip to content

Commit 9a5ba6b

Browse files
chore: playground for multi datalayers (#173)
Co-authored-by: Harlan Wilton <[email protected]>
1 parent 85f6a18 commit 9a5ba6b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script lang="ts" setup>
2+
import { useHead, useScriptGoogleAnalytics } from '#imports'
3+
4+
useHead({
5+
title: 'Google Analytics',
6+
})
7+
8+
// composables return the underlying api as a proxy object and a $script with the script state
9+
const { gtag: gtag1, $script: $script1 } = useScriptGoogleAnalytics({
10+
id: 'G-TR58L0EF8P',
11+
dataLayerName: 'dataLayer1',
12+
})
13+
14+
const { gtag: gtag2, $script: $script2 } = useScriptGoogleAnalytics({
15+
key: 'test',
16+
id: 'G-123456',
17+
dataLayerName: 'dataLayer2',
18+
})
19+
20+
// id set via nuxt scripts module config
21+
gtag1('event', 'page_view', {
22+
page_title: 'Google Analytics',
23+
page_location: 'https://harlanzw.com/third-parties/google-analytics',
24+
page_path: '/third-parties/google-analytics',
25+
})
26+
27+
function triggerConversion() {
28+
gtag2('event', 'conversion')
29+
}
30+
</script>
31+
32+
<template>
33+
<div>
34+
<ClientOnly>
35+
<div>
36+
1 status: {{ $script1.status.value }}
37+
</div>
38+
</ClientOnly>
39+
<ClientOnly>
40+
<div>
41+
2 status: {{ $script2.status.value }}
42+
</div>
43+
</ClientOnly>
44+
<button @click="triggerConversion">
45+
Trigger Conversion
46+
</button>
47+
</div>
48+
</template>

0 commit comments

Comments
 (0)