Build With RevenueCat

Build a customized mobile subscription business with RevenueCat. We do the heavy lifting of normalizing subscribers from any source and maintain a single source of truth for subscription status, so you can get back to building your app.

RevenueCat is a powerful, secure, reliable, and free to use in-app purchase server with global support. All you need to get started is an API key.

Get Started    API Reference

mParticle

Integrate in-app subscription events from RevenueCat with mParticle

👍

The mParticle integration is only available on paid plans.

RevenueCat can automatically send subscription events into mParticle. From there, you pass these events on to any of the hundreds of other integrations on their platform. This is useful for tracking all events and revenue that occur for your app even if it's not active for a period of time.

The mParticle integration tracks the following events:

Event

Description

Initial Purchase

The first purchase of an auto-renewing subscription product that does not contain a free trial.

Trial Started

The start of an auto-renewing subscription product free trial.

Trial Converted

When an auto-renewing subscription product converts from a free trial to normal paid period.

Trial Cancelled

When a user turns off renewals for an auto-renewing subscription product during a free trial period.

Renewal

When an auto-renewing subscription product renews OR a user repurchases the auto-renewing subscription product after a lapse in their subscription.

Cancellation

When a user turns off renewals for an auto-renewing subscription product during the normal paid period.

Refund

When a user canceled their subscription via customer support

Uncancellation

When a user re-enables the auto-renew status for a subscription.

Non Subscription Purchase

The purchase of any product that's not an auto-renewing subscription.

For events that have revenue, such as trial conversions and renewals, RevenueCat will automatically record this amount along with the event in mParticle.

1. Set mParticle user identity and send device data to RevenueCat

If you're using the mParticle SDK, you can set the User ID to match the RevenueCat App User Id. This way, events sent from the mParticle SDK and events sent from RevenueCat can be synced to the same user.

The mParticle integration also requires some device-specific data. RevenueCat will only send events into Singular if the below Subscriber Attributes keys have been set for the device.

Key

Description

Required

$mparticleId

The unique mParticle user identifier (mpid).

✅ (recommended)

$idfa

iOS advertising identifier UUID

❌ (optional)

$idfv

iOS vender identifier UUID

❌ (optional)

$gpsAdId

Google advertising identifier

❌ (optional)

$androidId

Android device identifier

❌ (optional)

$ip

The IP address of the device

❌ (optional)

These properties can be set manually, like any other Subscriber Attributes, or through the helper methods collectDeviceIdentifiers() and setMparticleId().

Create an identityRequest and add it to the MParticleOptions that you pass to the start() method on the mParticle SDK to set the same App User Id that is set in RevenueCat.

// Configure Purchases SDK
Purchases.configure(withAPIKey: "public_sdk_key", appUserID: "my_app_user_id")


// Set App User Id in mParticle
let options = MParticleOptions(key: "mParticle_app_key",
                               secret: "mParticle_app_secret")
let identityRequest = MPIdentityApiRequest.withEmptyUser()
identityRequest.email = "[email protected]"
identityRequest.customerId = "123456"
options.identifyRequest = identityRequest
options.onIdentifyComplete =  { (result: MPIdentityApiResult?, error: Error?) in
    guard error == nil else {
        // handle error
        return
    }
    guard let result = result else {
        // handle empty result
        return
    }
    
    // IMPORTANT: user identified successfully, get the mPID and send to RevenueCat
    let mPid = result.user.userId
    Purchases.shared.collectDeviceIdentifiers()
    Purchases.shared.setMparticleID(mPid.stringValue)
}

// Start mParticle
MParticle.sharedInstance().start(with: options)
// Configure Purchases SDK
[RCPurchases configureWithAPIKey:@"public_sdk_key" appUserID:@"my_app_user_id"];


// Set App User Id in mParticle
MParticleOptions *options = [MParticleOptions optionsWithKey:@"mParticle_app_key"
                             secret:@"mParticle_app_secret"];
