Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: e2e integration tests for ga and gtm #189

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions test/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,34 @@ describe('basic', () => {
expect(text).toMatchInlineSnapshot(`"/_scripts/6nd5bD9YCW.js"`)
})
})

describe('third-party-capital', () => {
it('expect GA to collect data', {
timeout: 10000,
}, async () => {
const page = await createPage('/tpc/ga')
await page.waitForTimeout(500)

// wait for the collect request or timeout
const request = page.waitForRequest(request => request.url().includes('google-analytics.com/g/collect'), {
timeout: 10000,
})
await page.getByText('Trigger conversion').click()

await request
})

it('expect GTM to work collect data', {
timeout: 10000,
}, async () => {
const page = await createPage('/tpc/gtm')
await page.waitForTimeout(500)

// wait for the collect request
const request = page.waitForRequest(request => request.url().includes('analytics.google.com/g/collect?'), {
timeout: 10000,
})
await page.getByText('trigger').click()
await request
})
})
28 changes: 28 additions & 0 deletions test/fixtures/basic/pages/tpc/ga.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts" setup>
import { useHead, useScriptGoogleAnalytics } from '#imports'

useHead({
title: 'Google Analytics',
})

// composables return the underlying api as a proxy object and a $script with the script state
const { gtag, $script } = useScriptGoogleAnalytics({
id: 'G-TR58L0EF8P',
})
function triggerConversion() {
gtag('event', 'conversion')
}
</script>

<template>
<div>
<ClientOnly>
<div>
status: {{ $script.status.value }}
</div>
</ClientOnly>
<button @click="triggerConversion">
Trigger Conversion
</button>
</div>
</template>
28 changes: 28 additions & 0 deletions test/fixtures/basic/pages/tpc/gtm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts" setup>
import { useScriptGoogleTagManager } from '#imports'

const { dataLayer, $script } = useScriptGoogleTagManager({
id: 'GTM-MNJD4B',
})

function pushEvent() {
dataLayer.push({
event: 'page_view',
page_title: 'GTM',
})
}
</script>

<template>
<div>
<ClientOnly>
<div>
status: {{ $script.status }}
</div>
</ClientOnly>

<button @click="pushEvent">
trigger
</button>
</div>
</template>