Cannot mark as impressed more than one message almost same time
- Android Studio version: Arctic Fox 2020.3.1 Patch 4
- Firebase Component: InAppMessage
- Component version: 19.1.5
Steps to reproduce:
Have a custom Display component for InAppMessage, i.e.:
FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyFirebaseMessaging());
Relevant Code:
My custom display component has a HashMap to handle multiple messages displaying on screen. Like 2 cards embedded on layout.
private final HashMap<String, HashMap> InAppMessages = new HashMap<>();
Every time we receive a message we do something like:
@Override
public void displayMessage(@NonNull InAppMessage inAppMessage, @NonNull FirebaseInAppMessagingDisplayCallbacks callbacks) {
try {
String campaignId = inAppMessage.getCampaignMetadata().getCampaignId();
// Here we build a object that represents the received message
HashMap<String, Object> inAppMessageObject = new HashMap<String, Object>();
inAppMessageObject.put("message", inAppMessage);
inAppMessageObject.put("callbacks", callbacks);
// Then we put on HashMap this object to be called later
this.InAppMessages.put(campaignId, inAppMessageObject);
} catch (Exception e) {
Log.e("FIAM: Error", e.toString());
}
}
The problem
Some times, more than one event is triggered each one with a message assigned:
FirebaseInAppMessaging.getInstance().triggerEvent("main_screen_opened");
FirebaseInAppMessaging.getInstance().triggerEvent("another_main_screen_opened");
But when we try to mark as impressed only one message are marked. We use something like this to handle multiple messages and mark each as impressed:
public void markAsImpressionDetected(String campaignId) {
try {
// We recover from HashMap the message callbacks
FirebaseInAppMessagingDisplayCallbacks callbacks = (FirebaseInAppMessagingDisplayCallbacks) this.InAppMessages.get(campaignId).get("callbacks");
// And call
callbacks.impressionDetected();
} catch(Exception e) {
Log.e("FIAM: Error", e.toString());
}
}
With milliseconds between each call. But always only one of 2 or more messages are marked as impressed. And no error was throw
I found a few problems with this issue:
- I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
- This issue does not seem to follow the issue template. Make sure you provide all the required information.
Hi @igorjacauna, thanks for reporting.
May I ask where do you call markAsImpressionDetected? Also any chance you could provide a minimal repro of your issue? Thanks in advance!
Hi @argzdev ! Thanks for the reply!
So, let me try explain how we use it.
Currently, we are using in a ReactNative app, so on our custom Display class, when the displayMessage are called, we send a event to ReactNative to render the component assign to message.
We were trying to use to display 2 differents messages linked to 2 cards components embeded on layout at same time, so we trigged two events each one linked with a differente message.
So, displayMessage are called twice and and send info about the messages to ReactNative that renders the 2 componentes relateds. Also, we put to a HashMap, using the message ID as index, the messages callbacks and keep it in memory
When ReactNative render the components, we send back the impressionDetected passing the message ID used to populate the HashMap.
With the message ID we recovery the message callbacks from HashMap and call impressionDetected
But when we call twice or more times makrImpressionDetected for differents messages in a short time only one message are marked as read
Thanks for the explaining, @igorjacauna. I was able to reproduce the same behavior. I'll notify an engineer and see what we can do here.
Hi @igorjacauna ,
Could you please confirm how you are checking make sure all impression detected calls are getting fired and marked as read? Is it based on some callbacks?
Also could you please try calling the impressiondetected calls with a delay (may be 5 seconds between each call?)
Hi @eldhosembabu,
To check if impression detected is called and marked as read we follow the ADB logcat by using adb logcat | grep "FIAM", it shows logs from Firebase when a message already impressed or not and in our custom FirebaseInAppMessagingDisplay class implementation we put some logs to known if impressionDetected been called correctly and compare with logs from FIAM.
We create a delay with 5 seconds and the problem persists. We follow this steps:
- Open the app
- Call for two messages: Message A bind to event
event_aand Message B bind toevent_b. We call the messages with firing the events:
FirebaseInAppMessaging.getInstance().triggerEvent("event_a");
FirebaseInAppMessaging.getInstance().triggerEvent("event_b");
- On
adb logcat | grep "FIAM"shows:
FIAM.Headless: Already impressed campaign Message A ? : false
FIAM.Headless: Already impressed campaign Message B ? : false
- We display the two messages on two differents components on screen
- When the messages are displayed, we call
impressionDetectedfor Message A - Our logs shows
impressionDetectedcalled without errors - Delay 5 seconds for call
impressionDetectedfor Message B - Our logs shows
impressionDetectedcalled without errors - We close the app
- We open the app again
- We fire again the two events,
event_aandevent_b - On
adb logcat | grep "FIAM"shows:
FIAM.Headless: Already impressed campaign Message A ? : true
FIAM.Headless: Already impressed campaign Message B ? : false
- Once the Message B is marked as not impressed it shows up again, but before when we call
impressionDetectedfor it, no error occurred - We display the Message B
- Call
impressionDetectedfor Message B - Our logs shows
impressionDetectedcalled without errors - Close the app
- Reopen the app
- Fire
event_aandevent_b - On
adb logcat | grep "FIAM"shows:
FIAM.Headless: Already impressed campaign Message A ? : true
FIAM.Headless: Already impressed campaign Message B ? : true
Hope this help.
Could you please provide a sample app where I can try reproducing the issue?
Hi @eldhosembabu, I created this repo: https://github.com/igorjacauna/android-firebase-sdk-issue
Hi @igorjacauna ,
Could you please try to reproduce this issue in our Quick Start App? I was not able to get the above repo code working since I'm not familiar with the react code.
The possible reason for this issue is this wasImpressed flag which is static. But i need to reproduce the issue on quick start to provide a fix.
Hi all, seems to me that the fix for this has been merged. That said, I'll close this issue now. Feel free to reopen if the issue is still present.