fix(analytics): set reg platform only once

This commit is contained in:
Sabe Jones
2019-02-12 16:04:14 -06:00
parent b711c1672b
commit ee5c761680

View File

@@ -10,7 +10,7 @@ import {
} from 'lodash'; } from 'lodash';
import { content as Content } from '../../common'; import { content as Content } from '../../common';
const AMPLIUDE_TOKEN = nconf.get('AMPLITUDE_KEY'); const AMPLITUDE_TOKEN = nconf.get('AMPLITUDE_KEY');
const GA_TOKEN = nconf.get('GA_ID'); const GA_TOKEN = nconf.get('GA_ID');
const GA_POSSIBLE_LABELS = ['gaLabel', 'itemKey']; const GA_POSSIBLE_LABELS = ['gaLabel', 'itemKey'];
const GA_POSSIBLE_VALUES = ['gaValue', 'gemCost', 'goldCost']; const GA_POSSIBLE_VALUES = ['gaValue', 'gemCost', 'goldCost'];
@@ -23,7 +23,7 @@ const PLATFORM_MAP = Object.freeze({
}); });
let amplitude; let amplitude;
if (AMPLIUDE_TOKEN) amplitude = new Amplitude(AMPLIUDE_TOKEN); if (AMPLITUDE_TOKEN) amplitude = new Amplitude(AMPLITUDE_TOKEN);
let ga = googleAnalytics(GA_TOKEN); let ga = googleAnalytics(GA_TOKEN);
@@ -271,11 +271,28 @@ let _sendPurchaseDataToGoogle = (data) => {
}); });
}; };
let _setOnce = (data) => {
return new Promise((resolve, reject) => {
amplitude.identify({
user_properties: {
$setOnce: data,
},
})
.then(resolve)
.catch(reject);
});
};
function track (eventType, data) { function track (eventType, data) {
return Promise.all([ let promises = [
_sendDataToAmplitude(eventType, data), _sendDataToAmplitude(eventType, data),
_sendDataToGoogle(eventType, data), _sendDataToGoogle(eventType, data),
]); ];
if (data.user && data.user.registeredThrough) {
promises.push(_setOnce({registeredPlatform: data.user.registeredThrough}));
}
return Promise.all(promises);
} }
function trackPurchase (data) { function trackPurchase (data) {