MPIdentityApiRequest *identityRequest = [MPIdentityApiRequest requestWithEmptyUser];
identityRequest.email = @"[email protected]";
identityRequest.customerId = @"123456";
options.identifyRequest = identityRequest;
options.onIdentifyComplete = ^(MPIdentityApiResult *_Nullable apiResult, NSError *_Nullable error) {
    if (error) {
        // handle error
        return;
    }
    if (apiResult == nil) {
        // handle empty result
        return;
    }
    // user identified successfully, get the mPID and send to RevenueCat
    NSNumber *mPid = [apiResult.user userId];
    [[RCPurchases sharedPurchases] collectDeviceIdentifiers];
    [[RCPurchases sharedPurchases] setMparticleID:mPid.stringValue];
};


// Start mParticle
[[MParticle sharedInstance] startWithOptions:options];
// Configure Purchases SDK
Purchases.configure(this, "my_api_key", "my_app_user_id");


// Set App User Id in mParticle
IdentityApiRequest identityRequest = IdentityApiRequest.withEmptyUser()
    .email("[email protected]")
    .customerId("123456")
    .build();

BaseIdentityTask identifyTask = new BaseIdentityTask()
    .addFailureListener(new TaskFailureListener() {
      @Override
      public void onFailure(IdentityHttpResponse identityHttpResponse) {
        // handle failure
      }
    }).addSuccessListener(new TaskSuccessListener() {
      @Override
      public void onSuccess(IdentityApiResult identityApiResult) {
        // user identified successfully, get the mPID and send to RevenueCat
        long mPid = identityApiResult.getUser().getId();
        Purchases.getSharedInstance().collectDeviceIdentifiers();
        Purchases.getSharedInstance().setMparticleID(String.valueOf(mPid));
      }
    });

MParticleOptions options = MParticleOptions.builder(this)
    .credentials("mParticle_app_key", "mParticle_app_secret")
    .identify(identityRequest)
    .identifyTask(identifyTask)
    .build();


// Start mParticle
MParticle.start(options);

mParticle also allows you to log a user in after starting the SDK and log a user out; you should handle both of these cases:

// handle logging out
MParticle.sharedInstance().identity.logout(completion: { (result: MPIdentityAPIResult?, error: Error?) in
    Purchases.shared().reset()
})
// handle logging out
[[[MParticle sharedInstance] identity] logoutWithCompletion:^(MPIdentityApiResult *_Nullable apiResult, NSError *_Nullable error) {
    [[RCPurchases sharedPurchases] reset];
}];
// handle logging out
MParticle.getInstance().Identity().logout(identityRequest)
    .addFailureListener(new TaskFailureListener() {
        @Override
        public void onFailure(IdentityHttpResponse identityHttpResponse) {
            // handle error
        }
    })
    .addSuccessListener(new TaskSuccessListener() {
        @Override
        public void onSuccess(IdentityApiResult identityApiResult) {
          Purchases.getSharedInstance().reset();
        }
    });
// handle logging in
MParticle.sharedInstance().identity.login(identityRequest, completion: { (result: MPIdentityAPIResult?, error: Error?) in 
    guard error == nil else {
        // handle error
        return
    }
    guard let result = result else {
        // handle empty result
        return
    }
    // user identified successfully, get the mPID and send to RevenueCat
    let mPid = result.user.userId
    Purchases.shared.collectDeviceIdentifiers()
    Purchases.shared.setMparticleID(mPid.stringValue)
})
// handle logging in
[[[MParticle sharedInstance] identity] login:identityRequest
                                  completion:^(MPIdentityApiResult *_Nullable apiResult, NSError *_Nullable error) {
    if (error) {
        // handle error
        return;
    }
    if (apiResult == nil) {
        // handle empty result
        return;
    }
    // user identified successfully, get the mPID and send to RevenueCat
    NSNumber *mPid = [apiResult.user userId];
    [RCPurchases shared] collectDeviceIdentifiers];
    [RCPurchases shared] setMparticleID: [mPid stringValue]];
}];
// handle logging in
MParticle.getInstance().Identity().login(identityRequest)
    .addFailureListener(new TaskFailureListener() {
        @Override
        public void onFailure(IdentityHttpResponse identityHttpResponse) {
            // handle error
        }
    })
    .addSuccessListener(new TaskSuccessListener() {
        @Override
        public void onSuccess(IdentityApiResult identityApiResult) {
          // user identified successfully, get the mPID and send to RevenueCat
            long mPid = identityApiResult.getUser().getId();
            Purchases.getSharedInstance().collectDeviceIdentifiers();
          Purchases.getSharedInstance().setMparticleID(String.valueOf(mPid));
        }
    });

