Mr. no
Mr. no

Reputation: 21

Retrieving UTMParameters from Firebase Dynamic Link

I've recently made some experiments with Firebase Dynamic Links.

I set the app following the Docs Guidelines (setting the intent filters properly). I've generated a Dynamic Link from the Firebase Console, using the optional parameters section for UTM.

Then I prepared the code in my activity in order to receive the link.

Firebase.dynamicLinks
    .getDynamicLink(intent)
    .addOnSuccessListener(this) { pendingDynamicLinkData ->
        var deepLink: Uri? = null
        var utm:Bundle? = null
        var extensions: Bundle? = null
        if (pendingDynamicLinkData != null) {
            deepLink = pendingDynamicLinkData.link
            utm = pendingDynamicLinkData.utmParameters
            extensions = pendingDynamicLinkData.extensions
        }
    }
    .addOnFailureListener(this) { e -> Log.w(TAG, "getDynamicLink:onFailure", e) }

The result I obtain is that I can receive the actual link. However, I'd like to take embed the utm parameters following the schema that is presented by the console itself. I've found very few materials, and even the Firebase docs don't mention how to gather those data, so I doubted it to be actually possible.

However, I've noticed the existence of some methods in the library, "utmParameters" and "extensions", that sound like, respectively, the UTM Parameters and the extended link (that should contain other parameters like "apn").

Moreover, in my iOS App, following the Firebase docs I'm able to recover those data. This, with the existence of the method "utmParameters" and "extensions" in Kotlin makes me think that it should be possible to do so also in Kotlin. However, if I try to retrieve those parameters from my DynamicLink, I get empty Bundles (the only method that seems to recover actual data is "timestamp", along with "link" that gives me the actual deeplink).

Does anybody know how I could recover those parameters (withous passing them in the deeplink) ? Or does someone have any evidence of the fact that recovering those data isn't possible (if not by the deeplink), in Kotlin ?

Upvotes: 1

Views: 1408

Answers (2)

JusMelon
JusMelon

Reputation: 37

@m-r-murazza

I also experience the same problem with dynamic links and empty bundle in utmParameters.

Apparently, when we don't add dynamic links as intent-filter in AndroidManifest all utmParameters and extension will be empty bundle.

To fix this problem, what I do is add both the dynamic links and the real deeplink url as intent-filter.

<!-- Normal Deeplink -->
<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data
        android:host="www.example.com"
        android:scheme="https"/>
</intent-filter>

<!-- Firebase Dynamic Link -->
<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data
        android:host="links.example.com"
        android:scheme="https"/>
</intent-filter>

Hope this can help you.

Upvotes: 2

Mr. no
Mr. no

Reputation: 21

I found the problem.

I didn't set properly the AndroidManifest. Tapping the highlighted link used to open the app, but the intent wasn't caught by the proper intent-filter, so when retrieving pendingDynamicLinkData, it lacked the extensions i mentioned before.

Upvotes: 1

Related Questions