Skip to content

Commit c2f6ec6

Browse files
committed
Added ga
1 parent 06863ad commit c2f6ec6

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

nuxt.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ module.exports = {
4747
/*
4848
** Plugins to load before mounting the App
4949
*/
50-
plugins: [],
50+
plugins: [
51+
{ src: '~plugins/ga.js', mode: 'client' }
52+
],
5153

5254
/*
5355
** Nuxt.js modules

plugins/ga.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-disable */
2+
3+
export default ({ app }) => {
4+
/*
5+
** Only run on client-side and only in production mode
6+
*/
7+
if (process.env.NODE_ENV !== 'production') return
8+
/*
9+
** Include Google Analytics Script
10+
*/
11+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
12+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
13+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
14+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
15+
/*
16+
** Set the current page
17+
*/
18+
ga('create', 'UA-160636504-1', 'auto')
19+
/*
20+
** Every time the route changes (fired on initialization too)
21+
*/
22+
app.router.afterEach((to, from) => {
23+
/*
24+
** We tell Google Analytics to add a `pageview`
25+
*/
26+
ga('set', 'page', to.fullPath)
27+
ga('send', 'pageview')
28+
})
29+
}

0 commit comments

Comments
 (0)