File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
playground/pages/third-parties/google-analytics Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
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 >
You can’t perform that action at this time.
0 commit comments