braze-inc / braze-flutter-sdk

Public repo for the Braze Flutter SDK
Other
15 stars 29 forks source link

[Help Needed] In App Messages not showing #30

Closed julianfalcionelli closed 1 year ago

julianfalcionelli commented 1 year ago

Hi guys,

We have already implemented Push Notifications with Braze, they are working fine (we did it though Segment Cloud Mode integration with Braze), but we are not being able to make the In-App messages work (for now we are just trying this only on Android).

Here is the Flutter + Android implementation:

Flutter Activity ``` class MainActivity : FlutterActivity() { override fun configureFlutterEngine(flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine) flutterEngine.getPlugins().add(SharedPreferencesPlugin()) } override fun attachBaseContext(base: Context) { super.attachBaseContext(base) MultiDex.install(this) } public override fun onResume() { super.onResume() // Registers the BrazeInAppMessageManager for the current Activity. This Activity will now listen for // in-app messages from Braze. BrazeInAppMessageManager.getInstance().registerInAppMessageManager(this) } } ```
Application Class ``` class CustomApplication : FlutterApplication() { override fun onCreate() { super.onCreate() registerActivityLifecycleCallbacks( BrazeActivityLifecycleCallbackListener( sessionHandlingEnabled = true, registerInAppMessageManager = true ) ) BrazeInAppMessageManager.getInstance().ensureSubscribedToInAppMessageEvents(applicationContext) } } ```
Custom Messaging Service Class ``` @SuppressLint("MissingFirebaseInstanceTokenRefresh") class MyFirebaseMessagingService : FirebaseMessagingService() { override fun onMessageReceived(remoteMessage: RemoteMessage) { if (BrazeFirebaseMessagingService.isBrazePushNotification(remoteMessage)) { Log.d("MessagingService", "Braze Push Notification"); BrazeFirebaseMessagingService.handleBrazeRemoteMessage(this, remoteMessage) } else { Log.d("MessagingService", "New Push Notification"); super.onMessageReceived(remoteMessage) } } } ```

However, we can see in the logs that the Push Notification (about In App Message) arrives but is not rendered at all:

I: Got remote message from FCM: {a=Tap to see Test In-App Message, p=0, t=Braze Test Send, _ab=true, cid=dGVzdF90ZXN0X2RpPTYzNzNkYTYwMTk1ODZiMTQwYWQxOTZkMWVjYmE5YjQ0, ab_nc=default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key=true}
I: Push message payload received: Bundle[{a=Tap to see Test In-App Message, p=0, t=Braze Test Send, _ab=true, cid=dGVzdF90ZXN0X2RpPTYzNzNkYTYwMTk1ODZiMTQwYWQxOTZkMWVjYmE5YjQ0, ab_nc=default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key=true}]

I am using the latest Braze SDKs (For Flutter and Android) on the latest Flutter version (3.7.+)

radixdev commented 1 year ago

Hello @julianfalcionelli ,

By default, push notification test sends of In-App messages will try to render automatically and not show the "click this In-App Message" push.

  1. Can you enable and provide verbose logs of before and after that push notification is received? Those verbose logs will state why the message didn't render.
  2. Do In-App Messages render if triggered (e.g. by a custom event) in the app?

Thanks, Julian

julianfalcionelli commented 1 year ago

Hi @radixdev, thanks for the reply.

  1. Braze-Related logs:

Before Push Notification:

I: Automatic Firebase Cloud Messaging registration not enabled in configuration. Braze will not register for Firebase Cloud Messaging.
I: Automatic ADM registration not enabled in configuration. Braze will not register for ADM.
I: Running Flutter BrazePlugin automatic initialization
W: Attempted to register plugin (com.braze.brazeplugin.BrazePlugin@e3d4ae2) but it was already registered with this FlutterEngine (io.flutter.embedding.engine.FlutterEngine@8c52571).
I: Event was published, but no subscribers were found. Saving event for later publishing to a matching subscriber. Event class: class com.braze.events.SessionStateChangedEvent
I: Event was published, but no subscribers were found. Saving event for later publishing to a matching subscriber. Event class: class com.braze.events.SessionStateChangedEvent
I: Requesting immediate data flush to Braze.
I: Event was published, but no subscribers were found. But not saving event for publishing later. Event class: class com.braze.events.NoMatchingTriggerEvent
I: Braze content cards response is empty. Doing nothing.

