Skip to content

Commit

Permalink
fix(docs): add vue-gtag (#3477)
Browse files Browse the repository at this point in the history
* fix(docs): add vue-gtag

* fix(docs): use google analytics id from .env

---------

Co-authored-by: Yauheni Prakopchyk <ontrew@gmail.com>
  • Loading branch information
m0ksem and asvae authored Jun 14, 2023
1 parent 2bd94ba commit 55dddc2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/docs/modules/google-analytics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as default } from './module'
28 changes: 28 additions & 0 deletions packages/docs/modules/google-analytics/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineNuxtModule, addPluginTemplate } from '@nuxt/kit';
import { resolve } from 'pathe'

/** Module used to add current file path to page-config */
export default defineNuxtModule<any>({
meta: {
name: 'googleAnalytics',
},

defaults: {
id: 0,
},

setup(options) {
if (!options.id) {
console.warn('Google Analytics ID is not specified. Disabling module.')
return
}

addPluginTemplate({
src: resolve(__dirname, './runtime/plugin.ts'),

options: {
ID: options.id,
}
})
}
})
8 changes: 8 additions & 0 deletions packages/docs/modules/google-analytics/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineNuxtPlugin } from '#app';
import VueGtag from 'vue-gtag'

export default defineNuxtPlugin((nuxt) => {
nuxt.vueApp.use(VueGtag, {
config: { id: "<%= options.ID %>" }
})
})
5 changes: 5 additions & 0 deletions packages/docs/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export default defineNuxtConfig({
compressPublicAssets: true,
},

googleAnalytics: {
id: process.env.GOOGLE_ANALYTICS_ID,
},

modules: [
'./modules/google-analytics',
'./modules/banner',
'./modules/vuestic',
'./modules/page-config',
Expand Down
5 changes: 3 additions & 2 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"@nuxtjs/i18n": "^8.0.0-beta.11",
"@nuxtjs/tailwindcss": "^6.3.0",
"@types/escodegen": "^0.0.7",
"@types/marked": "^4.3.0",
"@types/estree": "^1.0.0",
"@types/marked": "^4.3.0",
"acorn": "^8.8.1",
"acorn-walk": "^8.2.0",
"autoprefixer": "^10.4.13",
Expand All @@ -47,6 +47,7 @@
"acorn": "^8.8.1",
"codesandbox": "^2.2.3",
"highlight.js": "^11.7.0",
"marked": "^4.3.0"
"marked": "^4.3.0",
"vue-gtag": "^2.0.1"
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18018,6 +18018,11 @@ vue-eslint-parser@^9.0.1:
lodash "^4.17.21"
semver "^7.3.6"

vue-gtag@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/vue-gtag/-/vue-gtag-2.0.1.tgz#d4dc1b9cf79809c37ce844824c0f7fa97af520dd"
integrity sha512-aM4A58FVL0wV2ptYi+xzAjeg+pQVRyUcfBc5UkXAwQrR4t3WBhor50Izp2I+3Oo7+l+vWJ7u78DGcNzReb8S/A==

vue-hot-reload-api@^2.3.0:
version "2.3.4"
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz#532955cc1eb208a3d990b3a9f9a70574657e08f2"
Expand Down

0 comments on commit 55dddc2

Please sign in to comment.