Skip to content

Commit

Permalink
Update ga tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
fdaciuk committed Aug 10, 2016
1 parent b173380 commit 96f5a99
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions trackers/ga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Maybe, isClientSide } = require('../lib/utils');
const { Maybe, isClientSide, is } = require('../lib/utils');

// Google Analytics Tracker

Expand All @@ -18,14 +18,30 @@ module.exports = () => {
return GA;
})();

const areAllFieldsOk = (gaFields) => {
if(!gaFields || !is('object', gaFields)) {
return false;
}

if(!gaFields.metadata) {
return false;
}

if(!gaFields.metadata.label && !gaFields.metadata.value) {
return false;
}

return true;
};

gaTracker.createEvent = (eventName, eventData) => {
if(eventName && eventData) {
if(eventName && areAllFieldsOk(eventData)) {
ga('send', {
hitType: 'event',
eventCategory: eventName,
eventAction: Maybe(eventData.action),
eventLabel: Maybe(eventData.label),
eventValue: Maybe(eventData.value)
eventLabel: Maybe(eventData.metadata.label),
eventValue: Maybe(eventData.metadata.value)
});
}

Expand Down

0 comments on commit 96f5a99

Please sign in to comment.