After Push Notification:

V: scheduleReceiver info = ActivityInfo{fefbaa8 com.google.firebase.iid.FirebaseInstanceIdReceiver} intent = Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1080010 pkg=co.mindset cmp=co.mindset/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) } sync = true hasCode = 186373771
D: Braze Push Notification
I: Got remote message from FCM: {a=Tap to see Test In-App Message, p=0, t=Braze Test Send, _ab=true, cid=dGVzdF90ZXN0X2RpPTYzNzNmNWMzZWZkZjI3Nzg0Mzk3NzM5NmY1N2NjYmNh, ab_nc=default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key=true}
I: Received broadcast message. Message: Intent { act=firebase_messaging_service_routing_action (has extras) }
I: Push message payload received: Bundle[{a=Tap to see Test In-App Message, p=0, t=Braze Test Send, _ab=true, cid=dGVzdF90ZXN0X2RpPTYzNzNmNWMzZWZkZjI3Nzg0Mzk3NzM5NmY1N2NjYmNh, ab_nc=default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key=true}]
I: Push contained key for fetching test triggers, fetching triggers.
V: scheduleReceiver info = ActivityInfo{2d9d954 io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingReceiver} intent = Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1080010 pkg=co.mindset cmp=co.mindset/io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingReceiver (has extras) } sync = true hasCode = 66015335
D: broadcast received for message
I: 2022-11-15T21:25:39.631082   D   LogHelper.d:     [NotificationsManager] New Foreground Message Instance of 'RemoteMessage'
I: 2022-11-15T21:25:39.632679   D   LogHelper.d:     [NotificationsManager] renderNotification {p: 0, a: Tap to see Test In-App Message, _ab: true, t: Braze Test Send, ab_nc: default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key: true, cid: dGVzdF90ZXN0X2RpPTYzNzNmNWMzZWZkZjI3Nzg0Mzk3NzM5NmY1N2NjYmNh}
I: 
  1. We only tested the "Test" option from the Campaign Creator, should we test running the Campaign with a Custom Event?
radixdev commented 1 year ago
  1. Can you add <integer name="com_braze_logger_initial_log_level">0</integer> to your braze.xml to enable verbose logs? Those logs are still only info level and above. Sorry for providing instructions on how to enable verbose logs. And feel free to just dump the entire file/logs here so we can sift through them.
  2. Yes, that would work. Or a session start triggered message.
julianfalcionelli commented 1 year ago

Hi @radixdev

Here are the logs with that config:

D: Using resources value for key: 'com_braze_custom_endpoint' and value: 'sdk.iad-05.braze.com'
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_firebase_cloud_messaging_registration_enabled'.Using default value 'false'.
D: Using resources value for key: 'com_braze_firebase_cloud_messaging_registration_enabled' and value: 'false'
I: Automatic Firebase Cloud Messaging registration not enabled in configuration. Braze will not register for Firebase Cloud Messaging.
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_push_adm_messaging_registration_enabled'.Using default value 'false'.
D: Using resources value for key: 'com_braze_push_adm_messaging_registration_enabled' and value: 'false'
I: Automatic ADM registration not enabled in configuration. Braze will not register for ADM.
D: Unable to find the xml INTEGER configuration value with primary key 'com_braze_session_timeout'.Using default value '10'.
D: Using resources value for key: 'com_braze_session_timeout' and value: '10'
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_session_start_based_timeout_enabled'.Using default value 'false'.
D: Using resources value for key: 'com_braze_session_start_based_timeout_enabled' and value: 'false'
D: Unable to find the xml INTEGER configuration value with primary key 'com_braze_trigger_action_minimum_time_interval_seconds'.Using default value '30'.
D: Using resources value for key: 'com_braze_trigger_action_minimum_time_interval_seconds' and value: '30'
D: Braze geofences not enabled. Geofences not set up.
D: Unable to find the xml STRING_ARRAY configuration value with primary key 'com_braze_custom_location_providers_list'.Using default value '[]'.
D: Using resources value for key: 'com_braze_custom_location_providers_list' and value: '[]'
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_flutter_enable_automatic_integration_initializer'.Using default value 'true'.
D: Using resources value for key: 'com_braze_flutter_enable_automatic_integration_initializer' and value: 'true'
I: Running Flutter BrazePlugin automatic initialization
V: BrazeActivityLifecycleCallbackListener using in-app messaging blocklist: []
V: BrazeActivityLifecycleCallbackListener using session handling blocklist: []
D: Unable to find the xml STRING configuration value with primary key 'com_braze_flutter_automatic_integration_iam_operation'.Using default value ''.
D: Using resources value for key: 'com_braze_flutter_automatic_integration_iam_operation' and value: ''
D: com.braze.events.ContentCardsUpdatedEvent fired: ContentCardsUpdatedEvent{userId='', timestampSeconds=1668546645, isFromOfflineStorage=true, card count=0}
D: Triggering com.braze.events.ContentCardsUpdatedEvent on 1 subscribers.
W: Attempted to register plugin (com.braze.brazeplugin.BrazePlugin@b3b2db) but it was already registered with this FlutterEngine (io.flutter.embedding.engine.FlutterEngine@c1ec3de).
D: bo.app.o0 fired: commandType = ADD_BRAZE_EVENT
    brazeEvent = {"name":"ss","data":{},"time":1.668604524399E9,"session_id":"dc2aae97-668f-42cc-b87c-8a952f589557"}
    sessionId = null
    brazeRequest = null
