From 8928fb9f7e75a717cf65887fb01ed49383fd31e8 Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Thu, 1 Dec 2022 00:37:18 -0500 Subject: [PATCH 1/7] feat: add dependency on vue-gtag --- package.json | 3 ++- yarn.lock | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 28e19dc..1c827c2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "test": "yarn lint && jest" }, "dependencies": { - "vue-analytics": "^5.22.1" + "vue-analytics": "^5.22.1", + "vue-gtag": "^1.16.1" }, "devDependencies": { "@commitlint/cli": "latest", diff --git a/yarn.lock b/yarn.lock index 7207095..c107d9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10657,6 +10657,11 @@ vue-eslint-parser@^7.0.0: esquery "^1.0.1" lodash "^4.17.15" +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" From 939788d0bd794b294d57925d3681a4cb9f901d9f Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Thu, 1 Dec 2022 02:28:45 -0500 Subject: [PATCH 2/7] feat(api): add useGtag option to plugin config --- lib/plugin.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index 2089f1f..3072af1 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,5 +1,6 @@ import Vue from 'vue' import VueAnalytics from 'vue-analytics' +import VueGtag from 'vue-gtag' export default async (ctx, inject) => { const runtimeConfig = ctx.$config && ctx.$config.googleAnalytics || {} @@ -10,8 +11,13 @@ export default async (ctx, inject) => { options.id = await options.asyncID(ctx) } - Vue.use(VueAnalytics, {...{ router: ctx.app.router }, ...options}) - - ctx.$ga = Vue.$ga - inject('ga', Vue.$ga) + if (options.useGtag) { + Vue.use(VueGtag, { config: { id: options.id }, ...options }, ctx.app.router) + ctx.$gtag = Vue.$gtag + inject('gtag', Vue.$gtag) + } else { + Vue.use(VueAnalytics, { router: ctx.app.router, ...options}) + ctx.$ga = Vue.$ga + inject('ga', Vue.$ga) + } } From 43ec5bbe1b195b5175ff672d98d748d7bfe88010 Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Thu, 1 Dec 2022 02:29:55 -0500 Subject: [PATCH 3/7] refactor(api): add vue-gtag options to type signature --- package.json | 1 + types/index.d.ts | 48 +++++++-- types/vuex.d.ts | 6 +- yarn.lock | 256 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 297 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 1c827c2..723ee0f 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "devDependencies": { "@commitlint/cli": "latest", "@commitlint/config-conventional": "latest", + "@nuxt/types": "^2.15.8", "@nuxtjs/eslint-config": "latest", "@nuxtjs/module-test-utils": "latest", "eslint": "latest", diff --git a/types/index.d.ts b/types/index.d.ts index 832be6e..5927b9a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,33 +1,65 @@ -import type Vue from 'vue' -import type { default as VueAnalytics, InstallOptions } from 'vue-analytics' +import { Module, Context } from '@nuxt/types' +import VueAnalytics, { InstallOptions } from 'vue-analytics' +import { VueGtag, PluginOptions } from 'vue-gtag' import './vuex' +interface BaseOptions { + id?: string + asyncID?: (context: Context) => Promise + /** + * @deprecated use id instead + */ + ua?: string + useGtag?: boolean +} + +interface VueAnalyticsOptions extends BaseOptions, Omit { + useGtag?: false +} + +interface VueGtagOptions extends BaseOptions, Omit { + useGtag: true +} + +type Options = VueAnalyticsOptions | VueGtagOptions + declare module '@nuxt/vue-app' { interface Context { - $ga: VueAnalytics + $ga?: VueAnalytics + $gtag?: VueGtag } + interface NuxtAppOptions { - $ga: VueAnalytics + $ga?: VueAnalytics + $gtag?: VueGtag } } // Nuxt 2.9+ declare module '@nuxt/types' { interface Context { - $ga: VueAnalytics + $ga?: VueAnalytics + $gtag?: VueGtag } interface NuxtAppOptions { - $ga: VueAnalytics + $ga?: VueAnalytics + $gtag?: VueGtag } interface Configuration { - googleAnalytics?: InstallOptions + googleAnalytics?: Options } } declare module 'vue/types/vue' { interface Vue { - $ga: VueAnalytics + // @ts-expect-error vue-analytics marks this object as required + $ga?: VueAnalytics + // @ts-expect-error vue-gtag marks this object as required + $gtag?: VueGtag } } + +declare const analyticsModule: Module +export default analyticsModule diff --git a/types/vuex.d.ts b/types/vuex.d.ts index bf6d9c5..227226d 100644 --- a/types/vuex.d.ts +++ b/types/vuex.d.ts @@ -1,7 +1,9 @@ -import type VueAnalytics from 'vue-analytics' +import VueAnalytics from 'vue-analytics' +import VueGtag from 'vue-gtag' declare module 'vuex' { interface Store { - $ga: VueAnalytics, + $ga?: VueAnalytics + $gtag?: VueGtag } } diff --git a/yarn.lock b/yarn.lock index c107d9d..40346ca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1337,6 +1337,31 @@ "@types/webpack-dev-middleware" "^3.7.0" "@types/webpack-hot-middleware" "^2.25.0" +"@nuxt/types@^2.15.8": + version "2.15.8" + resolved "https://registry.yarnpkg.com/@nuxt/types/-/types-2.15.8.tgz#1249de448f68169fe17e9379ee7b5caa0eb336b0" + integrity sha512-zBAG5Fy+SIaZIerOVF1vxy1zz16ZK07QSbsuQAjdtEFlvr+vKK+0AqCv8r8DBY5IVqdMIaw5FgNUz5py0xWdPg== + dependencies: + "@types/autoprefixer" "9.7.2" + "@types/babel__core" "7.1.14" + "@types/compression" "1.7.0" + "@types/connect" "3.4.34" + "@types/etag" "1.8.0" + "@types/file-loader" "5.0.0" + "@types/html-minifier" "4.0.0" + "@types/less" "3.0.2" + "@types/node" "12.20.12" + "@types/optimize-css-assets-webpack-plugin" "5.0.3" + "@types/pug" "2.0.4" + "@types/sass-loader" "8.0.1" + "@types/serve-static" "1.13.9" + "@types/terser-webpack-plugin" "4.2.1" + "@types/webpack" "4.41.28" + "@types/webpack-bundle-analyzer" "3.9.3" + "@types/webpack-dev-middleware" "4.1.2" + "@types/webpack-hot-middleware" "2.25.4" + sass-loader "10.1.1" + "@nuxt/utils-edge@2.13.0-26475855.c2c7081d": version "2.13.0-26475855.c2c7081d" resolved "https://registry.yarnpkg.com/@nuxt/utils-edge/-/utils-edge-2.13.0-26475855.c2c7081d.tgz#0cf81da58cead1aa0bbdb2f4aa83a1b46efc567f" @@ -1481,7 +1506,7 @@ resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a" integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA== -"@types/autoprefixer@^9.7.0": +"@types/autoprefixer@9.7.2", "@types/autoprefixer@^9.7.0": version "9.7.2" resolved "https://registry.yarnpkg.com/@types/autoprefixer/-/autoprefixer-9.7.2.tgz#64b3251c9675feef5a631b7dd34cfea50a8fdbcc" integrity sha512-QX7U7YW3zX3ex6MECtWO9folTGsXeP4b8bSjTq3I1ODM+H+sFHwGKuof+T+qBcDClGlCGtDb3SVfiTVfmcxw4g== @@ -1489,6 +1514,17 @@ "@types/browserslist" "*" postcss "7.x.x" +"@types/babel__core@7.1.14": + version "7.1.14" + resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.14.tgz#faaeefc4185ec71c389f4501ee5ec84b170cc402" + integrity sha512-zGZJzzBUVDo/eV6KgbE0f0ZI7dInEYvo12Rb70uNQDshC3SkRMb67ja0GgRHZgAX3Za6rhaWlvbDO8rrGyAb1g== + dependencies: + "@babel/parser" "^7.1.0" + "@babel/types" "^7.0.0" + "@types/babel__generator" "*" + "@types/babel__template" "*" + "@types/babel__traverse" "*" + "@types/babel__core@^7.1.6", "@types/babel__core@^7.1.7": version "7.1.7" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.7.tgz#1dacad8840364a57c98d0dd4855c6dd3752c6b89" @@ -1547,7 +1583,7 @@ resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== -"@types/compression@^1.7.0": +"@types/compression@1.7.0", "@types/compression@^1.7.0": version "1.7.0" resolved "https://registry.yarnpkg.com/@types/compression/-/compression-1.7.0.tgz#8dc2a56604873cf0dd4e746d9ae4d31ae77b2390" integrity sha512-3LzWUM+3k3XdWOUk/RO+uSjv7YWOatYq2QADJntK1pjkk4DfVP0KrIEPDnXRJxAAGKe0VpIPRmlINLDuCedZWw== @@ -1561,7 +1597,14 @@ dependencies: "@types/node" "*" -"@types/etag@^1.8.0": +"@types/connect@3.4.34": + version "3.4.34" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.34.tgz#170a40223a6d666006d93ca128af2beb1d9b1901" + integrity sha512-ePPA/JuI+X0vb+gSWlPKOY0NdNAie/rPUqX2GUPpbZwiKTkSPhjXWuee47E4MtE54QVzGCQMQkAL6JhV2E1+cQ== + dependencies: + "@types/node" "*" + +"@types/etag@1.8.0", "@types/etag@^1.8.0": version "1.8.0" resolved "https://registry.yarnpkg.com/@types/etag/-/etag-1.8.0.tgz#37f0b1f3ea46da7ae319bbedb607e375b4c99f7e" integrity sha512-EdSN0x+Y0/lBv7YAb8IU4Jgm6DWM+Bqtz7o5qozl96fzaqdqbdfHS5qjdpFeIv7xQ8jSLyjMMNShgYtMajEHyQ== @@ -1586,6 +1629,13 @@ "@types/qs" "*" "@types/serve-static" "*" +"@types/file-loader@5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/file-loader/-/file-loader-5.0.0.tgz#c7d06c14a8fc0224661e9a29c4035ba47db826df" + integrity sha512-evodFzM0PLOXmMZy8DhPN+toP6QgJiIteF6e8iD9T0xGBUllQA/DAb1nZwCIoNh7vuLvqCGPUdsLf3GSbcHd4g== + dependencies: + "@types/webpack" "^4" + "@types/file-loader@^4.2.0": version "4.2.0" resolved "https://registry.yarnpkg.com/@types/file-loader/-/file-loader-4.2.0.tgz#ec8e793e275b7f90cdec3ff286518c6bf7bb8fc3" @@ -1600,6 +1650,15 @@ dependencies: "@types/node" "*" +"@types/html-minifier@4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/html-minifier/-/html-minifier-4.0.0.tgz#2065cb9944f2d1b241146707c6935aa7b947d279" + integrity sha512-eFnGhrKmjWBlnSGNtunetE3UU2Tc/LUl92htFslSSTmpp9EKHQVcYQadCyYfnzUEFB5G/3wLWo/USQS/mEPKrA== + dependencies: + "@types/clean-css" "*" + "@types/relateurl" "*" + "@types/uglify-js" "*" + "@types/html-minifier@^3.5.3": version "3.5.3" resolved "https://registry.yarnpkg.com/@types/html-minifier/-/html-minifier-3.5.3.tgz#5276845138db2cebc54c789e0aaf87621a21e84f" @@ -1634,6 +1693,16 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== +"@types/json-schema@^7.0.8": + version "7.0.11" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" + integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== + +"@types/less@3.0.2": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@types/less/-/less-3.0.2.tgz#2761d477678c8374cb9897666871662eb1d1115e" + integrity sha512-62vfe65cMSzYaWmpmhqCMMNl0khen89w57mByPi1OseGfcV/LV03fO8YVrNj7rFQsRWNJo650WWyh6m7p8vZmA== + "@types/less@^3.0.1": version "3.0.1" resolved "https://registry.yarnpkg.com/@types/less/-/less-3.0.1.tgz#625694093c72f8356c4042754e222407e50d6b08" @@ -1651,6 +1720,18 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.1.tgz#dc488842312a7f075149312905b5e3c0b054c79d" integrity sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw== +"@types/mime@^1": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" + integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== + +"@types/node-sass@*": + version "4.11.3" + resolved "https://registry.yarnpkg.com/@types/node-sass/-/node-sass-4.11.3.tgz#cabbe257bb1b615fcf0f8536d4673102e9930a3d" + integrity sha512-wXPCn3t9uu5rR4zXNSLasZHQMuRzUKBsdi4MsgT8uq4Lp1gQQo+T2G23tGj4SSgDHeNBle6vGseZtM2XV/X9bw== + dependencies: + "@types/node" "*" + "@types/node-sass@^4.11.0": version "4.11.0" resolved "https://registry.yarnpkg.com/@types/node-sass/-/node-sass-4.11.0.tgz#b0372075546e83f39df52bd37359eab00165a04d" @@ -1663,6 +1744,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.4.tgz#1581d6c16e3d4803eb079c87d4ac893ee7501c2c" integrity sha512-x26ur3dSXgv5AwKS0lNfbjpCakGIduWU1DU91Zz58ONRWrIKGunmZBNv4P7N+e27sJkiGDsw/3fT4AtsqQBrBA== +"@types/node@12.20.12": + version "12.20.12" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.12.tgz#fd9c1c2cfab536a2383ed1ef70f94adea743a226" + integrity sha512-KQZ1al2hKOONAs2MFv+yTQP1LkDWMrRJ9YCVRalXltOfXsBmH5IownLxQaiq0lnAHwAViLnh2aTYqrPcRGEbgg== + "@types/node@^12.12.29": version "12.12.37" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.37.tgz#cb4782d847f801fa58316da5b4801ca3a59ae790" @@ -1673,6 +1759,13 @@ resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== +"@types/optimize-css-assets-webpack-plugin@5.0.3": + version "5.0.3" + resolved "https://registry.yarnpkg.com/@types/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.3.tgz#9bf5bdbb57b379f59a37a6775336f42cd6701852" + integrity sha512-PJgbI4KplJfyxKWVrBbEL+rePEBqeozJRMT0mBL3ynhvngASBV/XJ+BneLuJN74RjjMzO0gA5ns80mgubQdZAA== + dependencies: + "@types/webpack" "^4" + "@types/optimize-css-assets-webpack-plugin@^5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@types/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.1.tgz#1f437ef9ef937b393687a8819be2d2fddc03b069" @@ -1690,7 +1783,7 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.0.0.tgz#dc85454b953178cc6043df5208b9e949b54a3bc4" integrity sha512-/rM+sWiuOZ5dvuVzV37sUuklsbg+JPOP8d+nNFlo2ZtfpzPiPvh1/gc8liWOLBqe+sR+ZM7guPaIcTt6UZTo7Q== -"@types/pug@^2.0.4": +"@types/pug@2.0.4", "@types/pug@^2.0.4": version "2.0.4" resolved "https://registry.yarnpkg.com/@types/pug/-/pug-2.0.4.tgz#8772fcd0418e3cd2cc171555d73007415051f4b2" integrity sha1-h3L80EGOPNLMFxVV1zAHQVBR9LI= @@ -1715,6 +1808,22 @@ resolved "https://registry.yarnpkg.com/@types/relateurl/-/relateurl-0.2.28.tgz#6bda7db8653fa62643f5ee69e9f69c11a392e3a6" integrity sha1-a9p9uGU/piZD9e5p6facEaOS46Y= +"@types/sass-loader@8.0.1": + version "8.0.1" + resolved "https://registry.yarnpkg.com/@types/sass-loader/-/sass-loader-8.0.1.tgz#628eb80c30cb34ce622056f9b9a1606a8147dcd0" + integrity sha512-kum0/5Im5K2WdDTRsLtrXXvX2VJc3rgq9favK+vIdWLn35miWUIYuPkiQlLCHks9//sZ3GWYs4uYzCdmoKKLcQ== + dependencies: + "@types/node-sass" "*" + "@types/sass" "*" + "@types/webpack" "^4" + +"@types/sass@*": + version "1.43.1" + resolved "https://registry.yarnpkg.com/@types/sass/-/sass-1.43.1.tgz#86bb0168e9e881d7dade6eba16c9ed6d25dc2f68" + integrity sha512-BPdoIt1lfJ6B7rw35ncdwBZrAssjcwzI5LByIrYs+tpXlj/CAkuVdRsgZDdP4lq5EjyWzwxZCqAoFyHKFwp32g== + dependencies: + "@types/node" "*" + "@types/serve-static@*", "@types/serve-static@^1.13.3": version "1.13.3" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.3.tgz#eb7e1c41c4468272557e897e9171ded5e2ded9d1" @@ -1723,6 +1832,14 @@ "@types/express-serve-static-core" "*" "@types/mime" "*" +"@types/serve-static@1.13.9": + version "1.13.9" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.9.tgz#aacf28a85a05ee29a11fb7c3ead935ac56f33e4e" + integrity sha512-ZFqF6qa48XsPdjXV5Gsz0Zqmux2PerNd3a/ktL45mHpa19cuMi/cL8tcxdAx497yRh+QtYPuofjT9oWw9P7nkA== + dependencies: + "@types/mime" "^1" + "@types/node" "*" + "@types/source-list-map@*": version "0.1.2" resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9" @@ -1738,6 +1855,19 @@ resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.5.tgz#9adbc12950582aa65ead76bffdf39fe0c27a3c02" integrity sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ== +"@types/tapable@^1": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.8.tgz#b94a4391c85666c7b73299fd3ad79d4faa435310" + integrity sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ== + +"@types/terser-webpack-plugin@4.2.1": + version "4.2.1" + resolved "https://registry.yarnpkg.com/@types/terser-webpack-plugin/-/terser-webpack-plugin-4.2.1.tgz#cbeccec2b011ad12a9ddcd60b4089c9e138a313a" + integrity sha512-x688KsgQKJF8PPfv4qSvHQztdZNHLlWJdolN9/ptAGimHVy3rY+vHdfglQDFh1Z39h7eMWOd6fQ7ke3PKQcdyA== + dependencies: + "@types/webpack" "^4" + terser "^4.6.13" + "@types/terser-webpack-plugin@^2.2.0": version "2.2.0" resolved "https://registry.yarnpkg.com/@types/terser-webpack-plugin/-/terser-webpack-plugin-2.2.0.tgz#b1561e3118b9319d80ff65798c345877669b3e12" @@ -1753,6 +1883,13 @@ dependencies: source-map "^0.6.1" +"@types/webpack-bundle-analyzer@3.9.3": + version "3.9.3" + resolved "https://registry.yarnpkg.com/@types/webpack-bundle-analyzer/-/webpack-bundle-analyzer-3.9.3.tgz#3a12025eb5d86069c30b47a157e62c0aca6e39a1" + integrity sha512-l/vaDMWGcXiMB3CbczpyICivLTB07/JNtn1xebsRXE9tPaUDEHgX3x7YP6jfznG5TOu7I4w0Qx1tZz61znmPmg== + dependencies: + "@types/webpack" "^4" + "@types/webpack-bundle-analyzer@^2.13.3": version "2.13.3" resolved "https://registry.yarnpkg.com/@types/webpack-bundle-analyzer/-/webpack-bundle-analyzer-2.13.3.tgz#820c8f734e171f081cbf02d889b9cda687cc89dd" @@ -1760,6 +1897,14 @@ dependencies: "@types/webpack" "*" +"@types/webpack-dev-middleware@4.1.2": + version "4.1.2" + resolved "https://registry.yarnpkg.com/@types/webpack-dev-middleware/-/webpack-dev-middleware-4.1.2.tgz#c683adc6a44d0b66e98f1932ab33d1c32d558142" + integrity sha512-SxXzPCqeZ03fJ2dg3iD7cSXvqZymmS5/2GD9fANRcyWN7HYK1H3ty6q7IInXZKvPrdUqij831G3RLIeKK6aGdw== + dependencies: + "@types/connect" "*" + "@types/webpack" "^4" + "@types/webpack-dev-middleware@^3.7.0": version "3.7.0" resolved "https://registry.yarnpkg.com/@types/webpack-dev-middleware/-/webpack-dev-middleware-3.7.0.tgz#3f90ddf22aef2c592eae528c08739bc4807a7d62" @@ -1770,6 +1915,14 @@ "@types/webpack" "*" loglevel "^1.6.2" +"@types/webpack-hot-middleware@2.25.4": + version "2.25.4" + resolved "https://registry.yarnpkg.com/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.25.4.tgz#e439e9a3694158badf23b094bc1ad6051767ca05" + integrity sha512-6tQb9EBKIANZYUVLQYWiWfDFVe7FhXSj4bB2EF5QB7VtYWL3HDR+y/zqjZPAnCorv0spLqVMRqjRK8AmhfocMw== + dependencies: + "@types/connect" "*" + "@types/webpack" "^4" + "@types/webpack-hot-middleware@^2.25.0": version "2.25.2" resolved "https://registry.yarnpkg.com/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.25.2.tgz#22280f76e86a9dae41bc55ca0de5e88d22178f86" @@ -1799,6 +1952,30 @@ "@types/webpack-sources" "*" source-map "^0.6.0" +"@types/webpack@4.41.28": + version "4.41.28" + resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.28.tgz#0069a2159b7ad4d83d0b5801942c17d54133897b" + integrity sha512-Nn84RAiJjKRfPFFCVR8LC4ueTtTdfWAMZ03THIzZWRJB+rX24BD3LqPSFnbMscWauEsT4segAsylPDIaZyZyLQ== + dependencies: + "@types/anymatch" "*" + "@types/node" "*" + "@types/tapable" "^1" + "@types/uglify-js" "*" + "@types/webpack-sources" "*" + source-map "^0.6.0" + +"@types/webpack@^4": + version "4.41.33" + resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.33.tgz#16164845a5be6a306bcbe554a8e67f9cac215ffc" + integrity sha512-PPajH64Ft2vWevkerISMtnZ8rTs4YmRbs+23c402J0INmxDKCrhZNvwZYtzx96gY2wAtXdrK1BS2fiC8MlLr3g== + dependencies: + "@types/node" "*" + "@types/tapable" "^1" + "@types/uglify-js" "*" + "@types/webpack-sources" "*" + anymatch "^3.0.0" + source-map "^0.6.0" + "@types/yargs-parser@*": version "15.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d" @@ -2141,6 +2318,11 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1: resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da" integrity sha512-RO1ibKvd27e6FEShVFfPALuHI3WjSVNeK5FIsmme/LYRNxjKuNj+Dt7bucLa6NdSv3JcVTyMlm9kGR84z1XpaQ== +ajv-keywords@^3.5.2: + version "3.5.2" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" + integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== + ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.5.5: version "6.12.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd" @@ -2151,6 +2333,16 @@ ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.5.5: json-schema-traverse "^0.4.1" uri-js "^4.2.2" +ajv@^6.12.5: + version "6.12.6" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" + integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== + dependencies: + fast-deep-equal "^3.1.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + alphanum-sort@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3" @@ -2228,6 +2420,14 @@ anymatch@^2.0.0: micromatch "^3.1.4" normalize-path "^2.1.1" +anymatch@^3.0.0: + version "3.1.3" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" + integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + anymatch@^3.0.3, anymatch@~3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.1.tgz#c55ecf02185e2469259399310c173ce31233b142" @@ -6645,6 +6845,11 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== +klona@^2.0.4: + version "2.0.5" + resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.5.tgz#d166574d90076395d9963aa7a928fabb8d76afbc" + integrity sha512-pJiBpiXMbt7dkzXe8Ghj/u4FfXOOa98fPW+bihOJ4SjnoijweJrNThJfd3ifXpXhREjpoF2mZVH1GfS9LV3kHQ== + last-call-webpack-plugin@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz#9742df0e10e3cf46e5c0381c2de90d3a7a2d7555" @@ -6748,6 +6953,15 @@ loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4 emojis-list "^3.0.0" json5 "^1.0.1" +loader-utils@^2.0.0: + version "2.0.4" + resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c" + integrity sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw== + dependencies: + big.js "^5.2.2" + emojis-list "^3.0.0" + json5 "^2.1.2" + loadjs@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/loadjs/-/loadjs-4.2.0.tgz#2a0336376397a6a43edf98c9ec3229ddd5abb6f6" @@ -7290,6 +7504,11 @@ neo-async@^2.5.0, neo-async@^2.6.0, neo-async@^2.6.1: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c" integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw== +neo-async@^2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" + integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== + nice-try@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" @@ -9314,6 +9533,17 @@ sane@^4.0.3: minimist "^1.1.1" walker "~1.0.5" +sass-loader@10.1.1: + version "10.1.1" + resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-10.1.1.tgz#4ddd5a3d7638e7949065dd6e9c7c04037f7e663d" + integrity sha512-W6gVDXAd5hR/WHsPicvZdjAWHBcEJ44UahgxcIE196fW2ong0ZHMPO1kZuI5q0VlvMQZh32gpv69PLWQm70qrw== + dependencies: + klona "^2.0.4" + loader-utils "^2.0.0" + neo-async "^2.6.2" + schema-utils "^3.0.0" + semver "^7.3.2" + sax@~1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -9343,6 +9573,15 @@ schema-utils@^2.0.0, schema-utils@^2.5.0, schema-utils@^2.6.1, schema-utils@^2.6 ajv "^6.12.0" ajv-keywords "^3.4.1" +schema-utils@^3.0.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" + integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + semver-compare@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" @@ -10117,6 +10356,15 @@ terser@^4.1.2, terser@^4.3.9, terser@^4.6.12: source-map "~0.6.1" source-map-support "~0.5.12" +terser@^4.6.13: + version "4.8.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.1.tgz#a00e5634562de2239fd404c649051bf6fc21144f" + integrity sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw== + dependencies: + commander "^2.20.0" + source-map "~0.6.1" + source-map-support "~0.5.12" + test-exclude@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e" From a5b3a9cd740be1080979c602e58c44935d92c7c1 Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Thu, 1 Dec 2022 02:40:08 -0500 Subject: [PATCH 4/7] test: add unit tests for gtag --- test/fixture/gtag/nuxt.config.js | 10 ++++++++ test/fixture/gtag/pages/index.vue | 11 ++++++++ test/gtag.test.js | 42 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 test/fixture/gtag/nuxt.config.js create mode 100644 test/fixture/gtag/pages/index.vue create mode 100644 test/gtag.test.js diff --git a/test/fixture/gtag/nuxt.config.js b/test/fixture/gtag/nuxt.config.js new file mode 100644 index 0000000..f08dd48 --- /dev/null +++ b/test/fixture/gtag/nuxt.config.js @@ -0,0 +1,10 @@ +module.exports = { + rootDir: __dirname, + buildModules: [ + { handler: require('../../../') } + ], + googleAnalytics: { + id: 'XXX', + useGtag: true + } +} diff --git a/test/fixture/gtag/pages/index.vue b/test/fixture/gtag/pages/index.vue new file mode 100644 index 0000000..6218ede --- /dev/null +++ b/test/fixture/gtag/pages/index.vue @@ -0,0 +1,11 @@ + + + diff --git a/test/gtag.test.js b/test/gtag.test.js new file mode 100644 index 0000000..53309cc --- /dev/null +++ b/test/gtag.test.js @@ -0,0 +1,42 @@ +const { setup, loadConfig, get, url } = require('@nuxtjs/module-test-utils') + +describe('prod', () => { + let nuxt, addTemplate + + beforeAll(async () => { + const beforeNuxtReady = (nuxt) => { + addTemplate = nuxt.moduleContainer.addTemplate = jest.fn( + nuxt.moduleContainer.addTemplate + ) + } + ({ nuxt } = (await setup(loadConfig(__dirname, 'gtag'), { beforeNuxtReady }))) + }, 60000) + + afterAll(async () => { + await nuxt.close() + }) + + test('render', async () => { + const html = await get('/') + expect(html).toContain('Works!') + }) + + test('$gtag should be defined', async () => { + const window = await nuxt.renderAndGetWindow(url('/')) + expect(window.$nuxt.$gtag).toBeDefined() + }) + + test('$ga should not be defined', async () => { + const window = await nuxt.renderAndGetWindow(url('/')) + expect(window.$nuxt.$ga).not.toBeDefined() + }) + + test('option id', () => { + expect(addTemplate).toBeDefined() + const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js')) + expect(call).toBeDefined() + const options = call[0].options + expect(options.id).toBe('XXX') + expect(options.useGtag).toBe(true) + }) +}) From 32503907fc9c8e6ece920ecbbd51f6a78e60b59f Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Sat, 3 Dec 2022 13:37:45 -0500 Subject: [PATCH 5/7] docs: include information on how to use Google Analytics 4 --- docs/content/en/index.md | 2 +- docs/content/en/options.md | 54 +++++++++++++++++++++++- docs/content/en/setup.md | 5 ++- docs/content/en/usage/event-tracking.md | 4 ++ docs/content/en/usage/page-tracking.md | 4 ++ docs/content/en/usage/screen-tracking.md | 4 ++ docs/content/en/usage/time-tracking.md | 4 ++ 7 files changed, 73 insertions(+), 4 deletions(-) diff --git a/docs/content/en/index.md b/docs/content/en/index.md index 3ee97d4..cbd22de 100644 --- a/docs/content/en/index.md +++ b/docs/content/en/index.md @@ -16,7 +16,7 @@ features: -[Google Analytics](https://analytics.google.com/analytics/web/) integration for [Nuxt](https://nuxtjs.org) using [vue-analytics](https://github.com/MatteoGabriele/vue-analytics). +[Google Analytics](https://analytics.google.com/analytics/web/) integration for [Nuxt](https://nuxtjs.org) using [vue-analytics](https://github.com/MatteoGabriele/vue-analytics) for Google Analytics 3 and [vue-gtag](https://github.com/MatteoGabriele/vue-gtag) for Google Analytics 4. Track the visitors to your sites and applications, measure your ROI and provide in-depth analysis details about your visitors' behaviors. diff --git a/docs/content/en/options.md b/docs/content/en/options.md index 2230316..d735b27 100644 --- a/docs/content/en/options.md +++ b/docs/content/en/options.md @@ -70,6 +70,24 @@ If both `id` and `asyncID` are present, the returned value from `asyncID` will o + +### `useGtag` + +* Type: `Boolean` +* default: `false` + +If set to `true`, the module will use [Google Analytics 4](#google-analytics-4). By default, the module uses [Google Analytics 3](#google-analytics-3). Refer to the respective sections for options below. + +## Google Analytics 3 + +The following options are only applicable if you have `useGtag` set to false. + + + +For a full list of options, please see [Vue Analytics](https://matteogabriele.gitbooks.io/vue-analytics) documentation. + + + ### `debug` * Type: `Object` @@ -110,8 +128,42 @@ export default { } ``` +## Google Analytics 4 + +The following options are only applicable if you have `useGtag` set to true. + -For a full list of options, please see [Vue Analytics](https://matteogabriele.gitbooks.io/vue-analytics) documentation. +For a full list of options, please see [Vue Gtag v1](https://matteo-gabriele.gitbook.io/vue-gtag/v/master/) documentation. + +### `disableScriptLoad` + +* Type: `Boolean` + +Disable the script loader + +```js[nuxt.config.js] +export default { + googleAnalytics: { + disableScriptLoad: true + } +} +``` + +### `onReady` + +* Type: `Function` + +Will fire when the gtag script is successfully loaded + +```js[nuxt.config.js] +export default { + googleAnalytics: { + onReady() { + // Ready! + } + } +} +``` diff --git a/docs/content/en/setup.md b/docs/content/en/setup.md index c552b54..3265a4b 100644 --- a/docs/content/en/setup.md +++ b/docs/content/en/setup.md @@ -6,8 +6,9 @@ category: Guide --- -> **⚠ WARNING: This package does not support GA4. ** -> This package currently only supports GA3/UA + + If you need Google Analytics 4 support, check our documentation on the `useGtag` option here + Check the [Nuxt.js documentation](https://nuxtjs.org/guides/configuration-glossary/configuration-modules) for more information about installing and using modules in Nuxt.js. diff --git a/docs/content/en/usage/event-tracking.md b/docs/content/en/usage/event-tracking.md index 145ee26..81d7ea2 100644 --- a/docs/content/en/usage/event-tracking.md +++ b/docs/content/en/usage/event-tracking.md @@ -5,6 +5,10 @@ position: 5 category: Usage --- + +This documentation is only applicable when the Google Analytics 3 is enabled. For documentation on event tracking with Google Analytics 4, see vue-gtag/event documentation. + + This module injects `$ga` instance globally. You can access the instance anywhere using: diff --git a/docs/content/en/usage/page-tracking.md b/docs/content/en/usage/page-tracking.md index 739f220..f2f92d8 100644 --- a/docs/content/en/usage/page-tracking.md +++ b/docs/content/en/usage/page-tracking.md @@ -5,6 +5,10 @@ position: 4 category: Usage --- + +This documentation is only applicable when the Google Analytics 3 is enabled. For documentation on event tracking with Google Analytics 4, see vue-gtag/pageview documentation. + + This module injects `$ga` instance globally. You can access the instance anywhere using `this.$ga` (within a component), or `context.$ga` (for plugins, `asyncData`, `fetch`, `nuxtServerInit` ,and middleware) ## Automatic page tracking diff --git a/docs/content/en/usage/screen-tracking.md b/docs/content/en/usage/screen-tracking.md index c57e947..714f6a9 100644 --- a/docs/content/en/usage/screen-tracking.md +++ b/docs/content/en/usage/screen-tracking.md @@ -5,6 +5,10 @@ position: 6 category: Usage --- + +This documentation is only applicable when the Google Analytics 3 is enabled. For documentation on event tracking with Google Analytics 4, see vue-gtag/screenview documentation. + + This module injects `$ga` instance globally. You can access the instance anywhere using `this.$ga` (within a component), or `context.$ga` (for plugins, `asyncData`, `fetch`, `nuxtServerInit` ,and middleware) ## `screenview(options)` diff --git a/docs/content/en/usage/time-tracking.md b/docs/content/en/usage/time-tracking.md index 5314f63..799628f 100644 --- a/docs/content/en/usage/time-tracking.md +++ b/docs/content/en/usage/time-tracking.md @@ -5,6 +5,10 @@ position: 7 category: Usage --- + +This documentation is only applicable when the Google Analytics 3 is enabled. For documentation on event tracking with Google Analytics 4, see vue-gtag/time documentation. + + This module injects `$ga` instance globally. You can access the instance anywhere using `this.$ga` (within a component), or `context.$ga` (for plugins, `asyncData`, `fetch`, `nuxtServerInit` ,and middleware) ## `time()` From 10c7a00b177f89ddb58187345b10f73d7ae2e705 Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Sat, 3 Dec 2022 13:38:21 -0500 Subject: [PATCH 6/7] docs: remove warning about GA3 support --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index c870895..c6a6411 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ [![@nuxtjs/google-analytics](https://google-analytics.nuxtjs.org/preview.png)](https://google-analytics.nuxtjs.org) - -> **⚠ WARNING: This package does not support GA4. ** -> This package currently only supports GA3/UA - # @nuxtjs/google-analytics [![npm version][npm-version-src]][npm-version-href] From 6372992d1178debff9fd7cc265c09b068063aa6c Mon Sep 17 00:00:00 2001 From: Abbondanzo Date: Sun, 4 Dec 2022 16:52:27 -0500 Subject: [PATCH 7/7] docs: add vue-gtag attribution to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6a6411..0677d13 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Codecov][codecov-src]][codecov-href] [![License][license-src]][license-href] -> [Google Analytics](https://analytics.google.com/analytics/web/) integration for [Nuxt](https://nuxtjs.org) using [vue-analytics](https://github.com/MatteoGabriele/vue-analytics). +> [Google Analytics](https://analytics.google.com/analytics/web/) integration for [Nuxt](https://nuxtjs.org) using [vue-analytics](https://github.com/MatteoGabriele/vue-analytics) for Google Analytics 3 and [vue-gtag](https://github.com/MatteoGabriele/vue-gtag) for Google Analytics 4. - [✨  Release Notes](./CHANGELOG.md) - [📖  Documentation](https://google-analytics.nuxtjs.org)