11import { CorePluginConfiguration } from '@snowplow/tracker-core' ;
22import { PlatformContextConfiguration , PlatformContextProperty } from '../../types' ;
33import { 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' ;
512import { removeEmptyProperties } from '@snowplow/tracker-core' ;
613
714export interface PlatformContextPlugin extends CorePluginConfiguration {
@@ -10,7 +17,6 @@ export interface PlatformContextPlugin extends CorePluginConfiguration {
1017 refreshPlatformContext : ( ) => Promise < void > ;
1118}
1219
13-
1420function 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
0 commit comments