diff --git a/packages/docs/modules/google-analytics/index.ts b/packages/docs/modules/google-analytics/index.ts new file mode 100644 index 0000000000..f53bdf403a --- /dev/null +++ b/packages/docs/modules/google-analytics/index.ts @@ -0,0 +1 @@ +export { default as default } from './module' diff --git a/packages/docs/modules/google-analytics/module.ts b/packages/docs/modules/google-analytics/module.ts new file mode 100644 index 0000000000..c3b3b031c8 --- /dev/null +++ b/packages/docs/modules/google-analytics/module.ts @@ -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({ + 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, + } + }) + } +}) diff --git a/packages/docs/modules/google-analytics/runtime/plugin.ts b/packages/docs/modules/google-analytics/runtime/plugin.ts new file mode 100644 index 0000000000..7a2e739ebd --- /dev/null +++ b/packages/docs/modules/google-analytics/runtime/plugin.ts @@ -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 %>" } + }) +}) diff --git a/packages/docs/nuxt.config.ts b/packages/docs/nuxt.config.ts index 5fac7faa7f..a50d4b74f5 100644 --- a/packages/docs/nuxt.config.ts +++ b/packages/docs/nuxt.config.ts @@ -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', diff --git a/packages/docs/package.json b/packages/docs/package.json index a1b21d1b2c..c7b268833d 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -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", @@ -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" } } diff --git a/yarn.lock b/yarn.lock index 74c88ee8eb..1279f5b9d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"