Skip to content

Commit 27c77b5

Browse files
committed
Make mobile_context values more consistent with earlier tracker versions
1 parent ca65906 commit 27c77b5

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
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": "Make mobile_context values more consistent with v2 tracker",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/react-native-tracker"
10+
}

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { CorePluginConfiguration } from '@snowplow/tracker-core';
22
import { PlatformContextConfiguration, PlatformContextProperty } from '../../types';
33
import { MOBILE_CONTEXT_SCHEMA } from '../../constants';
4-
import { Platform, PlatformIOSStatic, PlatformConstants, Dimensions, PixelRatio, NativeModules } from 'react-native';
4+
import {
5+
Platform,
6+
PlatformAndroidStatic,
7+
PlatformIOSStatic,
8+
Dimensions,
9+
PixelRatio,
10+
NativeModules,
11+
} from 'react-native';
512
import { removeEmptyProperties } from '@snowplow/tracker-core';
613

714
export interface PlatformContextPlugin extends CorePluginConfiguration {
@@ -10,7 +17,6 @@ export interface PlatformContextPlugin extends CorePluginConfiguration {
1017
refreshPlatformContext: () => Promise<void>;
1118
}
1219

13-
1420
function getIOSConstants() {
1521
// Example Platform info on iOS:
1622
// {
@@ -38,24 +44,12 @@ function getIOSConstants() {
3844
// "AppleLocale": "en_GB"
3945
// }
4046

41-
const constants = Platform.constants as PlatformConstants & {
42-
osVersion: string;
43-
systemName: string;
44-
isMacCatalyst?: boolean | undefined;
45-
};
47+
const { isPad, isTV, isVision, isMacCatalyst, constants } = Platform as PlatformIOSStatic;
4648
return {
4749
osType: constants.systemName,
48-
deviceManufacturer: 'Apple',
50+
deviceManufacturer: 'Apple Inc.',
4951
osVersion: constants.osVersion,
50-
deviceModel: (Platform as PlatformIOSStatic).isPad
51-
? 'iPad'
52-
: Platform.isTV
53-
? 'Apple TV'
54-
: (Platform as PlatformIOSStatic).isVision
55-
? 'Vision'
56-
: (Platform as PlatformIOSStatic).isMacCatalyst
57-
? 'Mac'
58-
: 'iPhone',
52+
deviceModel: isPad ? 'iPad' : isTV ? 'Apple TV' : isVision ? 'Vision' : isMacCatalyst ? 'Mac' : 'iPhone',
5953
language:
6054
NativeModules.SettingsManager?.settings?.AppleLocale ||
6155
NativeModules.SettingsManager?.settings?.AppleLanguages[0], //iOS 13
@@ -78,15 +72,11 @@ function getAndroidConstants() {
7872

7973
// Example NativeModules.I18nManager info on Android:
8074
// { "localeIdentifier": "en_US" }
81-
const constants = Platform.constants as PlatformConstants & {
82-
Version: number;
83-
Model: string;
84-
Manufacturer: string;
85-
};
75+
const constants = Platform.constants as PlatformAndroidStatic['constants'];
8676
return {
87-
osType: 'Android',
77+
osType: 'android',
8878
deviceManufacturer: constants.Manufacturer,
89-
osVersion: String(constants.Version),
79+
osVersion: constants.Release,
9080
deviceModel: constants.Model,
9181
language: NativeModules.I18nManager?.localeIdentifier,
9282
};
@@ -238,12 +228,13 @@ export async function newPlatformContextPlugin({
238228
? await platformContextRetriever?.getScale()
239229
: PixelRatio.get()
240230
: undefined;
241-
language =
242-
(platformContextProperties?.includes(PlatformContextProperty.Language) ?? true
231+
language = (
232+
platformContextProperties?.includes(PlatformContextProperty.Language) ?? true
243233
? platformContextRetriever?.getLanguage
244234
? await platformContextRetriever?.getLanguage()
245235
: constants?.language
246-
: undefined)?.substring(0, 8);
236+
: undefined
237+
)?.substring(0, 8);
247238
appSetId =
248239
platformContextProperties?.includes(PlatformContextProperty.AppSetId) ?? true
249240
? platformContextRetriever?.getAppSetId

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('PlatformContextPlugin on Android', () => {
4848
const [payload] = payloads;
4949
expect(payload?.co).toBeDefined();
5050
expect(payload?.co).toContain(MOBILE_CONTEXT_SCHEMA);
51-
expect(payload?.co).toContain('"33"');
51+
expect(payload?.co).toContain('"13"');
5252
expect(payload?.co).toContain('"sdk_gphone64_arm64"');
5353
expect(payload?.co).toContain('"Google"');
5454
expect(payload?.co).toContain('"Google"');

0 commit comments

Comments
 (0)