Use another way to enable google analytics

This commit is contained in:
2020-08-30 00:33:14 +10:00
parent 89d8552603
commit ff4df285bf
3 changed files with 45 additions and 18 deletions
-16
View File
@@ -31,22 +31,6 @@
</b-col>
</b-row>
<div v-if="isProduction">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=UA-5243064-21"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "UA-5243064-21");
</script>
</div>
</b-overlay>
</template>
+1 -2
View File
@@ -34,8 +34,7 @@ export default {
** Plugins to load before mounting the App
** https://nuxtjs.org/guide/plugins
*/
plugins: [
],
plugins: [{ src: '~plugins/ga.js', mode: 'client' }],
/*
** Auto import components
** See https://nuxtjs.org/api/configuration-components
+44
View File
@@ -0,0 +1,44 @@
/* 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-5243064-21", "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");
});
};