Skip to Content
AI Powered Docs! 🤖 These docs are translated with AI, so keep an eye out for minor quirks. We're always improving!

Messaging

This section contains documentation related to push notifications and in-app messages.

Firebase Implementation

  1. To begin, download the google-services.json file from the Firebase console and place it in your project.
app/ directory of your Android project
  1. Then, you need to enter the Push Credentials or the service-account.json file of the Firebase project in the Metrix panel.

  2. Update the build.gradle file:

Project-level build.gradle file:

buildscript { dependencies { classpath 'com.google.gms:google-services:4.4.1' // Use latest version } }

Application-level build.gradle file:

plugins { id 'com.android.application' id 'com.google.gms.google-services' }

Note: If you want to have Firebase dependencies in your project, exclude the firebase-iid and firebase-messaging values. Example:

implementation platform('com.google.firebase:firebase-bom:30.4.1') { exclude group: 'com.google.firebase', module: 'firebase-messaging' exclude group: 'com.google.firebase', module: 'firebase-iid' }

Push Notification Service Implementation

  1. Add the Metrix library dependency to the dependencies section of your application’s build.gradle file:
implementation 'ir.metrix.notification:metrix:2.7.0'

Note: Currently, sending notifications via the API is only available for identified users in Metrix. For this, the user must have the customUserId attribute set.

  1. Place the following value in your application’s AndroidManifest.xml file:
<service android:name="ir.metrix.notification.receivers.MetrixFirebaseMessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
  1. Set the customUserId when the user logs in and remove it when they log out:
MetrixAnalytics.User.setUserCustomId("yourId")
MetrixAnalytics.User.deleteUserCustomId()

Implementing In-App Messages

By default, the application loads and displays messages every time it is opened.

To show messages on your desired screen:

  1. Set the value of metrix_auto_load_in_app_messages in your application’s AndroidManifest.xml file:
<manifest> ... <application> ... <meta-data android:name="metrix_auto_load_in_app_messages" android:value="false" /> </application> </manifest>
  1. Then, call the following method in the desired location:
MetrixNotification.loadInAppMessages();