File tree Expand file tree Collapse file tree 3 files changed +87
-0
lines changed Expand file tree Collapse file tree 3 files changed +87
-0
lines changed Original file line number Diff line number Diff line change @@ -149,3 +149,34 @@ describe('basic', () => {
149
149
expect ( text ) . toMatchInlineSnapshot ( `"/_scripts/6nd5bD9YCW.js"` )
150
150
} )
151
151
} )
152
+
153
+ describe ( 'third-party-capital' , ( ) => {
154
+ it ( 'expect GA to collect data' , {
155
+ timeout : 10000 ,
156
+ } , async ( ) => {
157
+ const page = await createPage ( '/tpc/ga' )
158
+ await page . waitForTimeout ( 500 )
159
+
160
+ // wait for the collect request or timeout
161
+ const request = page . waitForRequest ( request => request . url ( ) . includes ( 'google-analytics.com/g/collect' ) , {
162
+ timeout : 10000 ,
163
+ } )
164
+ await page . getByText ( 'Trigger conversion' ) . click ( )
165
+
166
+ await request
167
+ } )
168
+
169
+ it ( 'expect GTM to work collect data' , {
170
+ timeout : 10000 ,
171
+ } , async ( ) => {
172
+ const page = await createPage ( '/tpc/gtm' )
173
+ await page . waitForTimeout ( 500 )
174
+
175
+ // wait for the collect request
176
+ const request = page . waitForRequest ( request => request . url ( ) . includes ( 'analytics.google.com/g/collect?' ) , {
177
+ timeout : 10000 ,
178
+ } )
179
+ await page . getByText ( 'trigger' ) . click ( )
180
+ await request
181
+ } )
182
+ } )
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, $script } = useScriptGoogleAnalytics ({
10
+ id: ' G-TR58L0EF8P' ,
11
+ })
12
+ function triggerConversion() {
13
+ gtag (' event' , ' conversion' )
14
+ }
15
+ </script >
16
+
17
+ <template >
18
+ <div >
19
+ <ClientOnly >
20
+ <div >
21
+ status: {{ $script.status.value }}
22
+ </div >
23
+ </ClientOnly >
24
+ <button @click =" triggerConversion" >
25
+ Trigger Conversion
26
+ </button >
27
+ </div >
28
+ </template >
Original file line number Diff line number Diff line change
1
+ <script lang="ts" setup>
2
+ import { useScriptGoogleTagManager } from ' #imports'
3
+
4
+ const { dataLayer, $script } = useScriptGoogleTagManager ({
5
+ id: ' GTM-MNJD4B' ,
6
+ })
7
+
8
+ function pushEvent() {
9
+ dataLayer .push ({
10
+ event: ' page_view' ,
11
+ page_title: ' GTM' ,
12
+ })
13
+ }
14
+ </script >
15
+
16
+ <template >
17
+ <div >
18
+ <ClientOnly >
19
+ <div >
20
+ status: {{ $script.status }}
21
+ </div >
22
+ </ClientOnly >
23
+
24
+ <button @click =" pushEvent" >
25
+ trigger
26
+ </button >
27
+ </div >
28
+ </template >
You can’t perform that action at this time.
0 commit comments