mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-26 15:00:23 +05:30
GA SPA integration
This commit is contained in:
parent
251a1237b4
commit
e0a1f0c845
@ -29,16 +29,12 @@
|
||||
}
|
||||
%>
|
||||
<!-- 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');
|
||||
|
||||
ga('create', '<%- htmlWebpackPlugin.options.ga.id %>', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- End Google Analytics -->
|
||||
<script>
|
||||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
||||
ga('create', '<%- htmlWebpackPlugin.options.ga.id %>', 'auto');
|
||||
</script>
|
||||
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
||||
<!-- End Google Analytics -->
|
||||
<% } %>
|
||||
</body>
|
||||
</html>
|
||||
|
13
src/index.js
13
src/index.js
@ -87,6 +87,19 @@ function restoreScroll() {
|
||||
}, 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 */
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// some shortcuts for testing on localhost
|
||||
|
Loading…
Reference in New Issue
Block a user