mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-14 07:42:06 +05:30
GA SPA integration
This commit is contained in:
parent
251a1237b4
commit
e0a1f0c845
@ -29,16 +29,12 @@
|
|||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<!-- Google Analytics -->
|
<!-- Google Analytics -->
|
||||||
<script>
|
<script>
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
ga('create', '<%- htmlWebpackPlugin.options.ga.id %>', 'auto');
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
</script>
|
||||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
||||||
|
<!-- End Google Analytics -->
|
||||||
ga('create', '<%- htmlWebpackPlugin.options.ga.id %>', 'auto');
|
|
||||||
ga('send', 'pageview');
|
|
||||||
</script>
|
|
||||||
<!-- End Google Analytics -->
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
13
src/index.js
13
src/index.js
@ -87,6 +87,19 @@ function restoreScroll() {
|
|||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browserHistory.listen(trackPageView);
|
||||||
|
|
||||||
|
function trackPageView(location) {
|
||||||
|
const ga = window.ga;
|
||||||
|
|
||||||
|
if (!ga) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ga('set', 'page', location.pathname + location.search);
|
||||||
|
ga('send', 'pageview');
|
||||||
|
}
|
||||||
|
|
||||||
/* global process: false */
|
/* global process: false */
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
// some shortcuts for testing on localhost
|
// some shortcuts for testing on localhost
|
||||||
|
Loading…
x
Reference in New Issue
Block a user