Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/events/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ describe('Events Requests', () => {
}
});

it('should not send up passed email or userId params', async () => {
it('should preserve email and userId in inApp payloads and strip them from non-inApp events', async () => {
(global as any).localStorage = localStorageMock;
const trackResponse = await track({
email: 'hello@gmail.com',
Expand Down Expand Up @@ -471,46 +471,54 @@ describe('Events Requests', () => {
JSON.parse(trackResponse.config.data).deviceInfo.appPackageName
).toBe('my-lil-site');

expect(JSON.parse(trackClickResponse.config.data).email).toBeUndefined();
expect(JSON.parse(trackClickResponse.config.data).userId).toBeUndefined();
expect(JSON.parse(trackClickResponse.config.data).email).toBe(
'hello@gmail.com'
);
expect(JSON.parse(trackClickResponse.config.data).userId).toBe('1234');
expect(
JSON.parse(trackClickResponse.config.data).deviceInfo.appPackageName
).toBe('my-lil-site');
expect(JSON.parse(trackClickResponse.config.data).deviceInfo.platform).toBe(
WEB_PLATFORM
);

expect(JSON.parse(trackCloseResponse.config.data).email).toBeUndefined();
expect(JSON.parse(trackCloseResponse.config.data).userId).toBeUndefined();
expect(JSON.parse(trackCloseResponse.config.data).email).toBe(
'hello@gmail.com'
);
expect(JSON.parse(trackCloseResponse.config.data).userId).toBe('1234');
expect(
JSON.parse(trackCloseResponse.config.data).deviceInfo.appPackageName
).toBe('my-lil-site');
expect(JSON.parse(trackCloseResponse.config.data).deviceInfo.platform).toBe(
WEB_PLATFORM
);

expect(JSON.parse(trackConsumeResponse.config.data).email).toBeUndefined();
expect(JSON.parse(trackConsumeResponse.config.data).userId).toBeUndefined();
expect(JSON.parse(trackConsumeResponse.config.data).email).toBe(
'hello@gmail.com'
);
expect(JSON.parse(trackConsumeResponse.config.data).userId).toBe('1234');
expect(
JSON.parse(trackConsumeResponse.config.data).deviceInfo.appPackageName
).toBe('my-lil-site');
expect(
JSON.parse(trackConsumeResponse.config.data).deviceInfo.platform
).toBe(WEB_PLATFORM);

expect(JSON.parse(trackDeliveryResponse.config.data).email).toBeUndefined();
expect(
JSON.parse(trackDeliveryResponse.config.data).userId
).toBeUndefined();
expect(JSON.parse(trackDeliveryResponse.config.data).email).toBe(
'hello@gmail.com'
);
expect(JSON.parse(trackDeliveryResponse.config.data).userId).toBe('1234');
expect(
JSON.parse(trackDeliveryResponse.config.data).deviceInfo.appPackageName
).toBe('my-lil-site');
expect(
JSON.parse(trackDeliveryResponse.config.data).deviceInfo.platform
).toBe(WEB_PLATFORM);

expect(JSON.parse(trackOpenResponse.config.data).email).toBeUndefined();
expect(JSON.parse(trackOpenResponse.config.data).userId).toBeUndefined();
expect(JSON.parse(trackOpenResponse.config.data).email).toBe(
'hello@gmail.com'
);
expect(JSON.parse(trackOpenResponse.config.data).userId).toBe('1234');
expect(
JSON.parse(trackOpenResponse.config.data).deviceInfo.appPackageName
).toBe('my-lil-site');
Expand Down
46 changes: 10 additions & 36 deletions src/events/inapp/events.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/* eslint-disable no-param-reassign */
import { baseIterableRequest } from '../../request';
import { InAppEventRequestParams } from './types';
import { IterableResponse } from '../../types';
import { ENDPOINTS, WEB_PLATFORM } from '../../constants';
import { eventRequestSchema } from './events.schema';

export const trackInAppClose = (payload: InAppEventRequestParams) => {
/* a customer could potentially send these up if they're not using TypeScript */
delete (payload as any).userId;
delete (payload as any).email;

return baseIterableRequest<IterableResponse>({
export const trackInAppClose = (payload: InAppEventRequestParams) =>
baseIterableRequest<IterableResponse>({
method: 'POST',
url: ENDPOINTS.track_app_close.route,
data: {
Expand All @@ -25,19 +20,14 @@ export const trackInAppClose = (payload: InAppEventRequestParams) => {
data: eventRequestSchema
}
});
};

export const trackInAppOpen = (
payload: Omit<
InAppEventRequestParams,
'clickedUrl' | 'inboxSessionId' | 'closeAction'
>
) => {
/* a customer could potentially send these up if they're not using TypeScript */
delete (payload as any).userId;
delete (payload as any).email;

return baseIterableRequest<IterableResponse>({
) =>
baseIterableRequest<IterableResponse>({
method: 'POST',
url: ENDPOINTS.track_app_open.route,
data: {
Expand All @@ -56,17 +46,12 @@ export const trackInAppOpen = (
])
}
});
};

export const trackInAppClick = (
payload: Omit<InAppEventRequestParams, 'inboxSessionId' | 'closeAction'>,
sendBeacon = false
) => {
/* a customer could potentially send these up if they're not using TypeScript */
delete (payload as any).userId;
delete (payload as any).email;

return baseIterableRequest<IterableResponse>({
) =>
baseIterableRequest<IterableResponse>({
method: 'POST',
url: ENDPOINTS.track_app_click.route,
sendBeacon,
Expand All @@ -82,19 +67,14 @@ export const trackInAppClick = (
data: eventRequestSchema.omit(['inboxSessionId', 'closeAction'])
}
});
};

export const trackInAppDelivery = (
payload: Omit<
InAppEventRequestParams,
'clickedUrl' | 'closeAction' | 'inboxSessionId'
>
) => {
/* a customer could potentially send these up if they're not using TypeScript */
delete (payload as any).userId;
delete (payload as any).email;

return baseIterableRequest<IterableResponse>({
) =>
baseIterableRequest<IterableResponse>({
method: 'POST',
url: ENDPOINTS.track_app_delivery.route,
data: {
Expand All @@ -113,19 +93,14 @@ export const trackInAppDelivery = (
])
}
});
};

export const trackInAppConsume = (
payload: Omit<
InAppEventRequestParams,
'clickedUrl' | 'closeAction' | 'inboxSessionId'
>
) => {
/* a customer could potentially send these up if they're not using TypeScript */
delete (payload as any).userId;
delete (payload as any).email;

return baseIterableRequest<IterableResponse>({
) =>
baseIterableRequest<IterableResponse>({
method: 'POST',
url: ENDPOINTS.track_app_consume.route,
data: {
Expand All @@ -144,4 +119,3 @@ export const trackInAppConsume = (
])
}
});
};
Loading