D: bo.app.o0 fired: commandType = FLUSH_PENDING_BRAZE_EVENTS
    brazeEvent = null
    sessionId = dc2aae97-668f-42cc-b87c-8a952f589557
    brazeRequest = null
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_enable_location_collection'.Using default value 'false'.
D: Using resources value for key: 'com_braze_enable_location_collection' and value: 'false'
D: Unable to find the xml STRING configuration value with primary key 'com_braze_server_target'.Using default value 'PROD'.
D: Using resources value for key: 'com_braze_server_target' and value: 'PROD'
D: bo.app.o0 fired:             commandType = ADD_REQUEST
                brazeEvent = null
                sessionId = null
                brazeRequest = {
      "respond_with": {
        "triggers": true,
        "config": {
          "config_time": 1662753925
        }
      }
    }
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_automatic_geofence_requests_enabled'.Using default value 'true'.
D: Using resources value for key: 'com_braze_automatic_geofence_requests_enabled' and value: 'true'
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_sdk_authentication_enabled'.Using default value 'false'.
D: Using resources value for key: 'com_braze_sdk_authentication_enabled' and value: 'false'
D: Using resources value for key: 'com_braze_sdk_flavor' and value: 'FLUTTER'
D: bo.app.o0 fired:             commandType = ADD_REQUEST
                brazeEvent = null
                sessionId = null
                brazeRequest = {
      "last_full_sync_at": 0,
      "last_card_updated_at": 0
    }
D: com.braze.events.SessionStateChangedEvent fired: SessionStateChangedEvent{sessionId='dc2aae97-668f-42cc-b87c-8a952f589557', eventType='SESSION_STARTED'}'
I: Event was published, but no subscribers were found. Saving event for later publishing to a matching subscriber. Event class: class com.braze.events.SessionStateChangedEvent
D: Unable to find the xml INTEGER configuration value with primary key 'com_braze_data_flush_interval_great_network'.Using default value '10'.
D: Using resources value for key: 'com_braze_data_flush_interval_great_network' and value: '10'
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_device_object_whitelisting_enabled'.Using default value 'false'.
D: Using resources value for key: 'com_braze_device_object_whitelisting_enabled' and value: 'false'
D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_device_object_whitelisting_enabled'.Using default value 'false'.
D: Using resources value for key: 'com_braze_device_object_whitelisting_enabled' and value: 'false'
D: Using resources value for key: 'com_braze_internal_sdk_metadata' and value: '[FLUTTER]'
D: Unable to find the xml STRING_ARRAY configuration value with primary key 'com_braze_sdk_metadata'.Using default value '[]'.
D: Using resources value for key: 'com_braze_sdk_metadata' and value: '[]'
D: Using runtime override value for key: 'com_braze_sdk_metadata' and value: '[]'
D: bo.app.o0 fired:             commandType = ADD_REQUEST
                brazeEvent = null
                sessionId = null
                brazeRequest = {
      "respond_with": {
        "triggers": true
      }
    }
