Skip to content

Commit

Permalink
fix: mixpanel initialize configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodouradol committed Feb 15, 2024
1 parent 52c6733 commit 03c11d6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/dispatchers/dispatchers.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export type EventType = 'customEvent' | 'screenEvent' | 'userIdentification';
export type PropertiesType = { [key: string]: string };
export type PropertiesType = { [key: string]: string | boolean | number | string[] | undefined; };
export type UserPropertiesType = {
email?: string;
name?: string;
[key: string]: string | undefined;
[key: string]: string | boolean | number | any[] | undefined;
};
export type EventData = {
screen?: string;
Expand Down
4 changes: 1 addition & 3 deletions src/initializers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ const mixPanelInitializer = (
): void => {
if (isProduction(environment)) {
localStorage.setItem('_bl_mp', apiKey);
mixpanel.init(apiKey, {
track_pageview: true,
});
mixpanel.init(apiKey);
localStorage.removeItem('_bl_init');
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/providers/setups/mixpanel/mixpanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ describe('MixPanelProvider', () => {

test('dispatchCustomEvent should call mixpanel.track with event and properties', () => {
const event = 'testEvent';
const properties = { key1: 'value1', key2: 'value2' };
const properties = {
key1: 'value1', key2: true, key3: 9.9, key4: ['value1', 'value2'],
};

MixPanelProvider.customEvent(event, properties);

expect(mixpanel.track).toHaveBeenCalledWith(event, { properties });
const { ...rest } = properties;
expect(mixpanel.track).toHaveBeenCalledWith(event, rest);
});

test('dispatchScreenEvent should call mixpanel.track with screen', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/providers/setups/mixpanel/mixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const dispatchCustomEvent = (
event: string,
properties: PropertiesType,
): void => {
mixpanel.track(event, { properties });
const { ...rest } = properties;
mixpanel.track(event, rest);
};

const dispatchScreenEvent = (screen: string): void => {
Expand Down
4 changes: 1 addition & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export const checkIfMixPanelIsInitialized = (provider: string): void => {
const wasInitialized = localStorage.getItem('_bl_init');

if (!wasInitialized) {
mixpanel.init(apiKey, {
track_pageview: true,
});
mixpanel.init(apiKey);
localStorage.removeItem('_bl_mp');
localStorage.setItem('_bl_init', 'init');
}
Expand Down

0 comments on commit 03c11d6

Please sign in to comment.