React Native SDK: Tracking Events and Revenue

Singular React Native SDK 
Download
Singular React Native SDK version 1.1.1
Compatibility  React Native 0.46.4+
Integration Guides
  1. Basic Integration
  2. Tracking Events and Revenue
  3. Implementing Deep Links
  4. Adding SKAdNetwork Support
  5. Advanced Options

 

Tracking Events

Singular can collect data about in-app events to help analyze the performance of your campaigns and measure KPIs. For example, your organization may want to collect data about user logins, registrations, tutorial completions, or leveling up in a gaming app.

You can send events to Singular using the event and eventWithArgs methods.

Note:

  • We highly recommend passing event names and attributes in English to guarantee compatibility with third-party partners and analytics solutions if you plan to use them.
  • Event names are limited to 32 characters in ASCII. If you use non-ASCII characters, the limit is 32 bytes after the string is converted to UTF-8.
  • The names and values of additional attributes are limited to 500 ASCII characters.
Singular.event Method
Description Report a user event to Singular, passing the name of the event.
Usage Example
Singular.event(“Sign-up”);
Singular.eventWithArgs Method
Description Report a user event to Singular, passing the name of the event and any additional information you want to add, in the form of a map/object.
Usage Example
Singular.eventWithArgs('Level-Up', { level: '5', score: '130' });

Tracking Revenue

Singular can collect data about revenue gained through the app to help analyze the performance and ROI of your campaigns. Singular will make the data available to you in reports, log export, and postbacks.

When reporting revenue events to Singular, we recommend passing the purchase object as returned from Android's or iOS's In-App Purchase (IAP) process. This way, Singular gets all the details of the transaction, which enriches your Singular reports with data. In addition, Singular gets the transaction receipt from Google which can be used to validate the transaction in the context of fighting in-app fraud.

Passing the Purchase Object in React Native

This method requires using React Native's In-App Purchase package to manage transactions in your app.

Singular.inAppPurchase Method
Description Report an IAP event to Singular.
Usage Example
// Add the Singular Purchase classes imports
import {
 Singular,
 SingularConfig,
 SingularIOSPurchase,
 SingularAndroidPurchase,
} from 'singular-react-native';

let singularPurchase = null;

if (Platform.OS === 'ios') {
 singularPurchase = new SingularIOSPurchase(
   product.revenue,
   product.currency,
   purchase.productId,
   purchase.transactionId,
   purchase.transactionReceipt,
 );
} else if (Platform.OS === 'android'){
 singularPurchase = new SingularAndroidPurchase(
   product.revenue,
   product.currency,
   purchase.transactionReceipt,
   purchase.signatureAndroid,
 );
}

Singular.inAppPurchase('report iap', singularPurchase);

Passing the Purchase Object Using Native Code

If you don't use a React Native In-App Purchase package, you can still send revenue events to Singular with the purchase object, but you have to use native iOS and Android code.

iOS

iapComplete:transaction Method
Description Report an IAP event to Singular with all the details, optionally adding a name for the event.
Usage Example
// report the transaction details to Singular
[Singular iapComplete:transaction];

// report the transaction details to Singular with a custom name
[Singular iapComplete:transaction withName:@"MyCustomRevenue"];

Android

To take advantage of Android's IAP functionality, first add the following to your app's build.gradle file:

implementation 'com.singular.sdk:singular_sdk:9.+
Singular.revenue Method
Description Report a revenue event to Singular with the purchase object that is received from the Google Billing Library.
Usage Example
Singular.revenue("USD", 5.50, purchase);
Singular.customRevenue Method
Description Report a revenue event to Singular with a custom name for the event and with the purchase object that is received from the Google Billing Library.
Usage Example
Singular.customRevenue("MyCustomRevenue", 
"USD", 5.50, purchase);

Reporting Revenue Events without the Purchase Object

While we strongly recommend reporting revenue events the way described above, you can also send revenue events to Singular just by passing the currency and transaction amount. Note that this way, Singular does not get the purchase receipt and cannot validate the transaction.

Read more...
Singular.revenue Method
Description Report a revenue event to Singular with the revenue currency and amount.
Usage Example
Singular.revenue("USD", 5.50);
Singular.customRevenue Method
Description Report a revenue event to Singular with the revenue currency and amount as well as a custom name for the event.
Usage Example
Singular.customRevenue("MyCustomRevenue", "USD", 5.50);

 

Was this article helpful?