Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeplink not getting tracked. #127

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -31,10 +31,10 @@ import java.util.*
val WIDEVINE_UUID = UUID(-0x121074568629b532L, -0x5c37d8232ae2de13L)

/** AnalyticsPlugin */
class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHandler, ActivityAware,
class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHandler, ActivityAware,
PluginRegistry.NewIntentListener {
private var context: Context? = null

private val pendingDeeplinkEventsQueue: Queue<Intent> = LinkedList()
private fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) }

private val eventsChannel = "analytics/deep_link_events"
Expand Down Expand Up @@ -198,13 +198,31 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand
private fun handleIntent(context: Context, intent: Intent) {
val action = intent.action
if (Intent.ACTION_VIEW == action) {
if (changeReceiver != null) changeReceiver!!.onReceive(context, intent)
if (changeReceiver != null) {
changeReceiver!!.onReceive(context, intent)
} else {
pendingDeeplinkEventsQueue.add(intent.cloneFilter())
}
}
}

private fun processPendingDeeplinkEventsQueue() {
if (pendingDeeplinkEventsQueue.isEmpty() ||
this.context == null ||
changeReceiver == null
) {
return
}
while (pendingDeeplinkEventsQueue.isNotEmpty()) {
val intent = pendingDeeplinkEventsQueue.poll()
changeReceiver?.onReceive(context, intent)
Rjaintwilio marked this conversation as resolved.
Show resolved Hide resolved
}
}

override fun onListen(arguments: Any?, events: EventSink?) {
if (events != null) {
this.changeReceiver = createChangeReceiver(events)
processPendingDeeplinkEventsQueue()
}
}

Expand All @@ -216,7 +234,10 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand
binding.addOnNewIntentListener(this)
if (this.context != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
binding.activity.intent.putExtra("referringApplication", binding.activity.referrer.toString())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this key should be "referrer" according to segment docs I believe.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm it's "referrer" in analytics-kotlin.

binding.activity.intent.putExtra(
"referringApplication",
binding.activity.referrer.toString()
)
}
this.handleIntent(this.context!!, binding.activity.intent)
}
Expand Down
17 changes: 16 additions & 1 deletion packages/core/ios/Classes/AnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import UIKit
import Foundation

public class AnalyticsPlugin: NSObject, FlutterPlugin, NativeContextApi, FlutterStreamHandler, FlutterApplicationLifeCycleDelegate {
private var pendingDeeplinkEventsQueue:[[String:String]] = []
public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
_eventSink = events
processPendingDeeplinkEventsQueue();
return nil
}

Expand All @@ -17,16 +19,29 @@ public class AnalyticsPlugin: NSObject, FlutterPlugin, NativeContextApi, Flutter
public func application(_ application: UIApplication, open url: URL, sourceApplication: String, annotation: Any) -> Bool {
if (_eventSink != nil) {
_eventSink?(["url": url.absoluteString, "referringApplication": sourceApplication])
}else{
pendingDeeplinkEventsQueue.append(["url": url.absoluteString, "referringApplication": sourceApplication]);
Comment on lines 22 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. "referrer".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

}
return true
}
public func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
if (_eventSink != nil) {
_eventSink?([url: url.absoluteString])
}else{
pendingDeeplinkEventsQueue.append(["url": url.absoluteString]);
}
return true
}

private func processPendingDeeplinkEventsQueue() -> Void{

if(_eventSink == nil || pendingDeeplinkEventsQueue.isEmpty){
return;
}
while(!pendingDeeplinkEventsQueue.isEmpty){
let eventData:[String:String] = pendingDeeplinkEventsQueue.removeFirst();
_eventSink?(eventData);
Rjaintwilio marked this conversation as resolved.
Show resolved Hide resolved
}
}
internal static var device = VendorSystem.current

func getContext(collectDeviceId: Bool, completion: @escaping (Result<NativeContext, Error>) -> Void) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class DeepLinkDataState extends PersistedState<DeepLinkData> {

@JsonSerializable(explicitToJson: true, includeIfNull: false)
class DeepLinkData {
final String referringApplication;
final String? referringApplication;
final String url;

DeepLinkData(this.referringApplication, this.url);
Expand Down
20 changes: 14 additions & 6 deletions packages/core/lib/state.g.dart

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

Loading