Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,18 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
call.argument<String>("serverUrl")?.let { builder.serverUrl = it }
call.argument<Int>("minTimeBetweenSessionsMillis")
?.let { builder.minTimeBetweenSessionsMillis = it.toLong() }
call.argument<Map<String, Any>>("defaultTracking")?.let { map ->
val sessions = (map["sessions"] as? Boolean) ?: true
val appLifecycles = (map["appLifecycles"] as? Boolean) ?: false
val deepLinks = (map["deepLinks"] as? Boolean) ?: false
// screenViews is always disabled on Android — implemented in Flutter
builder.autocapture = buildSet {
if (sessions) add(AutocaptureOption.SESSIONS)
if (appLifecycles) add(AutocaptureOption.APP_LIFECYCLES)
if (deepLinks) add(AutocaptureOption.DEEP_LINKS)
// The Dart Configuration constructor resolves the effective autocapture
// value: a map for AutocaptureOptions/AutocaptureEnabled (derived from
// defaultTracking when not set explicitly), or `false` for
// AutocaptureDisabled. Translate either shape into an AutocaptureOption
// set; if neither is present (e.g. a direct channel caller), leave the
// native SDK defaults in place.
when (val autocaptureArg = call.argument<Any>("autocapture")) {
false -> builder.autocapture = emptySet()
is Map<*, *> -> builder.autocapture = buildSet {
if (autocaptureArg["sessions"] == true) add(AutocaptureOption.SESSIONS)
if (autocaptureArg["appLifecycles"] == true) add(AutocaptureOption.APP_LIFECYCLES)
if (autocaptureArg["deepLinks"] == true) add(AutocaptureOption.DEEP_LINKS)
}
}
call.argument<Map<String, Any>>("trackingOptions")?.let { map ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,30 @@ internal var pluginInstance: SwiftAmplitudeFlutterPlugin?
let instanceName = args["instanceName"] as? String ?? Constants.Configuration.DEFAULT_INSTANCE
let migrateLegacyData = args["migrateLegacyData"] as? Bool ?? true

// The Dart Configuration constructor resolves the effective autocapture
// value: a map for AutocaptureOptions/AutocaptureEnabled (derived from
// defaultTracking when not set explicitly), or `false` for
// AutocaptureDisabled. Translate either shape into an AutocaptureOptions
// option set; if neither is present (e.g. a direct channel caller),
// fall back to the native SDK defaults.
let autocaptureOptions: AutocaptureOptions = {
switch args["autocapture"] {
case let disabled as Bool where disabled == false:
return []
case let map as [String: Any]:
var opts: AutocaptureOptions = []
if (map["sessions"] as? Bool) == true { opts.insert(.sessions) }
if (map["appLifecycles"] as? Bool) == true { opts.insert(.appLifecycles) }
return opts
default:
return Configuration.Defaults.autocaptureOptions
}
}()
Comment thread
cursor[bot] marked this conversation as resolved.

let configuration = Configuration(
apiKey: apiKey,
instanceName: instanceName,
autocapture: autocaptureOptions,
migrateLegacyData: migrateLegacyData)

if let flushQueueSize = args["flushQueueSize"] as? Int {
Expand Down Expand Up @@ -243,18 +264,6 @@ internal var pluginInstance: SwiftAmplitudeFlutterPlugin?
if let identifyBatchIntervalMillis = args["identifyBatchIntervalMillis"] as? Int {
configuration.identifyBatchIntervalMillis = identifyBatchIntervalMillis
}
if let defaultTrackingDict = args["defaultTracking"] as? [String: Bool] {
let sessions = defaultTrackingDict["sessions"] ?? true
let appLifecycles = defaultTrackingDict["appLifecycles"] ?? false
// Set false to disable screenViews on iOS
// screenViews is implemented in Flutter
let screenViews = false
configuration.defaultTracking = DefaultTrackingOptions(
sessions: sessions,
appLifecycles: appLifecycles,
screenViews: screenViews
)
}

return configuration
}
Expand Down
4 changes: 2 additions & 2 deletions example/lib/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';

// ignore_for_file: depend_on_referenced_packages
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_flutter/autocapture/autocapture.dart';
import 'package:amplitude_flutter/configuration.dart';
import 'package:amplitude_flutter/constants.dart';
import 'package:amplitude_flutter/default_tracking.dart';
import 'package:flutter/material.dart';

import 'app_state.dart';
Expand Down Expand Up @@ -44,7 +44,7 @@ class _MyAppState extends State<MyApp> {
analytics = Amplitude(Configuration(
apiKey: widget.apiKey,
logLevel: LogLevel.debug,
defaultTracking: DefaultTrackingOptions.all()));
autocapture: const AutocaptureEnabled()));
initAnalytics();
}

Expand Down
209 changes: 0 additions & 209 deletions example/pubspec.lock

This file was deleted.

Loading
Loading