fix(analytics): always use mock service in development

This commit is contained in:
Matteo Pagliazzi
2020-11-29 23:15:26 +01:00
parent 6b3a6eb59f
commit 7745a0e65a
5 changed files with 23 additions and 19 deletions

View File

@@ -338,15 +338,26 @@ async function trackPurchase (data) {
}
// 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 = {
track: () => { },
trackPurchase: () => { },
};
// Return the production or mock service based on the current environment
function getServiceByEnvironment () {
if (nconf.get('IS_PROD')) {
return {
track,
trackPurchase,
};
}
return mockAnalyticsService;
}
export {
track,
trackPurchase,
mockAnalyticsService,
getServiceByEnvironment as getAnalyticsServiceByEnvironment,
};