Skip to content

Commit a0d35ab

Browse files
committed
docs(website): fix pageview and download tracking
1 parent 3617aed commit a0d35ab

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

‎docs/website/.vitepress/components/global/AssetsDownload.vue‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<script setup lang="ts">
2+
import { event } from 'vue-gtag'
23
import assets from '../../_data/assets.json'
4+
5+
function trackDownload(platform: string, variant: string, url: string) {
6+
if (!import.meta.env.VITE_GA)
7+
return
8+
9+
event('download_click', {
10+
platform,
11+
variant,
12+
link_url: url,
13+
transport_type: 'beacon',
14+
})
15+
}
316
</script>
417

518
<template>
@@ -9,6 +22,7 @@ import assets from '../../_data/assets.json'
922
:href="assets.macM1"
1023
theme="brand"
1124
text="Download for Apple Silicon"
25+
@click="trackDownload('macos', 'arm64', assets.macM1)"
1226
/>
1327

1428
<p>macOS 11.0+</p>
@@ -17,6 +31,7 @@ import assets from '../../_data/assets.json'
1731
:href="assets.mac"
1832
theme="brand"
1933
text="Download for Intel"
34+
@click="trackDownload('macos', 'intel', assets.mac)"
2035
/>
2136

2237
<p>macOS 10.13+</p>
@@ -28,12 +43,14 @@ import assets from '../../_data/assets.json'
2843
:href="assets.win"
2944
theme="brand"
3045
text="Download for Windows"
46+
@click="trackDownload('windows', 'installer', assets.win)"
3147
/>
3248

3349
<VPButton
3450
:href="assets.winPortable"
3551
theme="brand"
3652
text="Download for Windows (portable)"
53+
@click="trackDownload('windows', 'portable', assets.winPortable)"
3754
/>
3855
</div>
3956

@@ -45,6 +62,7 @@ import assets from '../../_data/assets.json'
4562
:href="assets.linux"
4663
theme="brand"
4764
text="Download for Linux"
65+
@click="trackDownload('linux', 'appimage', assets.linux)"
4866
/>
4967

5068
<p>Ubuntu</p>

‎docs/website/.vitepress/theme/index.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { EnhanceAppContext } from 'vitepress'
22
import VPButton from 'vitepress/dist/client/theme-default/components/VPButton.vue'
33
import DefaultTheme from 'vitepress/theme'
44
import { h, watch } from 'vue'
5+
import { configure, pageview } from 'vue-gtag'
56
import AppLink from '../components/global/AppLink.vue'
67
import AppVersion from '../components/global/AppVersion.vue'
78
import AssetsDownload from '../components/global/AssetsDownload.vue'
@@ -10,21 +11,21 @@ import SidebarSponsors from '../components/sponsors/SidebarSponsors.vue'
1011
import './styles.css'
1112

1213
function initGtag(context: EnhanceAppContext) {
13-
if (import.meta.env.SSR)
14+
if (import.meta.env.SSR || !import.meta.env.VITE_GA)
1415
return
1516

16-
import('vue-gtag').then(({ configure, pageview }) => {
17-
configure({
18-
tagId: import.meta.env.VITE_GA,
19-
})
20-
21-
watch(
22-
() => context.router.route.data.relativePath,
23-
() => {
24-
pageview(context.router.route.path)
25-
},
26-
)
17+
configure({
18+
tagId: import.meta.env.VITE_GA,
19+
config: { send_page_view: false },
2720
})
21+
22+
watch(
23+
() => context.router.route.data.relativePath,
24+
() => {
25+
pageview(context.router.route.path)
26+
},
27+
{ immediate: true, flush: 'post' },
28+
)
2829
}
2930

3031
export default {

0 commit comments

Comments
 (0)