Messaging
This section contains documentation related to push notifications and in-app messages.
Firebase Implementation
- To begin, download the
google-services.jsonfile from the Firebase console and place it in your project.
app/ directory of your Android project-
Then, you need to enter the Push Credentials or the
service-account.jsonfile of the Firebase project in the Metrix panel. -
Update the
build.gradlefile:
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
- Add the Metrix library dependency to the
dependenciessection of your application’sbuild.gradlefile:
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.
- Place the following value in your application’s
AndroidManifest.xmlfile:
<service
android:name="ir.metrix.notification.receivers.MetrixFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>- Set the
customUserIdwhen 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:
- Set the value of
metrix_auto_load_in_app_messagesin your application’sAndroidManifest.xmlfile:
<manifest>
...
<application>
...
<meta-data
android:name="metrix_auto_load_in_app_messages"
android:value="false" />
</application>
</manifest>- Then, call the following method in the desired location:
MetrixNotification.loadInAppMessages();