Skip to content

Commit 77b0b30

Browse files
committed
chore: ga to gtm migration
1 parent 5a1f851 commit 77b0b30

File tree

7 files changed

+67
-58
lines changed

7 files changed

+67
-58
lines changed

.github/workflows/site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
# branches: [main]
66
pull_request:
77
branches: [main]
8+
workflow_dispatch:
89
jobs:
910
build:
1011
runs-on: ${{ matrix.os }}

website/components/LangMetaPage.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
</div>
6060

6161
<!-- <div class="mt-5">
62-
<span>OS</span>
63-
<select v-model="osSelected" class="px-2 py-2 rounded bg-purple-200">
64-
<option v-for="i in osOptions" :key="i" :value="i">{{ i }}</option>
65-
</select>
66-
</div> -->
62+
<span>OS</span>
63+
<select v-model="osSelected" class="px-2 py-2 rounded bg-purple-200">
64+
<option v-for="i in osOptions" :key="i" :value="i">{{ i }}</option>
65+
</select>
66+
</div> -->
6767

6868
<div v-if="cpuInfo" class="mt-5 text-xs">
6969
<label class="font-bold">CPU INFO:</label
@@ -171,11 +171,9 @@
171171
v-show="other || problem"
172172
:class="['text-left', 'pl-4', mdHide]"
173173
>
174-
<a
175-
:href="`/${i.lang}`"
176-
class="underline text-blue-500"
177-
>{{ i.lang }}</a
178-
>
174+
<a :href="`/${i.lang}`" class="underline text-blue-500">{{
175+
i.lang
176+
}}</a>
179177
</td>
180178
<td class="text-right">
181179
<a
@@ -259,8 +257,10 @@
259257
<script lang="ts">
260258
import { Component, Watch, Vue } from 'nuxt-property-decorator'
261259
import _ from 'lodash'
260+
import { MetaInfo } from 'vue-meta'
262261
import MenuButton from './MenuButton.vue'
263262
import { getFullCompilerVersion, mergeLangBenchResults } from '~/contentUtils'
263+
import { importGoogleTagIfNeeded } from '~/gtmUtils'
264264
265265
function requireAll(requireContext: any) {
266266
const r = requireContext.keys().map(requireContext)
@@ -489,7 +489,7 @@ export default class LangMetaPage extends Vue {
489489
langsStrs.push(`${this.lang!.langDisplay} lang`)
490490
}
491491
492-
return {
492+
const metaInfo: MetaInfo = {
493493
title,
494494
meta: [
495495
{
@@ -499,6 +499,8 @@ export default class LangMetaPage extends Vue {
499499
},
500500
],
501501
}
502+
importGoogleTagIfNeeded(metaInfo)
503+
return metaInfo
502504
}
503505
504506
created() {

website/gtmUtils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { MetaInfo } from 'vue-meta'
2+
3+
export function importGoogleTagIfNeeded(metaInfo: MetaInfo) {
4+
const tag = googleTagId()
5+
if (tag) {
6+
metaInfo.script = [
7+
{
8+
src: `//www.googletagmanager.com/gtag/js?id=${tag}`,
9+
async: true,
10+
},
11+
{
12+
innerHTML: `
13+
window.dataLayer = window.dataLayer || [];
14+
function gtag() {
15+
dataLayer.push(arguments);
16+
}
17+
gtag("js", new Date());
18+
gtag("config", "${tag}");
19+
`,
20+
},
21+
]
22+
metaInfo.__dangerouslyDisableSanitizers = ['script']
23+
}
24+
}
25+
26+
function googleTagId() {
27+
return process.env.GOOGLE_TAG_ID
28+
}

website/nuxt.config.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,4 @@ if (process.env.APP_HOST_NAME) {
153153
}
154154
}
155155

156-
// ga
157-
// https://google-analytics.nuxtjs.org/
158-
if (process.env.GOOGLE_ANALYTICS_ID) {
159-
// eslint-disable-next-line no-console
160-
console.log(`Turning on google analytics`)
161-
config.buildModules?.push('@nuxtjs/google-analytics')
162-
config.googleAnalytics = {
163-
id: process.env.GOOGLE_ANALYTICS_ID,
164-
checkDuplicatedScript: true,
165-
}
166-
}
167-
168156
export default config

website/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@nuxt/typescript-build": "^2.1.0",
5353
"@nuxtjs/eslint-config-typescript": "^10.0.0",
5454
"@nuxtjs/eslint-module": "^3.1.0",
55-
"@nuxtjs/google-analytics": "^2.4.0",
5655
"@nuxtjs/stylelint-module": "^4.1.0",
5756
"@nuxtjs/tailwindcss": "5.1.3",
5857
"@types/lodash": "^4.14.182",

website/pages/index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@
135135
<script lang="ts">
136136
import { Component, Vue } from 'nuxt-property-decorator'
137137
import _ from 'lodash'
138+
import { MetaInfo } from 'vue-meta'
138139
import MenuButton from './../components/MenuButton.vue'
139140
import { mergeLangBenchResults } from '~/contentUtils'
141+
import { importGoogleTagIfNeeded } from '~/gtmUtils'
140142
141143
function requireAll(requireContext: any) {
142144
const r = requireContext.keys().map(requireContext)
@@ -185,7 +187,8 @@ export default class IndexPage extends Vue {
185187
.map((i) => i.langDisplay)
186188
.uniq()
187189
.value()
188-
return {
190+
191+
const metaInfo: MetaInfo = {
189192
title:
190193
'Benchmarks for programming languages and compilers, Which programming language or compiler is faster',
191194
meta: [
@@ -198,6 +201,8 @@ export default class IndexPage extends Vue {
198201
},
199202
],
200203
}
204+
importGoogleTagIfNeeded(metaInfo)
205+
return metaInfo
201206
}
202207
203208
getLinkClass() {

website/pnpm-lock.yaml

Lines changed: 19 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)