Skip to content

Commit ff961f1

Browse files
committed
Round resolution in mobile context to avoid validation failures on Android (#1404)
1 parent 785c929 commit ff961f1

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/react-native-tracker",
5+
"comment": "Round resolution in mobile context to avoid validation failures on Android",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/react-native-tracker"
10+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export async function newPlatformContextPlugin({
230230
platformContextProperties?.includes(PlatformContextProperty.Resolution) ?? true
231231
? platformContextRetriever?.getResolution
232232
? await platformContextRetriever?.getResolution()
233-
: Dimensions.get('window').width + 'x' + Dimensions.get('window').height
233+
: Math.floor(Dimensions.get('window').width) + 'x' + Math.floor(Dimensions.get('window').height)
234234
: undefined;
235235
scale =
236236
platformContextProperties?.includes(PlatformContextProperty.Scale) ?? true

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { buildPageView, Payload, trackerCore } from '@snowplow/tracker-core';
22
import { newPlatformContextPlugin } from '../../src/plugins/platform_context';
33
import { MOBILE_CONTEXT_SCHEMA } from '../../src/constants';
44
import { NativeModules } from 'react-native';
5+
import { Dimensions } from 'react-native';
56

67
describe('PlatformContextPlugin on Android', () => {
78
beforeAll(() => {
@@ -17,6 +18,12 @@ describe('PlatformContextPlugin on Android', () => {
1718
},
1819
select: () => null,
1920
}));
21+
jest.spyOn(Dimensions, 'get').mockReturnValue({
22+
width: 123.4567,
23+
height: 89.1234,
24+
scale: 0,
25+
fontScale: 0,
26+
});
2027
NativeModules.I18nManager = {
2128
localeIdentifier: 'en-GB',
2229
};
@@ -46,5 +53,6 @@ describe('PlatformContextPlugin on Android', () => {
4653
expect(payload?.co).toContain('"Google"');
4754
expect(payload?.co).toContain('"Google"');
4855
expect(payload?.co).toContain('"en-GB"');
56+
expect(payload?.co).toContain('"123x89"');
4957
});
5058
});

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { buildPageView, Payload, trackerCore } from '@snowplow/tracker-core';
22
import { newPlatformContextPlugin } from '../../src/plugins/platform_context';
33
import { NativeModules } from 'react-native';
44
import { MOBILE_CONTEXT_SCHEMA } from '../../src/constants';
5+
import { Dimensions } from 'react-native';
56

67
describe('PlatformContextPlugin on iOS', () => {
78
beforeAll(() => {
@@ -22,6 +23,12 @@ describe('PlatformContextPlugin on iOS', () => {
2223
isVision: false,
2324
select: () => null,
2425
}));
26+
jest.spyOn(Dimensions, 'get').mockReturnValue({
27+
width: 123.4567,
28+
height: 89.1234,
29+
scale: 0,
30+
fontScale: 0,
31+
});
2532
NativeModules.SettingsManager = {
2633
settings: {
2734
AppleLanguages: ['en-GB'],
@@ -51,6 +58,7 @@ describe('PlatformContextPlugin on iOS', () => {
5158
expect(payload?.co).toContain('"iOS"');
5259
expect(payload?.co).toContain('"18.0"');
5360
expect(payload?.co).toContain('"en-GB"');
61+
expect(payload?.co).toContain('"123x89"');
5462
});
5563

5664
it('does not add platform context to events if disabled', async () => {

0 commit comments

Comments
 (0)