ابرووا
شروع رایگان
☰ فهرست مستندات · آمار SDK
به‌زودی. Abrova Push به‌زودی فعال می‌شود. این صفحه توضیح می‌دهد چطور کار خواهد کرد؛ هنوز قابل استفاده نیست.
این صفحه هنوز ترجمه نشده — نسخه‌ی انگلیسی نمایش داده می‌شود. English

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

dart
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

dart
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.

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

kotlin
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

kotlin
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

kotlin
// Disable analytics tracking
AbrovaPush.disableAnalytics()

// Check if analytics is enabled
val isEnabled = AbrovaPush.isAnalyticsEnabled()

iOS (Swift)#

Analytics Handler Not Available on iOS.

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.

swift
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 = forwarder

React Native#

Analytics Handler Not Available in React 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

typescript
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

typescript
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

typescript
// 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).

EventDescriptionProperties
SDK_INITIALIZEDSDK was initialized-
DEVICE_REGISTEREDDevice registered successfullydeviceId, userId
DEVICE_UNREGISTEREDDevice was unregistereddeviceId
MESSAGE_RECEIVEDPush message receivedmessageId, title, silent, hasImage
MESSAGE_DISPLAYEDNotification was shown to usermessageId, title
NOTIFICATION_CLICKEDUser tapped notificationmessageId, title, action
ACTION_CLICKEDUser tapped action buttonactionId, messageId
CONNECTEDConnected successfully-
DISCONNECTEDDisconnected-
CONNECTION_ERRORConnection error occurrederrorCode, errorMessage, details
RETRY_STARTEDReconnection attempt startedretryAttempt, nextRetryMs
TOPIC_SUBSCRIBEDSubscribed to topictopic
TOPIC_UNSUBSCRIBEDUnsubscribed from topictopic
NETWORK_STATE_CHANGEDNetwork state changedisAvailable, networkType
APP_STATE_CHANGEDApp visibility changedisVisible, visibilityState
PERMISSION_REQUESTEDPermission prompt shown-
PERMISSION_GRANTEDUser granted permission-
PERMISSION_DENIEDUser denied permission-

Integration Examples#

Google Analytics 4

typescript
abrovaPush.setAnalyticsHandler((event, properties) => {
  gtag('event', `abrovaPush_${event}`, {
    ...properties,
    send_to: 'GA_MEASUREMENT_ID',
  });
});

Mixpanel

typescript
abrovaPush.setAnalyticsHandler((event, properties) => {
  mixpanel.track(`AbrovaPush: ${event}`, properties);
});

Amplitude

typescript
abrovaPush.setAnalyticsHandler((event, properties) => {
  amplitude.track(`abrovaPush_${event}`, properties);
});
این صفحه مفید بود؟
گزارش مشکل