mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import Telescope from 'meteor/nova:lib';
|
|
import Events from '../collection.js';
|
|
import { Callbacks } from 'meteor/nova:core';
|
|
|
|
Events.analyticsRequest = function() {
|
|
// Google Analytics
|
|
if (typeof window.ga !== 'undefined'){
|
|
window.ga('send', 'pageview', {
|
|
'page': window.location.pathname
|
|
});
|
|
}
|
|
};
|
|
|
|
Events.analyticsInit = function() {
|
|
|
|
// Google Analytics
|
|
const googleAnalyticsId = Telescope.settings.get("googleAnalyticsId");
|
|
if (googleAnalyticsId) {
|
|
|
|
(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','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
var cookieDomain = document.domain === "localhost" ? "none" : "auto";
|
|
|
|
window.ga('create', googleAnalyticsId, cookieDomain);
|
|
|
|
}
|
|
|
|
// trigger first request once analytics are initialized
|
|
Events.analyticsRequest();
|
|
|
|
};
|
|
|
|
Events.analyticsInit();
|
|
|
|
function analyticsRequest () {
|
|
Events.analyticsRequest();
|
|
}
|
|
Callbacks.add('router.onUpdate', analyticsRequest);
|