Skip to content

Commit

Permalink
Round resolution in mobile context to avoid validation failures on An…
Browse files Browse the repository at this point in the history
…droid (#1404)
  • Loading branch information
matus-tomlein committed Jan 13, 2025
1 parent 785c929 commit ff961f1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/react-native-tracker",
"comment": "Round resolution in mobile context to avoid validation failures on Android",
"type": "none"
}
],
"packageName": "@snowplow/react-native-tracker"
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export async function newPlatformContextPlugin({
platformContextProperties?.includes(PlatformContextProperty.Resolution) ?? true
? platformContextRetriever?.getResolution
? await platformContextRetriever?.getResolution()
: Dimensions.get('window').width + 'x' + Dimensions.get('window').height
: Math.floor(Dimensions.get('window').width) + 'x' + Math.floor(Dimensions.get('window').height)
: undefined;
scale =
platformContextProperties?.includes(PlatformContextProperty.Scale) ?? true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { buildPageView, Payload, trackerCore } from '@snowplow/tracker-core';
import { newPlatformContextPlugin } from '../../src/plugins/platform_context';
import { MOBILE_CONTEXT_SCHEMA } from '../../src/constants';
import { NativeModules } from 'react-native';
import { Dimensions } from 'react-native';

describe('PlatformContextPlugin on Android', () => {
beforeAll(() => {
Expand All @@ -17,6 +18,12 @@ describe('PlatformContextPlugin on Android', () => {
},
select: () => null,
}));
jest.spyOn(Dimensions, 'get').mockReturnValue({
width: 123.4567,
height: 89.1234,
scale: 0,
fontScale: 0,
});
NativeModules.I18nManager = {
localeIdentifier: 'en-GB',
};
Expand Down Expand Up @@ -46,5 +53,6 @@ describe('PlatformContextPlugin on Android', () => {
expect(payload?.co).toContain('"Google"');
expect(payload?.co).toContain('"Google"');
expect(payload?.co).toContain('"en-GB"');
expect(payload?.co).toContain('"123x89"');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { buildPageView, Payload, trackerCore } from '@snowplow/tracker-core';
import { newPlatformContextPlugin } from '../../src/plugins/platform_context';
import { NativeModules } from 'react-native';
import { MOBILE_CONTEXT_SCHEMA } from '../../src/constants';
import { Dimensions } from 'react-native';

describe('PlatformContextPlugin on iOS', () => {
beforeAll(() => {
Expand All @@ -22,6 +23,12 @@ describe('PlatformContextPlugin on iOS', () => {
isVision: false,
select: () => null,
}));
jest.spyOn(Dimensions, 'get').mockReturnValue({
width: 123.4567,
height: 89.1234,
scale: 0,
fontScale: 0,
});
NativeModules.SettingsManager = {
settings: {
AppleLanguages: ['en-GB'],
Expand Down Expand Up @@ -51,6 +58,7 @@ describe('PlatformContextPlugin on iOS', () => {
expect(payload?.co).toContain('"iOS"');
expect(payload?.co).toContain('"18.0"');
expect(payload?.co).toContain('"en-GB"');
expect(payload?.co).toContain('"123x89"');
});

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

0 comments on commit ff961f1

Please sign in to comment.