Skip to content

Commit

Permalink
feat: analitycs
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfredinni committed Jul 12, 2022
1 parent c8502dc commit 7f99138
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Expand Up @@ -32,6 +32,7 @@
"getcwd",
"getinfo",
"getsize",
"gtag",
"hashable",
"IGNORECASE",
"isabs",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -18,9 +18,11 @@
"@headlessui/vue": "^1.6.6",
"@vueuse/core": "^8.9.1",
"@vueuse/head": "^0.7.6",
"add": "^2.0.6",
"pinia": "^2.0.15",
"prism-theme-vars": "^0.2.3",
"vue": "^3.2.37",
"vue-gtag": "^2.0.1",
"vue-i18n": "^9.1.10",
"vue-router": "^4.1.2"
},
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions src/App.vue
Expand Up @@ -2,22 +2,23 @@
const route = useRoute()
const { meta } = useMeta()
useHead(meta)
const inProduction = import.meta.env.PROD
if (inProduction) {
useScriptTag(
`https://www.googletagmanager.com/gtag/js?id=${import.meta.env.VITE_GTAG}`,
() => {
window.dataLayer = window.dataLayer || []
function gtag() {
// eslint-disable-next-line no-undef
dataLayer.push(arguments)
}
gtag('js', new Date())
gtag('config', import.meta.env.VITE_GTAG)
}
)
}
// useAnalytics()
// const inProduction = import.meta.env.PROD
// if (inProduction) {
// useScriptTag(
// `https://www.googletagmanager.com/gtag/js?id=${import.meta.env.VITE_GTAG}`,
// () => {
// window.dataLayer = window.dataLayer || []
// function gtag() {
// // eslint-disable-next-line no-undef
// dataLayer.push(arguments)
// }
// gtag('js', new Date())
// gtag('config', import.meta.env.VITE_GTAG)
// }
// )
// }
watch(route, () => {
window.scrollTo(0, 0)
Expand Down
12 changes: 12 additions & 0 deletions src/modules/analytics.ts
@@ -0,0 +1,12 @@
import VueGtag from 'vue-gtag'
import { type UserModule } from '~/types'

export const install: UserModule = ({ app }) => {
const inProduction = import.meta.env.PROD
if (inProduction) {
const gTag = import.meta.env.VITE_GTAG || 'tag'
app.use(VueGtag, {
config: { id: gTag },
})
}
}
8 changes: 8 additions & 0 deletions src/types/index.d.ts
@@ -0,0 +1,8 @@
export {}

declare global {
// eslint-disable-next-line no-unused-vars
interface Window {
dataLayer: any
}
}
3 changes: 3 additions & 0 deletions tsconfig.json
Expand Up @@ -38,4 +38,7 @@
"coverage",
"cheatsheet",
],
"typeRoots": [
"./src/types"
]
}

0 comments on commit 7f99138

Please sign in to comment.