Skip to content

Add analytics w/ page views via Countly #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,39 @@
}
return dntStatus === 'Enabled'
}
/* From https://github.com/nodejs/nodejs.org/blob/703bacbc0da63fa91f156468209758c66c01f30f/layouts/partials/footer.hbs */

//some default pre init
var Countly = Countly || {};
Countly.q = Countly.q || [];

(function(){

// ************ FOR TESTING ONLY ************************
// Uncomment line below for testing, comment out for deployment
// if (!_dntEnabled()) {
// *******************************************************

// *********** FOR DEPLOYMENT *****************************
// Comment out line below for testing, uncomment for deployment
if (!_dntEnabled() && location.hostname === 'proto.school') {
!function(n,o,d,e,j,s){n.GoogleAnalyticsObject=d;n[d]||(n[d]=function(){
(n[d].q=n[d].q||[]).push(arguments)});n[d].l=+new Date;j=o.createElement(e);
s=o.getElementsByTagName(e)[0];j.async=1;j.src='//www.google-analytics.com/analytics.js';
s.parentNode.insertBefore(j,s)}(window,document,'ga','script');
if (!ga) return;
ga('create', 'UA-96910779-4', 'auto');
ga('send', 'pageview');
document.documentElement.addEventListener('click', function(e) {
// Track case studies
if(!e.target || !e.target.dataset || !e.target.dataset.casestudy) return;
ga('send', 'event', {
eventCategory: 'casestudy',
eventAction: 'click',
eventLabel: e.target.dataset.casestudy,
eventValue: 0
});
});
}
// *******************************************************

//provide countly initialization parameters
Countly.app_key = 'c785b6eaa9c61617e1a7db83cb437e5f3dfe4280';
Countly.url = 'https://countly.ipfs.io';

Countly.q.push(['track_sessions']);
Countly.q.push(['track_pageview']);
Countly.q.push(['track_clicks']);

//load countly script asynchronously
var cly = document.createElement('script'); cly.type = 'text/javascript';
cly.async = true;
//enter url of script here
cly.src = 'https://countly.ipfs.io/sdk/web/countly.min.js';
cly.onload = function(){Countly.init()};
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);
}
})();
</script>
</body>
Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ const router = new VueRouter({
}
})

// track page view via Countly when route changes
router.afterEach((to) => {
if (!window.Countly) return
window.Countly.q.push(['track_pageview', to.path])
})

Vue.config.productionTip = false

new Vue({
Expand Down