From 89358627b215e9897d7edab63b550b569b58ced8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Thu, 7 Sep 2023 16:07:26 +0200 Subject: [PATCH] Disable automatic screen view tracking in the iOS and Android tracker by default (close #198) --- .../reactnativetracker/ReactNativeTrackerModule.kt | 7 ++----- .../com/snowplow/reactnativetracker/util/ConfigUtil.kt | 8 +++++--- example/src/App.js | 1 - ios/ReactNativeTracker.swift | 6 ++---- ios/Util/ConfigUtils.swift | 4 +++- src/__tests__/configurations.test.ts | 4 ++-- src/types.ts | 6 ++++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt b/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt index 855e8f31..0cb2cd30 100644 --- a/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +++ b/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt @@ -91,11 +91,8 @@ class ReactNativeTrackerModule(val reactContext: ReactApplicationContext) : val controllers: MutableList = ArrayList() // TrackerConfiguration - argmap.getMap("trackerConfig")?.let { trackerConfig -> - val trackerConfiguration: TrackerConfiguration = - ConfigUtil.mkTrackerConfiguration(trackerConfig, this.reactContext) - controllers.add(trackerConfiguration) - } + val trackerConfiguration = ConfigUtil.mkTrackerConfiguration(argmap.getMap("trackerConfig"), this.reactContext) + controllers.add(trackerConfiguration) // SessionConfiguration argmap.getMap("sessionConfig")?.let { sessionConfig -> diff --git a/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt b/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt index 83ad117a..b1d73b6b 100644 --- a/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +++ b/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt @@ -78,13 +78,15 @@ object ConfigUtil { } fun mkTrackerConfiguration( - trackerConfig: ReadableMap, + trackerConfig: ReadableMap?, context: ReactApplicationContext ): TrackerConfiguration { - val appId: String = - if (trackerConfig.hasKey("appId")) trackerConfig.getString("appId")!! else context.getPackageName() + val appId = trackerConfig?.getString("appId") ?: context.packageName val trackerConfiguration = TrackerConfiguration(appId) .trackerVersionSuffix(TrackerVersion.RN_TRACKER_VERSION) + .screenViewAutotracking(false) + + val trackerConfig = trackerConfig ?: run { return trackerConfiguration } if (trackerConfig.hasKey("devicePlatform")) { val devicePlatform = mkDevicePlatform(trackerConfig.getString("devicePlatform")!!) trackerConfiguration.devicePlatform(devicePlatform) diff --git a/example/src/App.js b/example/src/App.js index 16c2df55..41a87519 100644 --- a/example/src/App.js +++ b/example/src/App.js @@ -86,7 +86,6 @@ const App = () => { appId: 'DemoAppId', base64Encoding: false, devicePlatform: 'iot', - screenViewAutotracking: false, // for tests predictability installAutotracking: false, }, sessionConfig: { diff --git a/ios/ReactNativeTracker.swift b/ios/ReactNativeTracker.swift index 29b7a607..1b75994e 100644 --- a/ios/ReactNativeTracker.swift +++ b/ios/ReactNativeTracker.swift @@ -25,10 +25,8 @@ class ReactNativeTracker: NSObject { var controllers: [ConfigurationProtocol] = [] // TrackerConfiguration - if let trackerArg = argmap.object(forKey: "trackerConfig") as? NSDictionary, - let trackerConfiguration = ConfigUtils.mkTrackerConfig(trackerArg) { - controllers.append(trackerConfiguration) - } + let trackerConfiguration = ConfigUtils.mkTrackerConfig(argmap.object(forKey: "trackerConfig") as? NSDictionary ?? NSDictionary()) + controllers.append(trackerConfiguration) // SessionConfiguration if let sessionArg = argmap.object(forKey: "sessionConfig") as? NSDictionary, diff --git a/ios/Util/ConfigUtils.swift b/ios/Util/ConfigUtils.swift index d5c3392d..68a0e5a7 100644 --- a/ios/Util/ConfigUtils.swift +++ b/ios/Util/ConfigUtils.swift @@ -3,7 +3,7 @@ import SnowplowTracker class ConfigUtils { - static func mkTrackerConfig(_ trackerConfig: NSDictionary) -> TrackerConfiguration? { + static func mkTrackerConfig(_ trackerConfig: NSDictionary) -> TrackerConfiguration { let trackerConfiguration = TrackerConfiguration() trackerConfiguration.trackerVersionSuffix = kRNTrackerVersion @@ -47,6 +47,8 @@ class ConfigUtils { } if let screenViewAutotracking = trackerConfig.object(forKey: "screenViewAutotracking") as? NSNumber { trackerConfiguration.screenViewAutotracking = screenViewAutotracking.boolValue + } else { + trackerConfiguration.screenViewAutotracking = false } if let lifecycleAutotracking = trackerConfig.object(forKey: "lifecycleAutotracking") as? NSNumber { trackerConfiguration.lifecycleAutotracking = lifecycleAutotracking.boolValue diff --git a/src/__tests__/configurations.test.ts b/src/__tests__/configurations.test.ts index e4273f36..af4bd8fb 100644 --- a/src/__tests__/configurations.test.ts +++ b/src/__tests__/configurations.test.ts @@ -251,7 +251,7 @@ describe('test initValidate resolves', () => { sessionContext: true, deepLinkContext: true, screenContext: true, - screenViewAutotracking: true, + screenViewAutotracking: false, lifecycleAutotracking: false, installAutotracking: true, exceptionAutotracking: true, @@ -342,7 +342,7 @@ describe('test isValidTrackerConf', () => { logLevel: 'off', platformContext: true, screenContext: true, - screenViewAutotracking: true, + screenViewAutotracking: false, sessionContext: true, deepLinkContext: true, userAnonymisation: false, diff --git a/src/types.ts b/src/types.ts index ccc8c0a7..fef7e09d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -170,8 +170,10 @@ export interface TrackerConfiguration { */ screenContext?: boolean; /** - * Whether enable automatic tracking of ScreenView events. - * @defaultValue true + * Whether enable automatic tracking of ScreenView events from the native side. + * Only tracking UIKit views on iOS and Activity on Android are supported. + * For tracking React Native views, see the tracker docs for manual and auto-tracking options. + * @defaultValue false */ screenViewAutotracking?: boolean; /**