Add google analytics event tracking

This commit is contained in:
SachaG 2018-12-02 22:33:57 +09:00
parent a58c1ad22b
commit dea838ecce

View file

@ -1,5 +1,5 @@
import { getSetting } from 'meteor/vulcan:core';
import { addPageFunction, addInitFunction } from 'meteor/vulcan:events';
import { addPageFunction, addInitFunction, addTrackFunction } from 'meteor/vulcan:events';
/*
@ -19,10 +19,25 @@ function googleAnaticsTrackPage() {
}
return {};
}
// add client-side callback: log a ga request on page view
addPageFunction(googleAnaticsTrackPage);
function googleAnaticsTrackEvent(name, properties, currentUser) {
const { category = name, action = name, label = name, value } = properties;
if (window && window.ga) {
window.ga('send', {
hitType: 'event',
eventCategory: category,
eventAction: action,
eventLabel: label,
eventValue: value,
});
}
return {};
}
// add client-side callback: log a ga request on page view
addTrackFunction(googleAnaticsTrackEvent);
function googleAnalyticsInit() {
// get the google analytics id from the settings
const googleAnalyticsId = getSetting('googleAnalytics.apiKey');