Skip to content

Commit

Permalink
Disable automatic screen view tracking in the iOS and Android tracker…
Browse files Browse the repository at this point in the history
… by default (close #198)

PR #202
  • Loading branch information
matus-tomlein committed Oct 5, 2023
1 parent 930fe2d commit 837f6d3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ class ReactNativeTrackerModule(val reactContext: ReactApplicationContext) :
val controllers: MutableList<Configuration> = 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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import java.util.concurrent.TimeUnit

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)
Expand Down
1 change: 0 additions & 1 deletion example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const App = () => {
appId: 'DemoAppId',
base64Encoding: false,
devicePlatform: 'iot',
screenViewAutotracking: false, // for tests predictability
installAutotracking: false,
},
sessionConfig: {
Expand Down
6 changes: 2 additions & 4 deletions ios/ReactNativeTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion ios/Util/ConfigUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/configurations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('test initValidate resolves', () => {
sessionContext: true,
deepLinkContext: true,
screenContext: true,
screenViewAutotracking: true,
screenViewAutotracking: false,
lifecycleAutotracking: false,
installAutotracking: true,
exceptionAutotracking: true,
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('test isValidTrackerConf', () => {
logLevel: 'off',
platformContext: true,
screenContext: true,
screenViewAutotracking: true,
screenViewAutotracking: false,
sessionContext: true,
deepLinkContext: true,
userAnonymisation: false,
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ export interface TrackerConfiguration {
*/
screenContext?: boolean;
/**
* Whether enable automatic tracking of ScreenView events.
* @defaultValue true
* Whether to 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;
/**
Expand Down

0 comments on commit 837f6d3

Please sign in to comment.