mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
Add google analytics event tracking
This commit is contained in:
parent
a58c1ad22b
commit
dea838ecce
1 changed files with 17 additions and 2 deletions
|
@ -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');
|
||||
|
|
Loading…
Add table
Reference in a new issue