5

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?

Christoffer
  • 81
  • 1
  • 5

2 Answers2

7

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

Boy
  • 7,010
  • 4
  • 54
  • 68
  • 2
    doesn't work for me either, I tried everything, but the message is still showing on splash screen even when the only event is "main_activity" which I log and trigger only in onresume of mainactivity – TootsieRockNRoll Mar 23 '20 at 17:31
  • @ElJazouli that is weird. Are you sure you are not sending a test message and using a real published message? – Boy Mar 24 '20 at 08:29
  • what do you mean? I'm using "test on device", is that different than a real published message? – TootsieRockNRoll Apr 03 '20 at 10:39
  • 4
    @ElJazouli please check my post and the image I added: when using `test on device`, the message is only triggered on app-open. It does not work on triggers and will therefore only show on the splashactivity – Boy Apr 03 '20 at 14:11
  • Thank you so much that explains everything, I just got an answer from a firebase team member about the issue and he said the same thing. – TootsieRockNRoll Apr 07 '20 at 00:05
  • For anyone still having issues in 2023, the only way for this custom events to work is to use FirebaseInAppMessaging.getInstance().triggerEvent() method, NOT FirebaseAnalytics.getInstance(this).logEvent() because for some reason, InAppMessaging Firebase backend isn't recognizing that custom event. – Beemo May 12 '23 at 08:42
0

Add following lines in app build.gradle file :

// in app messaging
implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.3'
implementation 'com.google.firebase:firebase-analytics:17.2.2

Add below lines in your starting activity in onCreate()

FirebaseDatabase.getInstance().setPersistenceEnabled(false);
FirebaseInAppMessaging.getInstance().setAutomaticDataCollectionEnabled(true);

I resolved same issue using above steps.

Crisic
  • 1,181
  • 1
  • 9
  • 27
  • While this code snippet may be the solution, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – f.khantsis Apr 02 '20 at 10:40