Repository: firebase/firebase-android-sdk

Issue #3056: Override behavior of In-App message
Created: 2021-10-14T14:12:54Z
[REQUIRED] Step 2: Describe your environment

Android Studio version: Arctic Fox 2020.3.1 Patch 3
Firebase Component: In-App Messaging
Component version: com.google.firebase:firebase-bom:28.3.0

[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
I created a Firebase In-App messaging campaign from console and I used addClickListener() to override behavior of primary button action. When I receive the in-app message and click primary button, my custom listener is invoked correctly but the Firebase SDK opens the link from campaign.
I need to attach dynamic information to the link configured in the Firebase console and then open the composed link.
The problem is in this line because when I override the click behavior, the SDK invokes launchUriIntent(activity, Uri.parse(action.getActionUrl())); anyway
Relevant Code:
I think that the fix can be something like that:
@Override
public void onClick(View v) {
    if (callbacks != null) {
        Logging.logi("Calling callback for click action");
        callbacks.messageClicked(action);
    } else {    <====== THIS ELSE
        launchUriIntent(activity, Uri.parse(action.getActionUrl()));
    }
   
    notifyFiamClick();
    // Ensure that we remove the displayed FIAM, and ensure that on re-load, the message
    // isn't re-displayed
    removeDisplayedFiam(activity);
    inAppMessage = null;
    callbacks = null;
}
In this way, the SDK delegates the behavior to the custom listener

Duplicate issue #5003: [In App Messaging] Ability to override action's default behaviour
Created: 2023-05-16T00:50:06Z
What feature would you like to see?


Firebase In App Messaging's default behaviour is to always launch the URL payload of the action button. Apps typically use deep link to navigate to a part of an application. However, the intent extras for such deep links just has the URL and doesn't have any specified custom data (key value pairs).
 


Support FirebaseInAppMessagingClickListener::messageClicked to return a boolean. Apps wanting to disable FirebaseInAppMessagingDisplay default behaviour can just return true, false otherwise.


new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (callbacks != null) {
                  Logging.logi("Calling callback for click action");
                  callbacks.messageClicked(action);
                }
                launchUriIntent(activity, Uri.parse(action.getActionUrl()));
                notifyFiamClick();
                // Ensure that we remove the displayed FIAM, and ensure that on re-load, the message
                // isn't re-displayed
                removeDisplayedFiam(activity);
                inAppMessage = null;
                callbacks = null;
              }
            };

How would you use it?
This gives app an ability to use custom data in click handler and be able to handle the action url as desired. Currently, it is not possible to get custom data from suggested deep link mechanism.

Closing comment (2023-05-16T12:51:00Z): Thanks for reaching out, @Ethan1983. In a way, this seems similar to #3056. Could you leave a thumbs up emoji on the author's post of #3056? This is so that we can quantify and have better tracking on features that have demand. Feel free to add more information on that thread. That said, I'll go ahead and mark this as a duplicate.