mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 18:22:21 +00:00
Merge pull request #10988 from HabitRPG/sabrecat/platform-analytics-tweak
Set registered platform on analytics only once
This commit is contained in:
commit
6cc925b535
1 changed files with 18 additions and 9 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue