SDK Analytics Handler
Track SDK events (message received, notification clicked, connected, errors, permission events) with a custom analytics handler — forward to Firebase, GA4, Mixpanel, Amplitude.
Track SDK events with custom analytics handlers to integrate with your analytics service.
Flutter#
Setting Up Analytics
AbrovaPush.setAnalyticsHandler((event, properties) {
print('Event: $event');
print('Properties: $properties');
// Send to your analytics service
FirebaseAnalytics.instance.logEvent(
name: 'abrovaPush_${event.name}',
parameters: properties?.map((k, v) => MapEntry(k, v.toString())),
);
});Handling Specific Events
AbrovaPush.setAnalyticsHandler((event, properties) {
switch (event) {
case AbrovaPushAnalyticsEvent.messageReceived:
// Track message received
analytics.track('push_received', properties);
break;
case AbrovaPushAnalyticsEvent.connected:
// Track successful connection
analytics.track('push_connected');
break;
case AbrovaPushAnalyticsEvent.connectionError:
// Track connection failures
FirebaseCrashlytics.instance.recordError(
Exception('Push connection error'),
null,
reason: properties?['error_code']?.toString() ?? properties?['error'],
);
break;
default:
break;
}
});The Flutter SDK's AbrovaPushAnalyticsEvent is a Dart enum with its own set of values: sdkInitialized, deviceRegistered, deviceUnregistered, messageReceived, messageDisplayed, connected, disconnected, connectionError, retryStarted, topicSubscribed, topicUnsubscribed, networkStateChanged, appStateChanged, appUpdated, the in-app events (inAppMessageDisplayed, inAppButtonClicked, inAppMessageDismissed, inAppMessagesFetched), the inbox events (inboxMessagesFetched, inboxMessageRead, inboxMessageArchived, inboxMessageDeleted) and the A/B test events (abTestVariantAssigned, abTestImpression, abTestOpened, abTestClicked). It has no notification-clicked or permission events; use AbrovaPush.onNotificationTapped for taps. Property keys are snake_case (for example error_code, error_message). Use AbrovaPush.disableAnalytics() / AbrovaPush.enableAnalytics() and the AbrovaPush.isAnalyticsEnabled getter to toggle it.
Android (Kotlin)#
Not supported on Android. The native Android SDK has setAnalyticsHandler, enableAnalytics, disableAnalytics and isAnalyticsEnabled, but the handler below is never called. Forward the events you need from your AbrovaPushCallback (see Callbacks). The Flutter SDK's handler is not affected: it emits its events from Dart.
Setting Up Analytics
import ir.abrova.push.sdk.AbrovaPush
import ir.abrova.push.sdk.AbrovaPushAnalyticsCallback
import ir.abrova.push.sdk.AbrovaPushAnalyticsEvent
AbrovaPush.setAnalyticsHandler(AbrovaPushAnalyticsCallback { event, properties ->
Log.d("AbrovaPush", "Event: $event")
Log.d("AbrovaPush", "Properties: $properties")
// Send to your analytics service
val params = Bundle().apply {
properties.forEach { (k, v) -> putString(k, v?.toString()) }
}
FirebaseAnalytics.getInstance(context).logEvent("abrovaPush_$event", params)
})Handling Specific Events
AbrovaPush.setAnalyticsHandler(AbrovaPushAnalyticsCallback { event, properties ->
when (event) {
AbrovaPushAnalyticsEvent.MESSAGE_RECEIVED -> {
// Track message received
analytics.track("push_received", properties)
}
AbrovaPushAnalyticsEvent.NOTIFICATION_CLICKED -> {
// Track notification tap
analytics.track("push_clicked", properties)
}
AbrovaPushAnalyticsEvent.CONNECTED -> {
// Track successful connection
analytics.track("push_connected")
}
AbrovaPushAnalyticsEvent.CONNECTION_ERROR -> {
// Track connection failures
FirebaseCrashlytics.getInstance().recordException(
Exception("Push connection error: ${properties["errorCode"]}")
)
}
else -> { /* ignore */ }
}
})Disable Analytics
// Disable analytics tracking AbrovaPush.disableAnalytics() // Check if analytics is enabled val isEnabled = AbrovaPush.isAnalyticsEnabled()
iOS (Swift)#
The iOS SDK does not currently expose setAnalyticsHandler. To collect SDK telemetry on iOS, conform to AbrovaPushDelegate and forward the events you care about — didReceiveMessage, didChangeConnectionState, didFailWithDetailedError, didStartReconnecting, didTapNotification, didReceiveNotificationAction — to your analytics provider directly. See the Callbacks page for the full delegate surface.
import AbrovaPush
class PushAnalyticsForwarder: NSObject, AbrovaPushDelegate {
func abrovaPush(_ abrovaPush: AbrovaPush, didReceiveMessage message: AbrovaPushMessage) {
Analytics.logEvent("push_received", parameters: [
"messageId": message.messageId ?? "",
"title": message.title,
])
}
func abrovaPush(_ abrovaPush: AbrovaPush, didTapNotification message: AbrovaPushMessage) {
Analytics.logEvent("push_clicked", parameters: [
"messageId": message.messageId ?? "",
])
}
func abrovaPush(_ abrovaPush: AbrovaPush, didFailWithDetailedError error: AbrovaPushError) {
Analytics.logEvent("push_error", parameters: [
"errorCode": error.code,
"errorMessage": error.message,
])
}
func abrovaPush(_ abrovaPush: AbrovaPush, didChangeConnectionState connected: Bool) {
Analytics.logEvent(connected ? "push_connected" : "push_disconnected", parameters: nil)
}
}
// `delegate` is a weak reference: keep the forwarder alive yourself
let forwarder = PushAnalyticsForwarder()
AbrovaPush.shared.delegate = forwarderReact Native#
The React Native SDK (abrova-push-react-native) does not expose setAnalyticsHandler. Forward the events you need from its listeners (for example onMessage, onNotificationTapped, onConnectionState, onDetailedError) to your analytics provider directly.
Web#
Setting Up Analytics
import AbrovaPush, { AbrovaPushAnalyticsEvent } from '@abrova/push-web';
const abrovaPush = new AbrovaPush({
apiKey: 'ab_live_your_api_key',
});
// Set up analytics handler
abrovaPush.setAnalyticsHandler((event, properties) => {
console.log('Analytics:', event, properties);
// Send to your analytics service (Google Analytics, Mixpanel, etc.)
gtag('event', `abrovaPush_${event}`, properties);
});Handling Specific Events
abrovaPush.setAnalyticsHandler((event, properties) => {
switch (event) {
case AbrovaPushAnalyticsEvent.SDK_INITIALIZED:
// SDK was initialized
analytics.track('push_sdk_init', properties);
break;
case AbrovaPushAnalyticsEvent.DEVICE_REGISTERED:
// Device registered successfully
analytics.track('push_registered', {
deviceId: properties?.deviceId,
userId: properties?.userId,
});
break;
case AbrovaPushAnalyticsEvent.MESSAGE_RECEIVED:
// Push message received
analytics.track('push_received', {
messageId: properties?.messageId,
title: properties?.title,
silent: properties?.silent,
});
break;
case AbrovaPushAnalyticsEvent.MESSAGE_DISPLAYED:
// Notification was shown
analytics.track('push_displayed', properties);
break;
case AbrovaPushAnalyticsEvent.NOTIFICATION_CLICKED:
// User tapped notification
analytics.track('push_clicked', {
messageId: properties?.messageId,
action: properties?.action,
});
break;
case AbrovaPushAnalyticsEvent.ACTION_CLICKED:
// User tapped action button
analytics.track('push_action', {
actionId: properties?.actionId,
messageId: properties?.messageId,
});
break;
case AbrovaPushAnalyticsEvent.CONNECTED:
// Connected
analytics.track('push_connected');
break;
case AbrovaPushAnalyticsEvent.DISCONNECTED:
// Disconnected
analytics.track('push_disconnected');
break;
case AbrovaPushAnalyticsEvent.CONNECTION_ERROR:
// Connection error occurred
analytics.track('push_error', {
errorCode: properties?.errorCode,
errorMessage: properties?.errorMessage,
});
break;
case AbrovaPushAnalyticsEvent.RETRY_STARTED:
// Reconnection attempt
analytics.track('push_retry', {
attempt: properties?.retryAttempt,
});
break;
case AbrovaPushAnalyticsEvent.TOPIC_SUBSCRIBED:
// Topic subscribed
analytics.track('push_topic_sub', { topic: properties?.topic });
break;
case AbrovaPushAnalyticsEvent.PERMISSION_GRANTED:
// User granted notification permission
analytics.track('push_permission_granted');
break;
case AbrovaPushAnalyticsEvent.PERMISSION_DENIED:
// User denied permission
analytics.track('push_permission_denied');
break;
}
});Disable Analytics
// Disable analytics tracking abrovaPush.disableAnalytics(); // Check if analytics is enabled const isEnabled = abrovaPush.isAnalyticsEnabled();
Available Events#
These are the events of the Web SDK (AbrovaPushAnalyticsEvent.X, string values in camelCase). The Android enum has the same names, but analytics events are not supported on Android (see above). Property names below are those sent by the Web SDK. The Flutter event set differs (see above).
| Event | Description | Properties |
|---|---|---|
| SDK_INITIALIZED | SDK was initialized | - |
| DEVICE_REGISTERED | Device registered successfully | deviceId, userId |
| DEVICE_UNREGISTERED | Device was unregistered | deviceId |
| MESSAGE_RECEIVED | Push message received | messageId, title, silent, hasImage |
| MESSAGE_DISPLAYED | Notification was shown to user | messageId, title |
| NOTIFICATION_CLICKED | User tapped notification | messageId, title, action |
| ACTION_CLICKED | User tapped action button | actionId, messageId |
| CONNECTED | Connected successfully | - |
| DISCONNECTED | Disconnected | - |
| CONNECTION_ERROR | Connection error occurred | errorCode, errorMessage, details |
| RETRY_STARTED | Reconnection attempt started | retryAttempt, nextRetryMs |
| TOPIC_SUBSCRIBED | Subscribed to topic | topic |
| TOPIC_UNSUBSCRIBED | Unsubscribed from topic | topic |
| NETWORK_STATE_CHANGED | Network state changed | isAvailable, networkType |
| APP_STATE_CHANGED | App visibility changed | isVisible, visibilityState |
| PERMISSION_REQUESTED | Permission prompt shown | - |
| PERMISSION_GRANTED | User granted permission | - |
| PERMISSION_DENIED | User denied permission | - |
Integration Examples#
Google Analytics 4
abrovaPush.setAnalyticsHandler((event, properties) => {
gtag('event', `abrovaPush_${event}`, {
...properties,
send_to: 'GA_MEASUREMENT_ID',
});
});Mixpanel
abrovaPush.setAnalyticsHandler((event, properties) => {
mixpanel.track(`AbrovaPush: ${event}`, properties);
});Amplitude
abrovaPush.setAnalyticsHandler((event, properties) => {
amplitude.track(`abrovaPush_${event}`, properties);
});