Skip to content

Commit

Permalink
add : setup google analytic
Browse files Browse the repository at this point in the history
  • Loading branch information
artdvp committed Mar 17, 2018
1 parent 09fd235 commit c81f8c3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $ npm install -g netlify-cli
* [x] Add About Section
* [x] Add Love Section
* [x] Add Js-World Section
* [ ] Setup Custom Domain
* [x] Setup Custom Domain
* [x] Setup Google Analytic
* [ ] Add [Particle.js](https://github.com/creotip/vue-particles) to page
* [ ] Setup About
42 changes: 42 additions & 0 deletions plugins/ga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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-88702930-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");
});
};

0 comments on commit c81f8c3

Please sign in to comment.