Blog

Analyse Using Notification Events

Let’s say you’re using Google Analytics in your app and want to see how your userbase is using your product. What if you would like to analyse if users opened certain notifications or not. Or if you want to verify if users actually received your notifications. How can you combine your analytics with the Plot plugin? In our recent plugin release you can! You can now analyse using notification events, yeah these are new.

These events get sent out by our plugin whenever a notification is shown to the user of the device or whenever they tap on the notification. You only have to tie these events to either an analytics service you’re already using, like Google Analytics, or your own custom solution.

iOS

For iOS you can implement two optional methods, one for each kind of event (notification sent, notification opened). These methods will get called by the Plot plugin whenever such an event happens. For instance, let’s say you want to log the notification sent event to your Google analytics, so you know when or what kind of users have received a notification. An implementation would look something like this:

-(void)plotNotificationSentEvent:(PlotSentNotification*)notification {
  NSString* message = [notification.userInfo objectForKey:PlotNotificationMessage];
  NSLog(@"Notification Sent Event: message: %@", message);
  // Make a call to Google Analytics
  [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Notification"
                                                      action:@"Sent"
                                                       label:message
                                                       value:@1] build]];
}

You can of course replace the call to Google Analytics with a different service, or your own custom statistics solution.

Android

For Android an example implementation for tracking tapped (opened) notifications would look like this:

public class MyNotificationEventReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        SentNotification notification = intent.getParcelableExtra("notification");
        if (intent.getAction().endsWith(".plot.OpenedNotification")) {
          String format = "Message of the sent notification: %s";
          Log.i(TAG, String.format(format, notification.getMessage()));
          // Make a call to Google Analytics
          tracker.send(new HitBuilders.EventBuilder()
   		 .setCategory("Notification")
  		  .setAction("Opened")
  		  .setLabel(notification.getMessage())
   		 .setValue(1)
   	 .build());
        }
    }
}

Easy peasy! Don’t forget to register the broadcast receiver in your AndroidManifest, together with an intent-filter on the open and sent events:

<receiver android:exported="false" android:name="[[Application Package]].MyNotificationEventReceiver">
    <intent-filter>
        <action android:name="[[Application Package]].plot.SentNotification" />
        <action android:name="[[Application Package]].plot.OpenedNotification" />
    </intent-filter>
</receiver>

Geotriggers

In addition to analysing notifications; if you’re using geotriggers and also would like to add these events to your own analytics, you can implement the geotrigger handler. More about this is described in a previous blog post.

More information

For full details on this feature check out the documentation page, or the specific paragraphs for iOS and Android.

Spread the love