Skip to content

Commit 4991047

Browse files
Fix trackInApp* functions returning 400 by preserving email/userId in payloads
Stop stripping email and userId from trackInAppOpen, trackInAppClick, trackInAppClose, trackInAppDelivery, and trackInAppConsume request payloads. The authorization interceptor re-adds these fields, but removing them from the payload caused issues when the interceptor exclusion logic prevented re-addition, resulting in 400 errors. Fixes #552 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 190a168 commit 4991047

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

src/events/events.test.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ describe('Events Requests', () => {
392392
}
393393
});
394394

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

474-
expect(JSON.parse(trackClickResponse.config.data).email).toBeUndefined();
475-
expect(JSON.parse(trackClickResponse.config.data).userId).toBeUndefined();
474+
expect(JSON.parse(trackClickResponse.config.data).email).toBe(
475+
'hello@gmail.com'
476+
);
477+
expect(JSON.parse(trackClickResponse.config.data).userId).toBe('1234');
476478
expect(
477479
JSON.parse(trackClickResponse.config.data).deviceInfo.appPackageName
478480
).toBe('my-lil-site');
479481
expect(JSON.parse(trackClickResponse.config.data).deviceInfo.platform).toBe(
480482
WEB_PLATFORM
481483
);
482484

483-
expect(JSON.parse(trackCloseResponse.config.data).email).toBeUndefined();
484-
expect(JSON.parse(trackCloseResponse.config.data).userId).toBeUndefined();
485+
expect(JSON.parse(trackCloseResponse.config.data).email).toBe(
486+
'hello@gmail.com'
487+
);
488+
expect(JSON.parse(trackCloseResponse.config.data).userId).toBe('1234');
485489
expect(
486490
JSON.parse(trackCloseResponse.config.data).deviceInfo.appPackageName
487491
).toBe('my-lil-site');
488492
expect(JSON.parse(trackCloseResponse.config.data).deviceInfo.platform).toBe(
489493
WEB_PLATFORM
490494
);
491495

492-
expect(JSON.parse(trackConsumeResponse.config.data).email).toBeUndefined();
493-
expect(JSON.parse(trackConsumeResponse.config.data).userId).toBeUndefined();
496+
expect(JSON.parse(trackConsumeResponse.config.data).email).toBe(
497+
'hello@gmail.com'
498+
);
499+
expect(JSON.parse(trackConsumeResponse.config.data).userId).toBe('1234');
494500
expect(
495501
JSON.parse(trackConsumeResponse.config.data).deviceInfo.appPackageName
496502
).toBe('my-lil-site');
497503
expect(
498504
JSON.parse(trackConsumeResponse.config.data).deviceInfo.platform
499505
).toBe(WEB_PLATFORM);
500506

501-
expect(JSON.parse(trackDeliveryResponse.config.data).email).toBeUndefined();
502-
expect(
503-
JSON.parse(trackDeliveryResponse.config.data).userId
504-
).toBeUndefined();
507+
expect(JSON.parse(trackDeliveryResponse.config.data).email).toBe(
508+
'hello@gmail.com'
509+
);
510+
expect(JSON.parse(trackDeliveryResponse.config.data).userId).toBe('1234');
505511
expect(
506512
JSON.parse(trackDeliveryResponse.config.data).deviceInfo.appPackageName
507513
).toBe('my-lil-site');
508514
expect(
509515
JSON.parse(trackDeliveryResponse.config.data).deviceInfo.platform
510516
).toBe(WEB_PLATFORM);
511517

512-
expect(JSON.parse(trackOpenResponse.config.data).email).toBeUndefined();
513-
expect(JSON.parse(trackOpenResponse.config.data).userId).toBeUndefined();
518+
expect(JSON.parse(trackOpenResponse.config.data).email).toBe(
519+
'hello@gmail.com'
520+
);
521+
expect(JSON.parse(trackOpenResponse.config.data).userId).toBe('1234');
514522
expect(
515523
JSON.parse(trackOpenResponse.config.data).deviceInfo.appPackageName
516524
).toBe('my-lil-site');

