diff --git a/website/server/libs/analyticsService.js b/website/server/libs/analyticsService.js index f96e7ca228..38da9c6a9c 100644 --- a/website/server/libs/analyticsService.js +++ b/website/server/libs/analyticsService.js @@ -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) {