# Push Notification Integration

In order to send notifications to your mobile users using Growlytics platform, you will need to add FCM messaging listeners to your apps.

### Step 1: Register FCM Messaging Service

Register an Growlytics' FCM messaging service in android manifest file as mentioned in example below. If you have already registered FCM messaging service, you can call Growlytics's `updateFCMToken()` and `updateFCMToken()` methods.

{% tabs %}
{% tab title="Growlytics FCM Service" %}
{% code title="AndroidManifest.xml" %}

```markup
// Skip adding this if you have already added in previous step
<service android:name="com.growlytics.android.sdk.FcmMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
```

{% endcode %}
{% endtab %}

{% tab title="If you have already implemented FCM Messaging Service " %}
{% code title="FcmMessagingService.java" %}

```java
@Override
public void onNewToken(String s) {
    super.onNewToken(s);
    
    // Call Growlytics's updateFCMToken() method
    com.growlytics.android.sdk.FcmMessagingService.updateFCMToken(
        token, 
        getApplicationContext()
    );

}

@Override
public void onMessageReceived(RemoteMessage message) {
    super.onMessageReceived(message);
    
    // Call Growlytics's updateFCMToken() method
    com.growlytics.android.sdk.FcmMessagingService.onMessageReceived(
        message, 
        getApplicationContext()
    );

}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Step 2: Register Broadcast Receiver

In order to receive notifications in background, add a receiver as mentioned in example below. If you have already registered FCM messaging service, you can call Growlytics's `onNotificationReceived()`method.

{% tabs %}
{% tab title="Add Growlytics Broadcast Receiver" %}
{% code title="AndroidManifest.xml" %}

```markup
<receiver 
    android:name="com.growlytics.android.sdk.GrwPushNotificationReceiver">
</receiver>
```

{% endcode %}
{% endtab %}

{% tab title="If you have already implemented Broadcast receiver" %}
{% code title="PushNotificationReceiver.java" %}

```java
public class GrwPushNotificationReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        
        // Call Growlytics's updateFCMToken() method
        com.growlytics.android.sdk.GrwPushNotificationReceiver.onReceive(
            context, 
            intent
        );
    }

}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Step 3: Configure FCM credentials

Visit Mobile [Push channel configuration page ](https://docs.growlytics.in/channels/mobile-push-notifications)for configuring FCM credentials.

### Additional Notes

Structure of the payload with a Growlytics FCM push notification.

| Key          | Data Type | Description                                                                                                                                      |
| ------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| glytcs\_pnf  | boolean   | If this field is present, means notification is received from Growlytics.                                                                        |
| glytcs\_id   | string    | Notification tracking id used by Growlytics.                                                                                                     |
| glytcs\_img  | string    | Url of an notification Image. If given, this URL will be used to show large image in notification.                                               |
| glytcs\_tl   | string    | Notification title, must be present or app name will be used as title.                                                                           |
| glytcs\_msg  | string    | Notification body, must be present, if not provided, notification will not be shown.                                                             |
| glytcs\_chnl | String    | Notification channel id, must be present and channel must be created by app, if given channel not registered, notification will not be rendered. |
| glytcs\_dl   | string    | If present, this is a deep link that must be followed at the time of notification open.                                                          |
| glytcs\_sbt  | string    | Notification sub-title, will be displayed next to app name in notification.                                                                      |
| glytcs\_clr  | string    | Color for small icon in notification. It Must be in hex or else color will be ignored.                                                           |
| glytcs\_pr   | string    | Priority for push notification \[Low, High, Max]                                                                                                 |
| glytcs\_dnr  | boolean   | If present, notification will not be shown, it will be ignore                                                                                    |
