Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,12 +55,13 @@ data class NativeContext (
val os: NativeContextOS? = (list[5] as? List<Any?>)?.let {
NativeContextOS.fromList(it)
}
val screen: NativeContextScreen? = (list[6] as? List<Any?>)?.let {
val referrer = list[6] as? String
val screen: NativeContextScreen? = (list[7] as? List<Any?>)?.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<Any?> {
Expand All @@ -70,6 +72,7 @@ data class NativeContext (
locale,
network?.toList(),
os?.toList(),
referrer,
screen?.toList(),
timezone,
userAgent,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/ios/Classes/AnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)),
Expand Down
10 changes: 7 additions & 3 deletions packages/core/ios/Classes/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -79,6 +81,7 @@ struct NativeContext {
locale: locale,
network: network,
os: os,
referrer: referrer,
screen: screen,
timezone: timezone,
userAgent: userAgent
Expand All @@ -92,6 +95,7 @@ struct NativeContext {
locale,
network?.toList(),
os?.toList(),
referrer,
screen?.toList(),
timezone,
userAgent,
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/analytics_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion packages/core/lib/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -372,6 +374,7 @@ class Context extends JSONExtendableImpl {
"locale",
"network",
"os",
"referrer",
"screen",
"timezone",
"traits"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/lib/event.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions packages/core/lib/native_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class NativeContext {
this.locale,
this.network,
this.os,
this.referrer,
this.screen,
this.timezone,
this.userAgent,
Expand All @@ -33,6 +34,8 @@ class NativeContext {

NativeContextOS? os;

String? referrer;

NativeContextScreen? screen;

String? timezone;
Expand All @@ -47,6 +50,7 @@ class NativeContext {
locale,
network?.encode(),
os?.encode(),
referrer,
screen?.encode(),
timezone,
userAgent,
Expand All @@ -72,11 +76,12 @@ class NativeContext {
os: result[5] != null
? NativeContextOS.decode(result[5]! as List<Object?>)
: null,
screen: result[6] != null
? NativeContextScreen.decode(result[6]! as List<Object?>)
referrer: result[6] as String?,
screen: result[7] != null
? NativeContextScreen.decode(result[7]! as List<Object?>)
: null,
timezone: result[7] as String?,
userAgent: result[8] as String?,
timezone: result[8] as String?,
userAgent: result[9] as String?,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/macos/Classes/AnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
10 changes: 7 additions & 3 deletions packages/core/macos/Classes/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -79,6 +81,7 @@ struct NativeContext {
locale: locale,
network: network,
os: os,
referrer: referrer,
screen: screen,
timezone: timezone,
userAgent: userAgent
Expand All @@ -92,6 +95,7 @@ struct NativeContext {
locale,
network?.toList(),
os?.toList(),
referrer,
screen?.toList(),
timezone,
userAgent,
Expand Down
1 change: 1 addition & 0 deletions packages/core/pigeon/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class NativeContext {
String? locale;
NativeContextNetwork? network;
NativeContextOS? os;
String? referrer;
NativeContextScreen? screen;
String? timezone;
String? userAgent;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/events_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,7 @@ class MockPlatform extends AnalyticsPlatform {
"en_EN",
networkObj,
osObj,
"referrer",
screenObj,
"timezone",
"userAgent"
Expand Down