2. Add RevenueCat Feed Inputs in mParticle

In mParticle, add the RevenueCat feed input and create two feeds: one for the Android platform and one for the iOS platform. Copy each feed's Server to Server Key and Server to Server Secret for setup on RevenueCat. Refer to mParticle's documentation to learn more about feeds.

3. Send RevenueCat events to mParticle

After you've set up the Purchase SDK and mParticle SDK to have the same user identity, you can "turn on" the integration and configure the event names from the RevenueCat dashboard.

  1. Navigate to your app in the RevenueCat dashboard and choose 'mParticle' from the integrations menu
  2. Add your Server to Server Keys and Server to Server Secrets for each platform from step 2
  3. Enter the event names that RevenueCat will send or choose the default event names
  4. Select whether you want RevenueCat to report proceeds (after app store cut) or revenue (gross sales)

Sample Event

Below is sample JSON that is delivered to mParticle for a trial conversion event.

{
  "events": [
    {
      "data": {
        "source_message_id": "df8bb4e6-148c-4bad-ac91-d4acdfe6a44b",
        "timestamp_unixtime_ms": 1592479792179,
        "custom_attributes": {
          "revenuecat_product_id": "com.phillips-baldwin.dunn.elliott.monthly",
          "revenuecat_event": "renewal"
        },
        "product_action": {
          "action": "purchase",
          "transaction_id": null,
          "total_amount": 29.995,
          "products": [
            {
              "id": "com.phillips-baldwin.dunn.elliott.monthly",
              "price": 29.995,
              "quantity": 1,
              "total_product_amount": 29.995
            }
          ]
        },
        "currency_code": "USD",
        "is_non_interactive": true
      },
      "event_type": "commerce_event"
    }
  ],
  "source_request_id": "d28919c3-8243-46b6-9eed-3ef0723d3717",
  "user_attributes": {
    "revenuecat_color": "blue",
    "revenuecat_size": "medium",
    "$mobile": "+34666666666",
    "$country": "ES",
    "revenuecat_aliases": [
      "alias1",
      "alias2"
    ],
    "revenuecat_app_user_id": "user_vkEeY",
    "revenuecat_original_app_user_id": "user_vkEeY"
  },
  "device_info": {
    "platform": "iOS",
    "ios_advertising_id": "EA555CD-A666-77BC-B888-99ECB9B99999",
    "ios_idfv": "C555F5DB-66FC-777F-B8C8-BC99E9B999D9"
  },
  "application_info": {
    "application_name": "Rivera-Chambers",
    "package": "com.phillips-baldwin.dunn.elliott"
  },
  "user_identities": {
    "email": "[email protected]"
  },
  "schema_version": 2,
  "environment": "development",
  "mpid": "000000000000000000"
}

4. Testing the mParticle integration

You can test the mParticle integration end-to-end before going live. It's recommended that you test the integration is working properly for new users, and any existing users that may update their app to a new version.

Make a sandbox purchase with a new user

Simulate a new user installing your app, and go through your app flow to complete a sandbox purchase.

Check that the required device data is collected

Navigate the the Customer View for the test user that just made a purchase. Make sure that all of the required data from step 1 above is listed as attributes for the user.

Check that the mParticle event delivered successfully

While still on the Customer View, click into the test purchase event in the Customer History and make sure that the mParticle integration event exists and was delivered successfully.

👍

You've done it!

You should start seeing events from RevenueCat appear in mParticle

Updated 2 days ago


mParticle


Integrate in-app subscription events from RevenueCat with mParticle

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.