mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Update how info is sent to google
This commit is contained in:
@@ -61,8 +61,7 @@ describe('analytics', function() {
|
||||
|
||||
var event_type = 'Cron';
|
||||
var analyticsData = {
|
||||
gaCategory: 'behavior',
|
||||
gaLabel: 'Ga Label',
|
||||
category: 'behavior',
|
||||
uuid: 'unique-user-id',
|
||||
resting: true,
|
||||
cronCount: 5
|
||||
@@ -88,6 +87,7 @@ describe('analytics', function() {
|
||||
event_type: 'Cron',
|
||||
user_id: 'unique-user-id',
|
||||
event_properties: {
|
||||
category: 'behavior',
|
||||
resting: true,
|
||||
cronCount: 5
|
||||
}
|
||||
@@ -112,6 +112,7 @@ describe('analytics', function() {
|
||||
event_type: 'Cron',
|
||||
user_id: 'unique-user-id',
|
||||
event_properties: {
|
||||
category: 'behavior',
|
||||
resting: true,
|
||||
cronCount: 5
|
||||
},
|
||||
@@ -137,7 +138,68 @@ describe('analytics', function() {
|
||||
expect(googleEvent).to.be.calledWith(
|
||||
'behavior',
|
||||
'Cron',
|
||||
'Ga Label'
|
||||
'Label Not Specified'
|
||||
);
|
||||
});
|
||||
|
||||
it('if goldCost property is provided, use as label', function() {
|
||||
var data = _.cloneDeep(analyticsData);
|
||||
data.goldCost = 4;
|
||||
|
||||
initializedAnalytics.track(event_type, data);
|
||||
|
||||
expect(googleEvent).to.be.calledOnce;
|
||||
expect(googleEvent).to.be.calledWith(
|
||||
'behavior',
|
||||
'Cron',
|
||||
4
|
||||
);
|
||||
});
|
||||
|
||||
it('if gemCost property is provided, use as label (overrides goldCost)', function() {
|
||||
var data = _.cloneDeep(analyticsData);
|
||||
data.goldCost = 10;
|
||||
data.itemName = 50;
|
||||
|
||||
initializedAnalytics.track(event_type, data);
|
||||
|
||||
expect(googleEvent).to.be.calledOnce;
|
||||
expect(googleEvent).to.be.calledWith(
|
||||
'behavior',
|
||||
'Cron',
|
||||
50
|
||||
);
|
||||
});
|
||||
|
||||
it('if itemName property is provided, use as label (overrides gem/goldCost)', function() {
|
||||
var data = _.cloneDeep(analyticsData);
|
||||
data.goldCost = 5;
|
||||
data.gemCost = 50;
|
||||
data.itemName = 'some item';
|
||||
|
||||
initializedAnalytics.track(event_type, data);
|
||||
|
||||
expect(googleEvent).to.be.calledOnce;
|
||||
expect(googleEvent).to.be.calledWith(
|
||||
'behavior',
|
||||
'Cron',
|
||||
'some item'
|
||||
);
|
||||
});
|
||||
|
||||
it('if gaLabel property is provided, use as label (overrides itemName)', function() {
|
||||
var data = _.cloneDeep(analyticsData);
|
||||
data.value = 'some value';
|
||||
data.itemName = 'some item';
|
||||
data.gaLabel = 'some label';
|
||||
|
||||
initializedAnalytics.track(event_type, data);
|
||||
|
||||
expect(googleEvent).to.be.calledOnce;
|
||||
expect(googleEvent).to.be.calledWith(
|
||||
'behavior',
|
||||
'Cron',
|
||||
'some label'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,11 +31,26 @@ function _sendDataToAmplitude(eventType, data) {
|
||||
}
|
||||
|
||||
function _sendDataToGoogle(eventType, data) {
|
||||
var category = data.gaCategory;
|
||||
var label = data.gaLabel;
|
||||
var category = data.category;
|
||||
var label = _generateLabelForGoogleAnalytics(data);
|
||||
|
||||
ga.event(category, eventType, label).send();
|
||||
}
|
||||
|
||||
function _generateLabelForGoogleAnalytics(data) {
|
||||
var label = 'Label Not Specified';
|
||||
var POSSIBLE_LABELS = ['gaLabel', 'itemName', 'gemCost', 'goldCost'];
|
||||
|
||||
_(POSSIBLE_LABELS).each(function(key) {
|
||||
if(data[key]) {
|
||||
label = data[key];
|
||||
return false; // exit _.each early
|
||||
}
|
||||
});
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
function trackPurchase(data) {
|
||||
_sendPurchaseDataToAmplitude(data);
|
||||
_sendPurchaseDataToGoogle(data);
|
||||
@@ -50,7 +65,7 @@ function _sendPurchaseDataToAmplitude(data) {
|
||||
}
|
||||
|
||||
function _formatDataForAmplitude(data) {
|
||||
var PROPERTIES_TO_SCRUB = ['uuid', 'user', 'purchaseValue', 'gaCategory', 'gaLabel'];
|
||||
var PROPERTIES_TO_SCRUB = ['uuid', 'user', 'purchaseValue', 'gaLabel'];
|
||||
var event_properties = _.omit(data, PROPERTIES_TO_SCRUB);
|
||||
|
||||
var ampData = {
|
||||
|
||||
Reference in New Issue
Block a user