firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 573 forks source link

Override behavior of In-App message #3056

Open garispe opened 2 years ago

garispe commented 2 years ago

[REQUIRED] Step 2: Describe your environment

[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

google-oss-bot commented 2 years ago

I found a few problems with this issue:

aguatno commented 2 years ago

Hi @garispe Thanks for pointing this out. We will check on this solution and get back. In the mean time, do you want to come up with a Pull Request?

garispe commented 2 years ago

Hi @aguatno Thanks for your reply. I can create the corresponding PR but I don't know if it's the expected behavior from Firebase because iOS works in the same way. If this is correct, I'll need to manage this issue locally in my app. Do you think that is an unexpected behavior?

AbdulrhmanKassemSalla commented 2 years ago

I faced the same issue if I used this listener "messageClicked" I don't want any other behaviour @garispe your solution is perfect

garispe commented 2 years ago

@AbdulrhmanKassemSalla I already opened a PR to fix this

argzdev commented 2 years ago

Hi @garispe, thank you for submitting a PR for this! I was able to test this and it works nicely.

I'm not sure if this is an intended behavior or an actual bug, I'll notify an engineer to see if we can get your PR approved or if there are changes needs to be done.

garispe commented 2 years ago

Hi @argzdev, thanks!

I look forward to the review. It would be great if that behavior could be modified.

eldhosembabu commented 2 years ago

Hi @garispe , Thanks for reaching out on this and for the PR.

The event listeners mentioned here are for the purpose of tracking the user interactions and not for overriding them. For example when the user interacts with an inapp message and is getting navigated to a web url, if the developer wants to track the navigation, then they can use these listeners. Sorry for the mis understanding here.

But however we understand the developers need for having custom handling of inapp message and so we will consider this in our upcoming features ie. to support inapp message customization and handling.

google-oss-bot commented 2 years ago

Hey @garispe. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Ethan1983 commented 1 year ago

Hi @garispe , Thanks for reaching out on this and for the PR.

The event listeners mentioned here are for the purpose of tracking the user interactions and not for overriding them. For example when the user interacts with an inapp message and is getting navigated to a web url, if the developer wants to track the navigation, then they can use these listeners. Sorry for the mis understanding here.

But however we understand the developers need for having custom handling of inapp message and so we will consider this in our upcoming features ie. to support inapp message customization and handling.

@eldhosembabu Please note there is also a limitation in the current deep link mechanism if and when the campaign has custom data (key value pairs) specified. This isn't passed to the activity handling the deep link. However, these custom data is available in the click listener via [getData](https://firebase.google.com/docs/reference/android/com/google/firebase/inappmessaging/model/InAppMessage?hl=en#data())

Screenshot 2023-05-15 at 8 39 50 PM