feat(ga): use nuxt module instead

This commit is contained in:
Julien 2018-09-10 00:30:03 +02:00
parent ec7ea1a63e
commit 3fa8c9b9bd
4 changed files with 22 additions and 47 deletions

View File

@ -20,9 +20,14 @@ module.exports = {
: "http://localhost:3000" : "http://localhost:3000"
}, },
css: ["normalize.css/normalize.css"], css: ["normalize.css/normalize.css"],
plugins: [ plugins: [{ src: "@/plugins/global.js" }],
{ src: "@/plugins/ga.js", ssr: false }, modules: [
{ src: "@/plugins/global.js" } [
"@nuxtjs/google-analytics",
{
id: "UA-125493236-1"
}
]
], ],
build: { build: {
extend(config, { isDev, isClient }) { extend(config, { isDev, isClient }) {

13
package-lock.json generated
View File

@ -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": { "@nuxtjs/youch": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/@nuxtjs/youch/-/youch-4.2.3.tgz", "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", "resolved": "https://registry.npmjs.org/vue/-/vue-2.5.17.tgz",
"integrity": "sha512-mFbcWoDIJi0w0Za4emyLiW72Jae0yjANHbCVquMKijcavBGypqlF7zHRgMa5k4sesdv7hv2rB4JPdZfR+TPfhQ==" "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": { "vue-eslint-parser": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-2.0.3.tgz", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-2.0.3.tgz",

View File

@ -13,6 +13,7 @@
"precommit": "npm run lint" "precommit": "npm run lint"
}, },
"dependencies": { "dependencies": {
"@nuxtjs/google-analytics": "^2.0.2",
"lodash": "^4.17.10", "lodash": "^4.17.10",
"normalize.css": "^8.0.0", "normalize.css": "^8.0.0",
"nuxt": "^1.0.0" "nuxt": "^1.0.0"

View File

@ -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");
});
};