Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InApp Messaging won't show message on custom event

using

implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.2'

I get the message when using the "Test on device" feature in Firebase I also get message when using the event "on_foreground" but I want to show a message not directly on app start, but when entering a new screen (when I send the event "Show_Category_Screen")

like this

FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(activity);
mFirebaseAnalytics.logEvent("Show_Category_Screen", null);

And I set the InApp Message trigger event to "Show_Category_Screen". But nothing happens

The event successfully shows up in the DebugView in Firebase

I see this in the log

I/FIAM.Headless: Successfully fetched 2 messages from backend
I/FIAM.Headless: Removing display event listener
I/FIAM.Headless: Already impressed InAppCategoryMessage ? : false

I have the same problem in my iOS app. Is it possible to do this?

like image 972
Christoffer Avatar asked Nov 14 '19 13:11

Christoffer


1 Answers

I started playing with in app messaging today and this took some figuring out using the famous trial and error technique.

There are two ways for triggering events:

FirebaseAnalytics.getInstance(this).logEvent("main_screen_opened", null);

and

FirebaseInAppMessaging.getInstance().triggerEvent("main_screen_opened");

I've published a campaign with the trigger main_screen_opened, as you cannot do this while testing, test messages are show on app open:

Test on device screenshot

Now, make sure you call triggerEvent() or logEvent() in the onResume() of the activity, it won't work if you do it on the OnCreate()!

@Override
protected void onResume() {
    super.onResume();

    FirebaseAnalytics.getInstance(this).logEvent("main_screen_opened", null);
    FirebaseInAppMessaging.getInstance().triggerEvent("main_screen_opened");
    ...
}

NOTE:* it will (probably?) not trigger the first time, to not bug the user right away. When you go to the home screen and go back into the app, it should show up now.

Edit: After some testing a bit more, it is ok if you put it in the onCreate(). When you check your logging, you'll see

Already impressed <your campaign name> ? : false

The second time you execute the logEvent() / Trigger(), the popup will show up

like image 178
Boy Avatar answered Oct 12 '22 20:10

Boy