diff --git a/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt b/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt index ef8d597..3ce47bd 100644 --- a/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt +++ b/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt @@ -38,6 +38,7 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand private fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) } private val eventsChannel = "analytics/deep_link_events" + private val referrerUrl: String? = null override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { context = flutterPluginBinding.applicationContext @@ -166,6 +167,7 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand name = "Android", version = Build.VERSION.RELEASE, ), + referrer = referrerUrl, screen = NativeContextScreen( height = displayMetrics.heightPixels.toLong(), width = displayMetrics.widthPixels.toLong(), @@ -190,6 +192,7 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand } else { val data = mapOf("url" to dataString, "referring_application" to referringApplication) events.success(data) + referrerUrl = dataString } } } diff --git a/packages/core/android/src/main/kotlin/com/segment/analytics/Context.kt b/packages/core/android/src/main/kotlin/com/segment/analytics/Context.kt index 0cb9530..ba67bd9 100644 --- a/packages/core/android/src/main/kotlin/com/segment/analytics/Context.kt +++ b/packages/core/android/src/main/kotlin/com/segment/analytics/Context.kt @@ -30,6 +30,7 @@ data class NativeContext ( val locale: String? = null, val network: NativeContextNetwork? = null, val os: NativeContextOS? = null, + val referrer: String? = null, val screen: NativeContextScreen? = null, val timezone: String? = null, val userAgent: String? = null @@ -54,12 +55,13 @@ data class NativeContext ( val os: NativeContextOS? = (list[5] as? List)?.let { NativeContextOS.fromList(it) } - val screen: NativeContextScreen? = (list[6] as? List)?.let { + val referrer = list[6] as? String + val screen: NativeContextScreen? = (list[7] as? List)?.let { NativeContextScreen.fromList(it) } - val timezone = list[7] as? String - val userAgent = list[8] as? String - return NativeContext(app, device, library, locale, network, os, screen, timezone, userAgent) + val timezone = list[8] as? String + val userAgent = list[9] as? String + return NativeContext(app, device, library, locale, network, os, referrer, screen, timezone, userAgent) } } fun toList(): List { @@ -70,6 +72,7 @@ data class NativeContext ( locale, network?.toList(), os?.toList(), + referrer, screen?.toList(), timezone, userAgent, diff --git a/packages/core/ios/Classes/AnalyticsPlugin.swift b/packages/core/ios/Classes/AnalyticsPlugin.swift index 0dde117..a23d6b7 100644 --- a/packages/core/ios/Classes/AnalyticsPlugin.swift +++ b/packages/core/ios/Classes/AnalyticsPlugin.swift @@ -4,6 +4,7 @@ import Foundation public class AnalyticsPlugin: NSObject, FlutterPlugin, NativeContextApi, FlutterStreamHandler, FlutterApplicationLifeCycleDelegate { private var pendingDeeplinkEventsQueue:[[String:String?]] = [] + private var referrerUrl: String? = nil public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { _eventSink = events processPendingDeeplinkEventsQueue(); @@ -89,6 +90,7 @@ public class AnalyticsPlugin: NSObject, FlutterPlugin, NativeContextApi, Flutter os: NativeContextOS( name: device.systemName, version: device.systemVersion), + referrer: referrerUrl, screen: NativeContextScreen( height: Int32(screen.height), width: Int32(screen.width)), diff --git a/packages/core/ios/Classes/Context.swift b/packages/core/ios/Classes/Context.swift index f2922e7..bb2bee3 100644 --- a/packages/core/ios/Classes/Context.swift +++ b/packages/core/ios/Classes/Context.swift @@ -39,6 +39,7 @@ struct NativeContext { var locale: String? = nil var network: NativeContextNetwork? = nil var os: NativeContextOS? = nil + var referrer: String? = nil var screen: NativeContextScreen? = nil var timezone: String? = nil var userAgent: String? = nil @@ -65,12 +66,13 @@ struct NativeContext { if let osList = list[5] as? [Any?] { os = NativeContextOS.fromList(osList) } + var referrer: String? = list[6] as? String var screen: NativeContextScreen? = nil - if let screenList = list[6] as? [Any?] { + if let screenList = list[7] as? [Any?] { screen = NativeContextScreen.fromList(screenList) } - let timezone = list[7] as? String - let userAgent = list[8] as? String + let timezone = list[8] as? String + let userAgent = list[9] as? String return NativeContext( app: app, @@ -79,6 +81,7 @@ struct NativeContext { locale: locale, network: network, os: os, + referrer: referrer, screen: screen, timezone: timezone, userAgent: userAgent @@ -92,6 +95,7 @@ struct NativeContext { locale, network?.toList(), os?.toList(), + referrer, screen?.toList(), timezone, userAgent, diff --git a/packages/core/lib/analytics_web.dart b/packages/core/lib/analytics_web.dart index 303661a..b28083e 100644 --- a/packages/core/lib/analytics_web.dart +++ b/packages/core/lib/analytics_web.dart @@ -23,6 +23,7 @@ class AnalyticsPlatformImpl extends AnalyticsPlatform { ), userAgent: web.window.navigator.userAgent, locale: web.window.navigator.language, + referrer: web.window.document.referrer, // SETH PLZ CHECK ME ON THIS screen: NativeContextScreen( height: web.window.screen.height, width: web.window.screen.width, diff --git a/packages/core/lib/event.dart b/packages/core/lib/event.dart index b8454ee..2ed1e84 100644 --- a/packages/core/lib/event.dart +++ b/packages/core/lib/event.dart @@ -327,13 +327,14 @@ class Context extends JSONExtendableImpl { String locale; ContextNetwork network; ContextOS os; + String referrer; ContextScreen screen; String timezone; String? instanceId; UserTraits traits; Context(this.app, this.device, this.library, this.locale, this.network, - this.os, this.screen, this.timezone, this.traits, + this.os, this.referrer, this.screen, this.timezone, this.traits, {this.instanceId, super.custom}); Context.fromNative(NativeContext nativeContext, this.traits) : app = nativeContext.app == null @@ -355,6 +356,7 @@ class Context extends JSONExtendableImpl { os = nativeContext.os == null ? ContextOS("", "") : ContextOS.fromNative(nativeContext.os as NativeContextOS), + referrer = nativeContext.referrer ?? "", screen = nativeContext.screen == null ? ContextScreen(0, 0) : ContextScreen.fromNative( @@ -372,6 +374,7 @@ class Context extends JSONExtendableImpl { "locale", "network", "os", + "referrer", "screen", "timezone", "traits" @@ -653,6 +656,7 @@ Context mergeContext(Context a, Context b) { a.locale, a.network, a.os, + a.referrer, mergeContextScreen(a.screen, b.screen), a.timezone, a.traits, diff --git a/packages/core/lib/event.g.dart b/packages/core/lib/event.g.dart index f9f9461..3c3843b 100644 --- a/packages/core/lib/event.g.dart +++ b/packages/core/lib/event.g.dart @@ -344,6 +344,7 @@ Context _$ContextFromJson(Map json) => Context( json['locale'] as String, ContextNetwork.fromJson(json['network'] as Map), ContextOS.fromJson(json['os'] as Map), + json['referrer'] as String, ContextScreen.fromJson(json['screen'] as Map), json['timezone'] as String, UserTraits.fromJson(json['traits'] as Map), @@ -360,6 +361,7 @@ Map _$ContextToJson(Context instance) { 'locale': instance.locale, 'network': instance.network.toJson(), 'os': instance.os.toJson(), + 'referrer': instance.referrer, 'screen': instance.screen.toJson(), 'timezone': instance.timezone, }; diff --git a/packages/core/lib/native_context.dart b/packages/core/lib/native_context.dart index 737bb9b..3fcaec8 100644 --- a/packages/core/lib/native_context.dart +++ b/packages/core/lib/native_context.dart @@ -16,6 +16,7 @@ class NativeContext { this.locale, this.network, this.os, + this.referrer, this.screen, this.timezone, this.userAgent, @@ -33,6 +34,8 @@ class NativeContext { NativeContextOS? os; + String? referrer; + NativeContextScreen? screen; String? timezone; @@ -47,6 +50,7 @@ class NativeContext { locale, network?.encode(), os?.encode(), + referrer, screen?.encode(), timezone, userAgent, @@ -72,11 +76,12 @@ class NativeContext { os: result[5] != null ? NativeContextOS.decode(result[5]! as List) : null, - screen: result[6] != null - ? NativeContextScreen.decode(result[6]! as List) + referrer: result[6] as String?, + screen: result[7] != null + ? NativeContextScreen.decode(result[7]! as List) : null, - timezone: result[7] as String?, - userAgent: result[8] as String?, + timezone: result[8] as String?, + userAgent: result[9] as String?, ); } } diff --git a/packages/core/macos/Classes/AnalyticsPlugin.swift b/packages/core/macos/Classes/AnalyticsPlugin.swift index ad23e8f..1efe7f1 100644 --- a/packages/core/macos/Classes/AnalyticsPlugin.swift +++ b/packages/core/macos/Classes/AnalyticsPlugin.swift @@ -54,6 +54,7 @@ internal static var device = VendorSystem.current os: NativeContextOS( name: device.systemName, version: device.systemVersion), + referrer: nil, screen: NativeContextScreen( height: Int32(screen.height), width: Int32(screen.width)), diff --git a/packages/core/macos/Classes/Context.swift b/packages/core/macos/Classes/Context.swift index c1c5613..176c07f 100644 --- a/packages/core/macos/Classes/Context.swift +++ b/packages/core/macos/Classes/Context.swift @@ -39,6 +39,7 @@ struct NativeContext { var locale: String? = nil var network: NativeContextNetwork? = nil var os: NativeContextOS? = nil + var referrer: String? = nil var screen: NativeContextScreen? = nil var timezone: String? = nil var userAgent: String? = nil @@ -65,12 +66,13 @@ struct NativeContext { if let osList = list[5] as? [Any?] { os = NativeContextOS.fromList(osList) } + let referrer = list[6] as? String var screen: NativeContextScreen? = nil - if let screenList = list[6] as? [Any?] { + if let screenList = list[7] as? [Any?] { screen = NativeContextScreen.fromList(screenList) } - let timezone = list[7] as? String - let userAgent = list[8] as? String + let timezone = list[8] as? String + let userAgent = list[9] as? String return NativeContext( app: app, @@ -79,6 +81,7 @@ struct NativeContext { locale: locale, network: network, os: os, + referrer: referrer, screen: screen, timezone: timezone, userAgent: userAgent @@ -92,6 +95,7 @@ struct NativeContext { locale, network?.toList(), os?.toList(), + referrer, screen?.toList(), timezone, userAgent, diff --git a/packages/core/pigeon/context.dart b/packages/core/pigeon/context.dart index 312f89b..1c36427 100644 --- a/packages/core/pigeon/context.dart +++ b/packages/core/pigeon/context.dart @@ -7,6 +7,7 @@ class NativeContext { String? locale; NativeContextNetwork? network; NativeContextOS? os; + String? referrer; NativeContextScreen? screen; String? timezone; String? userAgent; diff --git a/packages/core/test/events_test.dart b/packages/core/test/events_test.dart index f0a9e43..38ddf2a 100644 --- a/packages/core/test/events_test.dart +++ b/packages/core/test/events_test.dart @@ -17,6 +17,7 @@ class MockPlatform extends AnalyticsPlatform { mockNativeContext.os = NativeContextOS(); mockNativeContext.os!.name = "iOS"; mockNativeContext.os!.version = "14.1"; + mockNativeContext.referrer = "referrer"; mockNativeContext.screen = NativeContextScreen(); mockNativeContext.screen!.height = 800; mockNativeContext.screen!.width = 600; @@ -55,6 +56,7 @@ class MockPlatform extends AnalyticsPlatform { "en_EN", networkObj, osObj, + "referrer", screenObj, "timezone", "userAgent"