mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
add ability to log amplitude events (#12120)
This commit is contained in:
@@ -79,5 +79,6 @@
|
|||||||
"APPLE_TEAM_ID": "",
|
"APPLE_TEAM_ID": "",
|
||||||
"APPLE_AUTH_CLIENT_ID": "",
|
"APPLE_AUTH_CLIENT_ID": "",
|
||||||
"APPLE_AUTH_KEY_ID": "",
|
"APPLE_AUTH_KEY_ID": "",
|
||||||
"BLOCKED_IPS": ""
|
"BLOCKED_IPS": "",
|
||||||
|
"LOG_AMPLITUDE_EVENTS": "false"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import logger from './logger';
|
|||||||
|
|
||||||
const AMPLITUDE_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 LOG_AMPLITUDE_EVENTS = nconf.get('LOG_AMPLITUDE_EVENTS') === 'true';
|
||||||
|
|
||||||
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'];
|
||||||
const AMPLITUDE_PROPERTIES_TO_SCRUB = [
|
const AMPLITUDE_PROPERTIES_TO_SCRUB = [
|
||||||
@@ -176,6 +179,10 @@ function _sendDataToAmplitude (eventType, data) {
|
|||||||
|
|
||||||
amplitudeData.event_type = eventType;
|
amplitudeData.event_type = eventType;
|
||||||
|
|
||||||
|
if (LOG_AMPLITUDE_EVENTS) {
|
||||||
|
logger.info('Amplitude Event', amplitudeData);
|
||||||
|
}
|
||||||
|
|
||||||
return amplitude
|
return amplitude
|
||||||
.track(amplitudeData)
|
.track(amplitudeData)
|
||||||
.catch(err => logger.error(err, 'Error while sending data to Amplitude.'));
|
.catch(err => logger.error(err, 'Error while sending data to Amplitude.'));
|
||||||
@@ -245,6 +252,10 @@ function _sendPurchaseDataToAmplitude (data) {
|
|||||||
amplitudeData.event_type = 'purchase';
|
amplitudeData.event_type = 'purchase';
|
||||||
amplitudeData.revenue = data.purchaseValue;
|
amplitudeData.revenue = data.purchaseValue;
|
||||||
|
|
||||||
|
if (LOG_AMPLITUDE_EVENTS) {
|
||||||
|
logger.info('Amplitude Purchase Event', amplitudeData);
|
||||||
|
}
|
||||||
|
|
||||||
return amplitude
|
return amplitude
|
||||||
.track(amplitudeData)
|
.track(amplitudeData)
|
||||||
.catch(err => logger.error(err, 'Error while sending data to Amplitude.'));
|
.catch(err => logger.error(err, 'Error while sending data to Amplitude.'));
|
||||||
@@ -325,6 +336,8 @@ async function trackPurchase (data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stub for non-prod environments
|
// Stub for non-prod environments
|
||||||
|
// @TODO instead of exporting a different interface why not have track
|
||||||
|
// and trackPurchase be no ops when not in production?
|
||||||
const mockAnalyticsService = {
|
const mockAnalyticsService = {
|
||||||
track: () => { },
|
track: () => { },
|
||||||
trackPurchase: () => { },
|
trackPurchase: () => { },
|
||||||
|
|||||||
Reference in New Issue
Block a user