D: Making request with id => "6b6b929057f71eae"
    to url: https://sdk.iad-05.braze.com/api/v3/content_cards/sync

    with headers:
    "BRAZE-SYNC-RETRY-COUNT" => "0"
    "X-Braze-ContentCardsRequest" => "true"
    "X-Braze-DataRequest" => "true"
    "Accept-Encoding" => "gzip, deflate"
    "Content-Type" => "application/json"
    "X-Braze-Api-Key" => "12345678"

    and JSON :
    {
      "device_id": "12345678",
      "time": 1668604524,
      "api_key": "12345678",
      "sdk_version": "23.3.0",
      "last_full_sync_at": 0,
      "last_card_updated_at": 0
    }
D: Making request with id => "407b878d847a0402"
    to url: https://sdk.iad-05.braze.com/api/v3/data

    with headers:
    "X-Braze-TriggersRequest" => "true"
    "X-Braze-DataRequest" => "true"
    "Accept-Encoding" => "gzip, deflate"
    "Content-Type" => "application/json"
    "X-Braze-Api-Key" => "12345678"

    and JSON :
    {
      "device_id": "12345678",
      "time": 1668604524,
      "api_key": "12345678",
      "sdk_version": "23.3.0",
      "app_version": "0.0.1",
      "app_version_code": "1.0.0.0",
      "sdk_flavor": "flutter",
      "respond_with": {
        "triggers": true
      }
    }
D: Braze geofences not enabled. Not requesting geofences.
D: Making request with id => "a159f915cfdef35c"
    to url: https://sdk.iad-05.braze.com/api/v3/data

    with headers:
    "X-Braze-TriggersRequest" => "true"
    "X-Braze-DataRequest" => "true"
    "Accept-Encoding" => "gzip, deflate"
    "Content-Type" => "application/json"
    "X-Braze-Api-Key" => "12345678"

    and JSON :
    {
      "device_id": "12345678",
      "time": 1668604524,
      "api_key": "12345678",
      "sdk_version": "23.3.0",
      "app_version": "0.0.1",
      "app_version_code": "1.0.0.0",
      "device": {
        "os_version": "31",
        "carrier": "O2",
        "model": "HD1913",
        "resolution": "1440x3120",
        "locale": "en_US",
        "remote_notification_enabled": true,
        "android_is_background_restricted": false,
        "time_zone": "Europe\/Madrid"
      },
      "events": [
        {
          "name": "ss",
          "data": {},
          "time": 1.668604524399E9,
          "session_id": "dc2aae97-668f-42cc-b87c-8a952f589557"
        }
      ],
      "sdk_flavor": "flutter",
      "respond_with": {
        "triggers": true,
        "config": {
          "config_time": 1662753925
        }
      }
    }
D: com.braze.events.ContentCardsUpdatedEvent fired: ContentCardsUpdatedEvent{userId='', timestampSeconds=1668604524, isFromOfflineStorage=false, card count=0}
D: Triggering com.braze.events.ContentCardsUpdatedEvent on 1 subscribers.
D: com.braze.events.NoMatchingTriggerEvent fired: NoMatchingTriggerEvent(sourceEventType=open)
I: Event was published, but no subscribers were found. But not saving event for publishing later. Event class: class com.braze.events.NoMatchingTriggerEvent
I: Braze content cards response is empty. Doing nothing.
I: Requesting immediate data flush to Braze.
D: bo.app.o0 fired:             commandType = ADD_REQUEST
                brazeEvent = null
                sessionId = null
                brazeRequest = {
      "respond_with": {
        "config": {
          "config_time": 1662753925
        }
      }
    }

