mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
fix(analytics): always use mock service in development
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { authWithHeaders } from '../../middlewares/auth';
|
import { authWithHeaders } from '../../middlewares/auth';
|
||||||
import * as analytics from '../../libs/analyticsService';
|
import { getAnalyticsServiceByEnvironment } from '../../libs/analyticsService';
|
||||||
import {
|
import {
|
||||||
model as Group,
|
model as Group,
|
||||||
basicFields as basicGroupFields,
|
basicFields as basicGroupFields,
|
||||||
@@ -20,6 +20,8 @@ import { sendNotification as sendPushNotification } from '../../libs/pushNotific
|
|||||||
import apiError from '../../libs/apiError';
|
import apiError from '../../libs/apiError';
|
||||||
import { questActivityWebhook } from '../../libs/webhook';
|
import { questActivityWebhook } from '../../libs/webhook';
|
||||||
|
|
||||||
|
const analytics = getAnalyticsServiceByEnvironment();
|
||||||
|
|
||||||
const questScrolls = common.content.quests;
|
const questScrolls = common.content.quests;
|
||||||
|
|
||||||
function canStartQuestAutomatically (group) {
|
function canStartQuestAutomatically (group) {
|
||||||
|
|||||||
@@ -338,15 +338,26 @@ 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: () => { },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Return the production or mock service based on the current environment
|
||||||
|
function getServiceByEnvironment () {
|
||||||
|
if (nconf.get('IS_PROD')) {
|
||||||
|
return {
|
||||||
|
track,
|
||||||
|
trackPurchase,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return mockAnalyticsService;
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
track,
|
track,
|
||||||
trackPurchase,
|
trackPurchase,
|
||||||
mockAnalyticsService,
|
mockAnalyticsService,
|
||||||
|
getServiceByEnvironment as getAnalyticsServiceByEnvironment,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as analytics from '../analyticsService';
|
import { getAnalyticsServiceByEnvironment } from '../analyticsService';
|
||||||
import { getCurrentEvent } from '../worldState'; // eslint-disable-line import/no-cycle
|
import { getCurrentEvent } from '../worldState'; // eslint-disable-line import/no-cycle
|
||||||
import { // eslint-disable-line import/no-cycle
|
import { // eslint-disable-line import/no-cycle
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
} from '../errors';
|
} from '../errors';
|
||||||
import apiError from '../apiError';
|
import apiError from '../apiError';
|
||||||
|
|
||||||
|
const analytics = getAnalyticsServiceByEnvironment();
|
||||||
|
|
||||||
function getGiftMessage (data, byUsername, gemAmount, language) {
|
function getGiftMessage (data, byUsername, gemAmount, language) {
|
||||||
const senderMsg = shared.i18n.t('giftedGemsFull', {
|
const senderMsg = shared.i18n.t('giftedGemsFull', {
|
||||||
username: data.gift.member.profile.name,
|
username: data.gift.member.profile.name,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import * as analytics from '../analyticsService';
|
import { getAnalyticsServiceByEnvironment } from '../analyticsService';
|
||||||
import * as slack from '../slack'; // eslint-disable-line import/no-cycle
|
import * as slack from '../slack'; // eslint-disable-line import/no-cycle
|
||||||
import { // eslint-disable-line import/no-cycle
|
import { // eslint-disable-line import/no-cycle
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
@@ -21,6 +21,7 @@ import calculateSubscriptionTerminationDate from './calculateSubscriptionTermina
|
|||||||
|
|
||||||
// @TODO: Abstract to shared/constant
|
// @TODO: Abstract to shared/constant
|
||||||
const JOINED_GROUP_PLAN = 'joined group plan';
|
const JOINED_GROUP_PLAN = 'joined group plan';
|
||||||
|
const analytics = getAnalyticsServiceByEnvironment();
|
||||||
|
|
||||||
function _findMysteryItems (user, dateMoment) {
|
function _findMysteryItems (user, dateMoment) {
|
||||||
const pushedItems = [];
|
const pushedItems = [];
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
import nconf from 'nconf';
|
|
||||||
import {
|
import {
|
||||||
track,
|
getAnalyticsServiceByEnvironment,
|
||||||
trackPurchase,
|
|
||||||
mockAnalyticsService,
|
|
||||||
} from '../libs/analyticsService';
|
} from '../libs/analyticsService';
|
||||||
|
|
||||||
let service;
|
const service = getAnalyticsServiceByEnvironment();
|
||||||
|
|
||||||
if (nconf.get('IS_PROD')) {
|
|
||||||
service = {
|
|
||||||
track,
|
|
||||||
trackPurchase,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
service = mockAnalyticsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function attachAnalytics (req, res, next) {
|
export default function attachAnalytics (req, res, next) {
|
||||||
res.analytics = service;
|
res.analytics = service;
|
||||||
|
|||||||
Reference in New Issue
Block a user