src/events/inapp/events.ts

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
/* eslint-disable no-param-reassign */
21
import { baseIterableRequest } from '../../request';
32
import { InAppEventRequestParams } from './types';
43
import { IterableResponse } from '../../types';
54
import { ENDPOINTS, WEB_PLATFORM } from '../../constants';
65
import { eventRequestSchema } from './events.schema';
76

8-
export const trackInAppClose = (payload: InAppEventRequestParams) => {
9-
/* a customer could potentially send these up if they're not using TypeScript */
10-
delete (payload as any).userId;
11-
delete (payload as any).email;
12-
13-
return baseIterableRequest<IterableResponse>({
7+
export const trackInAppClose = (payload: InAppEventRequestParams) =>
8+
baseIterableRequest<IterableResponse>({
149
method: 'POST',
1510
url: ENDPOINTS.track_app_close.route,
1611
data: {
@@ -25,19 +20,14 @@ export const trackInAppClose = (payload: InAppEventRequestParams) => {
2520
data: eventRequestSchema
2621
}
2722
});
28-
};
2923

3024
export const trackInAppOpen = (
3125
payload: Omit<
3226
InAppEventRequestParams,
3327
'clickedUrl' | 'inboxSessionId' | 'closeAction'
3428
>
35-
) => {
36-
/* a customer could potentially send these up if they're not using TypeScript */
37-
delete (payload as any).userId;
38-
delete (payload as any).email;
39-
40-
return baseIterableRequest<IterableResponse>({
29+
) =>
30+
baseIterableRequest<IterableResponse>({
4131
method: 'POST',
4232
url: ENDPOINTS.track_app_open.route,
4333
data: {
@@ -56,17 +46,12 @@ export const trackInAppOpen = (
5646
])
5747
}
5848
});
59-
};
6049

6150
export const trackInAppClick = (
6251
payload: Omit<InAppEventRequestParams, 'inboxSessionId' | 'closeAction'>,
6352
sendBeacon = false
64-
) => {
65-
/* a customer could potentially send these up if they're not using TypeScript */
66-
delete (payload as any).userId;
67-
delete (payload as any).email;
68-
69-
return baseIterableRequest<IterableResponse>({
53+
) =>
54+
baseIterableRequest<IterableResponse>({
7055
method: 'POST',
7156
url: ENDPOINTS.track_app_click.route,
7257
sendBeacon,
@@ -82,19 +67,14 @@ export const trackInAppClick = (
8267
data: eventRequestSchema.omit(['inboxSessionId', 'closeAction'])
8368
}
8469
});
85-
};
8670

8771
export const trackInAppDelivery = (
8872
payload: Omit<
8973
InAppEventRequestParams,
9074
'clickedUrl' | 'closeAction' | 'inboxSessionId'
9175
>
92-
) => {
93-
/* a customer could potentially send these up if they're not using TypeScript */
94-
delete (payload as any).userId;
95-
delete (payload as any).email;
96-
97-
return baseIterableRequest<IterableResponse>({
76+
) =>
77+
baseIterableRequest<IterableResponse>({
9878
method: 'POST',
9979
url: ENDPOINTS.track_app_delivery.route,
10080
data: {
@@ -113,19 +93,14 @@ export const trackInAppDelivery = (
11393
])
11494
}
11595
});
116-
};
11796

11897
export const trackInAppConsume = (
11998
payload: Omit<
12099
InAppEventRequestParams,
121100
'clickedUrl' | 'closeAction' | 'inboxSessionId'
122101
>
123-
) => {
124-
/* a customer could potentially send these up if they're not using TypeScript */
125-
delete (payload as any).userId;
126-
delete (payload as any).email;
127-
128-
return baseIterableRequest<IterableResponse>({
102+
) =>
103+
baseIterableRequest<IterableResponse>({
129104
method: 'POST',
130105
url: ENDPOINTS.track_app_consume.route,
131106
data: {
@@ -144,4 +119,3 @@ export const trackInAppConsume = (
144119
])
145120
}
146121
});
147-
};

0 commit comments

Comments
 (0)