Merge pull request #10988 from HabitRPG/sabrecat/platform-analytics-tweak

Set registered platform on analytics only once
This commit is contained in:
Matteo Pagliazzi 2019-03-23 18:19:15 +01:00 committed by GitHub
commit 6cc925b535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,11 +10,11 @@ import {
} from 'lodash';
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_POSSIBLE_LABELS = ['gaLabel', 'itemKey'];
const GA_POSSIBLE_VALUES = ['gaValue', 'gemCost', 'goldCost'];
const AMPLITUDE_PROPERTIES_TO_SCRUB = ['uuid', 'user', 'purchaseValue', 'gaLabel', 'gaValue', 'headers'];
const AMPLITUDE_PROPERTIES_TO_SCRUB = ['uuid', 'user', 'purchaseValue', 'gaLabel', 'gaValue', 'headers', 'registeredThrough'];
const PLATFORM_MAP = Object.freeze({
'habitica-web': 'Web',
@ -23,7 +23,7 @@ const PLATFORM_MAP = Object.freeze({
});
let amplitude;
if (AMPLIUDE_TOKEN) amplitude = new Amplitude(AMPLIUDE_TOKEN);
if (AMPLITUDE_TOKEN) amplitude = new Amplitude(AMPLITUDE_TOKEN);
let ga = googleAnalytics(GA_TOKEN);
@ -97,10 +97,6 @@ let _formatUserData = (user) => {
properties.ABtests = toArray(user._ABtests);
}
if (user.registeredThrough) {
properties.registeredPlatform = user.registeredThrough;
}
if (user.loginIncentives) {
properties.loginIncentives = user.loginIncentives;
}
@ -271,11 +267,24 @@ let _sendPurchaseDataToGoogle = (data) => {
});
};
let _setOnce = (data) => {
return amplitude.identify({
user_properties: {
$setOnce: data,
},
});
};
function track (eventType, data) {
return Promise.all([
let promises = [
_sendDataToAmplitude(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) {