Skip to content

Commit e020e20

Browse files
committed
Truncate language in platform context entity to max 8 characters
1 parent d234d1c commit e020e20

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

trackers/react-native-tracker/src/plugins/platform_context/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ export async function newPlatformContextPlugin({
239239
: PixelRatio.get()
240240
: undefined;
241241
language =
242-
platformContextProperties?.includes(PlatformContextProperty.Language) ?? true
242+
(platformContextProperties?.includes(PlatformContextProperty.Language) ?? true
243243
? platformContextRetriever?.getLanguage
244244
? await platformContextRetriever?.getLanguage()
245245
: constants?.language
246-
: undefined;
246+
: undefined)?.substring(0, 8);
247247
appSetId =
248248
platformContextProperties?.includes(PlatformContextProperty.AppSetId) ?? true
249249
? platformContextRetriever?.getAppSetId

trackers/react-native-tracker/test/plugins/platform_context_android.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,27 @@ describe('PlatformContextPlugin on Android', () => {
5555
expect(payload?.co).toContain('"en-GB"');
5656
expect(payload?.co).toContain('"123x89"');
5757
});
58+
59+
it('truncates language to 8 characters', async () => {
60+
const sessionPlugin = await newPlatformContextPlugin({
61+
platformContextRetriever: {
62+
getLanguage: () => Promise.resolve('1234567890'),
63+
},
64+
});
65+
66+
const payloads: Payload[] = [];
67+
const tracker = trackerCore({
68+
corePlugins: [sessionPlugin.plugin],
69+
callback: (pb) => payloads.push(pb.build()),
70+
base64: false,
71+
});
72+
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
73+
74+
expect(payloads.length).toBe(1);
75+
const [payload] = payloads;
76+
expect(payload?.co).toBeDefined();
77+
const entities = JSON.parse(payload?.co as string).data;
78+
const mobileContext = entities.find((entity: any) => entity.schema === MOBILE_CONTEXT_SCHEMA);
79+
expect(mobileContext?.data.language).toBe('12345678');
80+
});
5881
});

trackers/react-native-tracker/test/plugins/platform_context_ios.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,27 @@ describe('PlatformContextPlugin on iOS', () => {
167167
appSetIdScope: 'my-app-set-scope',
168168
});
169169
});
170+
171+
it('truncates language to 8 characters', async () => {
172+
const sessionPlugin = await newPlatformContextPlugin({
173+
platformContextRetriever: {
174+
getLanguage: () => Promise.resolve('1234567890'),
175+
},
176+
});
177+
178+
const payloads: Payload[] = [];
179+
const tracker = trackerCore({
180+
corePlugins: [sessionPlugin.plugin],
181+
callback: (pb) => payloads.push(pb.build()),
182+
base64: false,
183+
});
184+
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
185+
186+
expect(payloads.length).toBe(1);
187+
const [payload] = payloads;
188+
expect(payload?.co).toBeDefined();
189+
const entities = JSON.parse(payload?.co as string).data;
190+
const mobileContext = entities.find((entity: any) => entity.schema === MOBILE_CONTEXT_SCHEMA);
191+
expect(mobileContext?.data.language).toBe('12345678');
192+
});
170193
});

0 commit comments

Comments
 (0)