From 3fa8c9b9bd1ced20504ad178f300ab63b716bdcb Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 10 Sep 2018 00:30:03 +0200 Subject: [PATCH] feat(ga): use nuxt module instead --- nuxt.config.js | 11 ++++++++--- package-lock.json | 13 +++++++++++++ package.json | 1 + plugins/ga.js | 44 -------------------------------------------- 4 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 plugins/ga.js diff --git a/nuxt.config.js b/nuxt.config.js index bdf9738..7fe5efe 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -20,9 +20,14 @@ module.exports = { : "http://localhost:3000" }, css: ["normalize.css/normalize.css"], - plugins: [ - { src: "@/plugins/ga.js", ssr: false }, - { src: "@/plugins/global.js" } + plugins: [{ src: "@/plugins/global.js" }], + modules: [ + [ + "@nuxtjs/google-analytics", + { + id: "UA-125493236-1" + } + ] ], build: { extend(config, { isDev, isClient }) { diff --git a/package-lock.json b/package-lock.json index 56bb454..35d5929 100644 --- a/package-lock.json +++ b/package-lock.json @@ -151,6 +151,14 @@ } } }, + "@nuxtjs/google-analytics": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@nuxtjs/google-analytics/-/google-analytics-2.0.2.tgz", + "integrity": "sha512-NpDQI7w4jr93Ukh98n3d0BRDHhX7cDUi3W2E0CAU6t5wmC+Q6cwQMqcEl32tGJBQlPZYWSrBKIM0A413HpL3TA==", + "requires": { + "vue-analytics": "5.16.0" + } + }, "@nuxtjs/youch": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/@nuxtjs/youch/-/youch-4.2.3.tgz", @@ -11147,6 +11155,11 @@ "resolved": "https://registry.npmjs.org/vue/-/vue-2.5.17.tgz", "integrity": "sha512-mFbcWoDIJi0w0Za4emyLiW72Jae0yjANHbCVquMKijcavBGypqlF7zHRgMa5k4sesdv7hv2rB4JPdZfR+TPfhQ==" }, + "vue-analytics": { + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/vue-analytics/-/vue-analytics-5.16.0.tgz", + "integrity": "sha512-WOdI1Ot/Tq3xHIIu3a5hiLawMrQeHsgqwcvHdZb5CNV4IM3RWZ3rw1gCnsAGbSWGPQw88mjkY9wuG5CXmfsssA==" + }, "vue-eslint-parser": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-2.0.3.tgz", diff --git a/package.json b/package.json index c325659..861ca3b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "precommit": "npm run lint" }, "dependencies": { + "@nuxtjs/google-analytics": "^2.0.2", "lodash": "^4.17.10", "normalize.css": "^8.0.0", "nuxt": "^1.0.0" diff --git a/plugins/ga.js b/plugins/ga.js deleted file mode 100644 index 3dcf73b..0000000 --- a/plugins/ga.js +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable */ - -export default ({ app }) => { - /* - ** Only run on client-side and only in production mode - */ - if (process.env.NODE_ENV !== "production") return; - /* - ** Include Google Analytics Script - */ - (function(i, s, o, g, r, a, m) { - i["GoogleAnalyticsObject"] = r; - (i[r] = - i[r] || - function() { - (i[r].q = i[r].q || []).push(arguments); - }), - (i[r].l = 1 * new Date()); - (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); - a.async = 1; - a.src = g; - m.parentNode.insertBefore(a, m); - })( - window, - document, - "script", - "https://www.google-analytics.com/analytics.js", - "ga" - ); - /* - ** Set the current page - */ - ga("create", "UA-125493236-1", "auto"); - /* - ** Every time the route changes (fired on initialization too) - */ - app.router.afterEach((to, from) => { - /* - ** We tell Google Analytics to add a `pageview` - */ - ga("set", "page", to.fullPath); - ga("send", "pageview"); - }); -};