Skip to content

Commit

Permalink
feat: add and use ENABLE_MIXPANEL and USE_MIXPANEL_PROXY env variable (
Browse files Browse the repository at this point in the history
  • Loading branch information
Chethan-Fyle committed Sep 3, 2024
1 parent d4924a9 commit 4fca4d0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion hooks/utils/prod-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const environment = {
LIVE_UPDATE_APP_VERSION: '${process.env.LIVE_UPDATE_APP_VERSION}',
SMARTLOOK_API_KEY: '${process.env.SMARTLOOK_API_KEY}',
MIXPANEL_PROJECT_TOKEN: '${process.env.MIXPANEL_PROJECT_TOKEN}',
MIXPANEL_PROXY_URL: '${process.env.MIXPANEL_PROXY_URL}',
USE_MIXPANEL_PROXY: '${process.env.USE_MIXPANEL_PROXY}',
ENABLE_MIXPANEL: '${process.env.ENABLE_MIXPANEL}'
};
`
9 changes: 9 additions & 0 deletions src/app/core/services/router-auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { apiAuthRes, authResData1 } from '../mock-data/auth-reponse.data';
import { ExpenseAggregationService } from './expense-aggregation.service';
import { SpenderService } from './platform/v1/spender/spender.service';
import { ApproverService } from './platform/v1/approver/approver.service';
import { TrackingService } from './tracking.service';

describe('RouterAuthService', () => {
let routerAuthService: RouterAuthService;
Expand All @@ -31,6 +32,7 @@ describe('RouterAuthService', () => {
let expenseAggregationService: jasmine.SpyObj<ExpenseAggregationService>;
let spenderService: jasmine.SpyObj<SpenderService>;
let approverService: jasmine.SpyObj<ApproverService>;
let trackingService: jasmine.SpyObj<TrackingService>;

const access_token =
'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzk5MDQ0NTQsImlzcyI6IkZ5bGVBcHAiLCJ1c2VyX2lkIjoidXN2S0E0WDhVZ2NyIiwib3JnX3VzZXJfaWQiOiJvdVg4ZHdzYkxDTHYiLCJvcmdfaWQiOiJvck5WdGhUbzJaeW8iLCJyb2xlcyI6IltcIkFETUlOXCIsXCJBUFBST1ZFUlwiLFwiRllMRVJcIixcIkhPUFwiLFwiSE9EXCIsXCJPV05FUlwiXSIsInNjb3BlcyI6IltdIiwiYWxsb3dlZF9DSURScyI6IltdIiwidmVyc2lvbiI6IjMiLCJjbHVzdGVyX2RvbWFpbiI6IlwiaHR0cHM6Ly9zdGFnaW5nLmZ5bGUudGVjaFwiIiwiZXhwIjoxNjc5OTA4MDU0fQ.z3i-MqE3NNyxPEvWFCSr3q58rLXn3LZcIBskW9BLN48';
Expand Down Expand Up @@ -59,6 +61,7 @@ describe('RouterAuthService', () => {
const expenseAggregationServiceSpy = jasmine.createSpyObj('ExpenseAggregationService', ['setRoot']);
const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['setRoot']);
const approverServiceSpy = jasmine.createSpyObj('ApproverService', ['setRoot']);
const trackingServiceSpy = jasmine.createSpyObj('TrackingService', ['setRoot']);

TestBed.configureTestingModule({
providers: [
Expand Down Expand Up @@ -115,6 +118,10 @@ describe('RouterAuthService', () => {
provide: ApproverService,
useValue: approverServiceSpy,
},
{
provide: TrackingService,
useValue: trackingServiceSpy,
},
],
});
routerAuthService = TestBed.inject(RouterAuthService);
Expand All @@ -135,6 +142,7 @@ describe('RouterAuthService', () => {
expenseAggregationService = TestBed.inject(ExpenseAggregationService) as jasmine.SpyObj<ExpenseAggregationService>;
spenderService = TestBed.inject(SpenderService) as jasmine.SpyObj<SpenderService>;
approverService = TestBed.inject(ApproverService) as jasmine.SpyObj<ApproverService>;
trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj<TrackingService>;
});

it('should be created', () => {
Expand Down Expand Up @@ -169,6 +177,7 @@ describe('RouterAuthService', () => {
expect(expenseAggregationService.setRoot).toHaveBeenCalledOnceWith(domain);
expect(spenderService.setRoot).toHaveBeenCalledOnceWith(domain);
expect(approverService.setRoot).toHaveBeenCalledOnceWith(domain);
expect(trackingService.setRoot).toHaveBeenCalledOnceWith(domain);
done();
});
});
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/services/router-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SpenderService } from './platform/v1/spender/spender.service';
import { ApproverService } from './platform/v1/approver/approver.service';
import { EmailExistsResponse } from '../models/email-exists-response.model';
import { ResendEmailVerification } from '../models/resend-email-verification.model';
import { TrackingService } from './tracking.service';

@Injectable({
providedIn: 'root',
Expand All @@ -35,7 +36,8 @@ export class RouterAuthService {
private spenderPlatformV1ApiService: SpenderPlatformV1ApiService,
private expenseAggregationService: ExpenseAggregationService,
private spenderService: SpenderService,
private approverService: ApproverService
private approverService: ApproverService,
private trackingService: TrackingService
) {}

checkEmailExists(email: string): Observable<EmailExistsResponse> {
Expand Down Expand Up @@ -66,6 +68,7 @@ export class RouterAuthService {
this.expenseAggregationService.setRoot(domain);
this.spenderService.setRoot(domain);
this.approverService.setRoot(domain);
this.trackingService.setRoot(domain);

await this.tokenService.setClusterDomain(domain);
}
Expand Down
35 changes: 24 additions & 11 deletions src/app/core/services/tracking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,32 @@ import mixpanel, { Config } from 'mixpanel-browser';
export class TrackingService {
identityEmail = null;

constructor(private authService: AuthService, private deviceService: DeviceService) {
try {
const config: Partial<Config> = {
debug: false,
track_pageview: false,
persistence: 'localStorage',
};
ROOT_ENDPOINT: string;

if (environment.MIXPANEL_PROXY_URL) {
config.api_host = environment.MIXPANEL_PROXY_URL;
}
constructor(private authService: AuthService, private deviceService: DeviceService) {}

mixpanel.init(environment.MIXPANEL_PROJECT_TOKEN, config);
setRoot(rootUrl: string): void {
this.ROOT_ENDPOINT = rootUrl;
this.initializeMixpanel();
}

initializeMixpanel(): void {
try {
const enableMixpanel = environment.ENABLE_MIXPANEL;
if (enableMixpanel === 'true') {
const config: Partial<Config> = {
debug: false,
track_pageview: false,
persistence: 'localStorage',
};

const useMixpanelProxy = environment.USE_MIXPANEL_PROXY;
if (useMixpanelProxy === 'true' && this.ROOT_ENDPOINT) {
config.api_host = this.ROOT_ENDPOINT + '/mixpanel';
}

mixpanel.init(environment.MIXPANEL_PROJECT_TOKEN, config);
}
} catch (e) {}
}

Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const environment = {
LIVE_UPDATE_APP_VERSION: '',
SMARTLOOK_API_KEY: '',
MIXPANEL_PROJECT_TOKEN: '',
MIXPANEL_PROXY_URL: '',
USE_MIXPANEL_PROXY: '',
ENABLE_MIXPANEL: '',
};

/*
Expand Down

0 comments on commit 4fca4d0

Please sign in to comment.