From e185c2c754131496c7522ee0cda9c5b3aeb111bb Mon Sep 17 00:00:00 2001 From: Jack Wilburn Date: Thu, 28 Sep 2023 14:42:46 -0600 Subject: [PATCH] Add vue-gtag and env variable to netlify toml --- netlify.toml | 3 +++ package.json | 1 + src/environment.ts | 1 + src/main.ts | 1 + src/vuegtag.ts | 12 ++++++++++++ yarn.lock | 5 +++++ 6 files changed, 23 insertions(+) create mode 100644 src/vuegtag.ts diff --git a/netlify.toml b/netlify.toml index 7027ad9b..249272d4 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,6 +2,9 @@ publish = "dist/" command = "yarn build" + [build.environment] + VITE_GA_TAG = "G-RL3875SQTJ" + [context.production.environment] VITE_MULTINET_HOST = "https://api.multinet.app" VITE_OAUTH_API_ROOT = "https://api.multinet.app/oauth/" diff --git a/package.json b/package.json index 205a936c..c73b8dd1 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "vega-lite": "^5.8.0", "vite": "^4.0.5", "vue": "^2.7.0", + "vue-gtag": "1.16.1", "vuetify": "^2.6.10", "yorkie": "^2.0.0" }, diff --git a/src/environment.ts b/src/environment.ts index 2bfc018d..beadeeef 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -2,3 +2,4 @@ export const host: string = import.meta.env.VITE_MULTINET_HOST || 'http://localh export const oauthApiRoot: string = import.meta.env.VITE_OAUTH_API_ROOT || `${host}/oauth`; export const oauthClientId: string = import.meta.env.VITE_OAUTH_CLIENT_ID || ''; export const prodBuild: boolean = import.meta.env.PROD; +export const gaTag: string = import.meta.env.VITE_GA_TAG || ''; diff --git a/src/main.ts b/src/main.ts index fc5c3a29..e436803d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import oauthClient from '@/oauth'; import { oauthClientId, prodBuild } from '@/environment'; import { createPinia, PiniaVuePlugin } from 'pinia'; import { invalidateSharedLoginCookie, readSharedLoginCookie, writeSharedLoginCookie } from 'multinet'; +import './vuegtag'; Vue.config.productionTip = false; Vue.use(PiniaVuePlugin); diff --git a/src/vuegtag.ts b/src/vuegtag.ts new file mode 100644 index 00000000..a0d88ef8 --- /dev/null +++ b/src/vuegtag.ts @@ -0,0 +1,12 @@ +import Vue from 'vue'; +import VueGtag from 'vue-gtag'; + +import { gaTag } from '@/environment'; + +if (gaTag) { + Vue.use(VueGtag, { + config: { + id: gaTag, + }, + }); +} diff --git a/yarn.lock b/yarn.lock index eb13c579..d061c32d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4696,6 +4696,11 @@ vue-eslint-parser@^9.0.1: lodash "^4.17.21" semver "^7.3.6" +vue-gtag@1.16.1: + version "1.16.1" + resolved "https://registry.yarnpkg.com/vue-gtag/-/vue-gtag-1.16.1.tgz#edb2f20ab4f6c4d4d372dfecf8c1fcc8ab890181" + integrity sha512-5vs0pSGxdqrfXqN1Qwt0ZFXG0iTYjRMu/saddc7QIC5yp+DKgjWQRpGYVa7Pq+KbThxwzzMfo0sGi7ISa6NowA== + vue-template-compiler@2.7.10: version "2.7.10" resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.7.10.tgz#9e20f35b2fdccacacf732dd7dedb49bf65f4556b"