mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Add platform, change itemName to itemKey
This commit is contained in:
@@ -820,7 +820,7 @@ api.wrap = (user, main=true) ->
|
|||||||
|
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: key,
|
itemKey: key,
|
||||||
acquireMethod: 'Gold',
|
acquireMethod: 'Gold',
|
||||||
goldCost: convRate,
|
goldCost: convRate,
|
||||||
category: 'behavior'
|
category: 'behavior'
|
||||||
@@ -847,7 +847,7 @@ api.wrap = (user, main=true) ->
|
|||||||
|
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: key,
|
itemKey: key,
|
||||||
itemType: 'Market',
|
itemType: 'Market',
|
||||||
acquireMethod: 'Gems',
|
acquireMethod: 'Gems',
|
||||||
gemCost: item.value,
|
gemCost: item.value,
|
||||||
@@ -977,7 +977,7 @@ api.wrap = (user, main=true) ->
|
|||||||
|
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: key,
|
itemKey: key,
|
||||||
acquireMethod: 'Gold',
|
acquireMethod: 'Gold',
|
||||||
goldCost: item.value,
|
goldCost: item.value,
|
||||||
category: 'behavior'
|
category: 'behavior'
|
||||||
@@ -996,7 +996,7 @@ api.wrap = (user, main=true) ->
|
|||||||
user.items.gear.owned[i.key]=true
|
user.items.gear.owned[i.key]=true
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: i.key,
|
itemKey: i.key,
|
||||||
itemType: 'Subscriber Gear',
|
itemType: 'Subscriber Gear',
|
||||||
acquireMethod: 'Hourglass',
|
acquireMethod: 'Hourglass',
|
||||||
category: 'behavior'
|
category: 'behavior'
|
||||||
@@ -1076,7 +1076,7 @@ api.wrap = (user, main=true) ->
|
|||||||
|
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: path,
|
itemKey: path,
|
||||||
itemType: 'customization',
|
itemType: 'customization',
|
||||||
acquireMethod: 'Gems',
|
acquireMethod: 'Gems',
|
||||||
gemCost: (cost/.25),
|
gemCost: (cost/.25),
|
||||||
@@ -1170,7 +1170,7 @@ api.wrap = (user, main=true) ->
|
|||||||
|
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: item,
|
itemKey: item,
|
||||||
itemType: 'Subscriber Gear',
|
itemType: 'Subscriber Gear',
|
||||||
acquireMethod: 'Subscriber',
|
acquireMethod: 'Subscriber',
|
||||||
category: 'behavior'
|
category: 'behavior'
|
||||||
@@ -1628,7 +1628,7 @@ api.wrap = (user, main=true) ->
|
|||||||
|
|
||||||
analyticsData = {
|
analyticsData = {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
itemName: 'quest drop: ' + k,
|
itemKey: 'quest drop: ' + k,
|
||||||
acquireMethod: 'Drop',
|
acquireMethod: 'Drop',
|
||||||
category: 'behavior'
|
category: 'behavior'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ describe('analytics', function() {
|
|||||||
expect(amplitudeTrack).to.be.calledWith({
|
expect(amplitudeTrack).to.be.calledWith({
|
||||||
event_type: 'Cron',
|
event_type: 'Cron',
|
||||||
user_id: 'unique-user-id',
|
user_id: 'unique-user-id',
|
||||||
|
platform: 'server',
|
||||||
event_properties: {
|
event_properties: {
|
||||||
category: 'behavior',
|
category: 'behavior',
|
||||||
resting: true,
|
resting: true,
|
||||||
@@ -111,6 +112,7 @@ describe('analytics', function() {
|
|||||||
expect(amplitudeTrack).to.be.calledWith({
|
expect(amplitudeTrack).to.be.calledWith({
|
||||||
event_type: 'Cron',
|
event_type: 'Cron',
|
||||||
user_id: 'unique-user-id',
|
user_id: 'unique-user-id',
|
||||||
|
platform: 'server',
|
||||||
event_properties: {
|
event_properties: {
|
||||||
category: 'behavior',
|
category: 'behavior',
|
||||||
resting: true,
|
resting: true,
|
||||||
@@ -159,7 +161,7 @@ describe('analytics', function() {
|
|||||||
it('if gemCost property is provided, use as label (overrides goldCost)', function() {
|
it('if gemCost property is provided, use as label (overrides goldCost)', function() {
|
||||||
var data = _.cloneDeep(analyticsData);
|
var data = _.cloneDeep(analyticsData);
|
||||||
data.goldCost = 10;
|
data.goldCost = 10;
|
||||||
data.itemName = 50;
|
data.itemKey = 50;
|
||||||
|
|
||||||
initializedAnalytics.track(event_type, data);
|
initializedAnalytics.track(event_type, data);
|
||||||
|
|
||||||
@@ -171,11 +173,11 @@ describe('analytics', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('if itemName property is provided, use as label (overrides gem/goldCost)', function() {
|
it('if itemKey property is provided, use as label (overrides gem/goldCost)', function() {
|
||||||
var data = _.cloneDeep(analyticsData);
|
var data = _.cloneDeep(analyticsData);
|
||||||
data.goldCost = 5;
|
data.goldCost = 5;
|
||||||
data.gemCost = 50;
|
data.gemCost = 50;
|
||||||
data.itemName = 'some item';
|
data.itemKey = 'some item';
|
||||||
|
|
||||||
initializedAnalytics.track(event_type, data);
|
initializedAnalytics.track(event_type, data);
|
||||||
|
|
||||||
@@ -187,10 +189,10 @@ describe('analytics', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('if gaLabel property is provided, use as label (overrides itemName)', function() {
|
it('if gaLabel property is provided, use as label (overrides itemKey)', function() {
|
||||||
var data = _.cloneDeep(analyticsData);
|
var data = _.cloneDeep(analyticsData);
|
||||||
data.value = 'some value';
|
data.value = 'some value';
|
||||||
data.itemName = 'some item';
|
data.itemKey = 'some item';
|
||||||
data.gaLabel = 'some label';
|
data.gaLabel = 'some label';
|
||||||
|
|
||||||
initializedAnalytics.track(event_type, data);
|
initializedAnalytics.track(event_type, data);
|
||||||
@@ -239,6 +241,7 @@ describe('analytics', function() {
|
|||||||
expect(amplitudeTrack).to.be.calledWith({
|
expect(amplitudeTrack).to.be.calledWith({
|
||||||
event_type: 'purchase',
|
event_type: 'purchase',
|
||||||
user_id: 'user-id',
|
user_id: 'user-id',
|
||||||
|
platform: 'server',
|
||||||
event_properties: {
|
event_properties: {
|
||||||
paymentMethod: 'PayPal',
|
paymentMethod: 'PayPal',
|
||||||
sku: 'paypal-checkout',
|
sku: 'paypal-checkout',
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function _sendDataToGoogle(eventType, data) {
|
|||||||
|
|
||||||
function _generateLabelForGoogleAnalytics(data) {
|
function _generateLabelForGoogleAnalytics(data) {
|
||||||
var label = 'Label Not Specified';
|
var label = 'Label Not Specified';
|
||||||
var POSSIBLE_LABELS = ['gaLabel', 'itemName', 'gemCost', 'goldCost'];
|
var POSSIBLE_LABELS = ['gaLabel', 'itemKey', 'gemCost', 'goldCost'];
|
||||||
|
|
||||||
_(POSSIBLE_LABELS).each(function(key) {
|
_(POSSIBLE_LABELS).each(function(key) {
|
||||||
if(data[key]) {
|
if(data[key]) {
|
||||||
@@ -70,6 +70,7 @@ function _formatDataForAmplitude(data) {
|
|||||||
|
|
||||||
var ampData = {
|
var ampData = {
|
||||||
user_id: data.uuid,
|
user_id: data.uuid,
|
||||||
|
platform: 'server',
|
||||||
event_properties: event_properties
|
event_properties: event_properties
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +110,7 @@ function _sendPurchaseDataToGoogle(data) {
|
|||||||
var price = data.purchaseValue;
|
var price = data.purchaseValue;
|
||||||
var qty = data.quantity;
|
var qty = data.quantity;
|
||||||
var sku = data.sku;
|
var sku = data.sku;
|
||||||
var itemName = data.itemPurchased;
|
var itemKey = data.itemPurchased;
|
||||||
var variation = type;
|
var variation = type;
|
||||||
if(data.gift) variation += ' - Gift';
|
if(data.gift) variation += ' - Gift';
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ function _sendPurchaseDataToGoogle(data) {
|
|||||||
.send();
|
.send();
|
||||||
|
|
||||||
ga.transaction(data.uuid, price)
|
ga.transaction(data.uuid, price)
|
||||||
.item(price, qty, sku, itemName, variation)
|
.item(price, qty, sku, itemKey, variation)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user