Skip to content

Commit

Permalink
📈 Add gtag
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Nov 5, 2022
1 parent 0495509 commit 1b30a22
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default {
],

// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [],
plugins: [
{ src: '~/plugins/gtag.client.js', mode: 'client' },
],

// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"core-js": "^3.19.3",
"nuxt": "^2.15.8",
"vue": "^2.6.14",
"vue-gtag": "^1.16.1",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vuejs-paginate": "^2.1.0",
Expand Down
18 changes: 18 additions & 0 deletions plugins/gtag.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Vue from 'vue' // eslint-disable-line import/no-extraneous-dependencies
import VueGtag from 'vue-gtag'

export default (ctx, inject) => {
const {
app: { router },
} = ctx
Vue.use(
VueGtag,
{
config: { id: 'G-E8Q9GGZHNY' },
bootstrap: !(window.doNotTrack || navigator.doNotTrack),
},
router
)
ctx.$gtag = Vue.$gtag
inject('gtag', Vue.$gtag)
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10945,6 +10945,11 @@ vue-eslint-parser@^8.0.1, vue-eslint-parser@^8.3.0:
lodash "^4.17.21"
semver "^7.3.5"

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-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 1b30a22

Please sign in to comment.