I: Requesting immediate data flush to Braze. D: bo.app.o0 fired: commandType = ADD_REQUEST brazeEvent = null sessionId = null brazeRequest = { "respond_with": { "config": { "config_time": 1662753925 } } } D: Braze Push Notification I: Got remote message from FCM: {a=Tap to see Test In-App Message, p=0, t=Braze Test Send, _ab=true, cid=dGVzdF90ZXN0X2RpPTYzNzRlMmYyNWRmMmFkOThlM2Y3MmRiNDZmMDI3YzJm, ab_nc=default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key=true} V: Adding bundle item from FCM remote data with key: t and value: Braze Test Send I: Push message payload received: Bundle[{a=Tap to see Test In-App Message, p=0, t=Braze Test Send, _ab=true, cid=dGVzdF90ZXN0X2RpPTYzNzRlMmYyNWRmMmFkOThlM2Y3MmRiNDZmMDI3YzJm, ab_nc=default_channel_id_in_app_notification, ab_push_fetch_test_triggers_key=true}] D: Unable to find the xml BOOLEAN configuration value with primary key 'com_braze_in_app_message_push_test_eager_display_enabled'.Using default value 'true'. D: Using resources value for key: 'com_braze_in_app_message_push_test_eager_display_enabled' and value: 'true' D: bo.app.o0 fired: commandType = ADD_REQUEST brazeEvent = null sessionId = null brazeRequest = { "respond_with": { "triggers": true, "config": { "config_time": 1662753925 } } } D: Making request with id => "9017c505df0da022" to url: https://sdk.iad-05.braze.com/api/v3/data

with headers:
"X-Braze-TriggersRequest" => "true"
"X-Braze-DataRequest" => "true"
"Accept-Encoding" => "gzip, deflate"
"Content-Type" => "application/json"
"X-Braze-Api-Key" => "12345678"

and JSON :
{
  "device_id": "12345678",
  "time": 1668604658,
  "api_key": "12345678",
  "sdk_version": "23.3.0",
  "app_version": "0.0.1",
  "app_version_code": "1.0.0.0",
  "sdk_flavor": "flutter",
  "respond_with": {
    "triggers": true,
    "config": {
      "config_time": 1662753925
    }
  }
}

I: Requesting immediate data flush to Braze. D: bo.app.o0 fired: commandType = ADD_REQUEST brazeEvent = null sessionId = null brazeRequest = { "respond_with": { "config": { "config_time": 1662753925 } } }



I changed any Keys in the logs for "12345678"

2- I am trying running the Campaign, will let u know any updates on that. 
julianfalcionelli commented 1 year ago

We are having trouble running the In-App Messages Campaign, they are not being triggered... We don't know why, others Campaigns (like Push Notifications) works with the exact settings.

Screen Shot 2022-11-16 at 16 09 37

I already send that to the Customer Support team.

julianfalcionelli commented 1 year ago

Hi @radixdev, any news on this? Do I have anything else to check?

radixdev commented 1 year ago

Sorry for the delay,

  1. Can you route this question fully through support@braze.com so we can obtain an APK to test with? We'd also need unfiltered logcat output to better diagnose things and a public github issue might not be the best place to put those.
  2. From the logs, there are no calls from the BrazeInAppMessageManger, which implies that it is not being registered properly. This is weird since there are several correct looking calls to BrazeInAppMessageManager in your code.
  3. Could you remove your calls to BrazeInAppMessageManager and try to reproduce? The flutter android plugin itself makes those calls itself and there could be some interference (https://github.com/braze-inc/braze-flutter-sdk/blob/master/android/src/main/kotlin/com/braze/brazeplugin/IntegrationInitializer.kt). You could also try setting com_braze_flutter_enable_automatic_integration_initializer boolean to false in your braze.xml to disable the automatic initializer.
julianfalcionelli commented 1 year ago

@radixdev sure, I will provide an apk to the support team.

As I mentioned before, we are registering the device (the push notification token) through Segment Integration (from Cloud mode, via custom mappings), and the Push Notifications work as expected (they arrive and render successfully) but for the In-App Messaging I can see that the Push notifications arrive when trying the "test" opt from the Braze Campaign Creator but nothing is rendered in that case.

julianfalcionelli commented 1 year ago

@radixdev I get the "Test" opt working, looks like is required for Braze In-App messaging to have the User Session data, and is not enough our integration with Segment, so basically I made the changeUser call from Flutter and after the Session Data started showing I was able to trigger the In-App Messages. Is weird that this is required for In-App messages and not for Push Notifications 🤔 .

julianfalcionelli commented 1 year ago

I am going to close this issue, as a conclusion is that the Flutter SDK has to be used for In-App Messages to work, it is not enough with only the Native SDKs. It still seems strange to me that this is necessary, since Push Notifications work correctly without the need for the Flutter SDK.

Thanks for the support @radixdev .