Importing Google Play purchase payloads

This tutorial describes how to import Google Play purchases into ChartMogul.

Google Play does not directly notify ChartMogul of new purchases, nor does it list all past purchases. For this reason, we rely on you, the mobile app developer, to import in-app purchases into ChartMogul.

📘

Before you begin

Before completing this tutorial, you must connect your Google Play account with ChartMogul. Follow our help centre article to learn more.

1. The Payloads URL

The Payloads URL is an endpoint uniquely generated for each Google Play data source. This endpoint accepts in-app purchase data and customer data from you, the mobile app developer.

Depending on when you created your Google Play source, the Payload URLs can have the following formats:

https://googleplay.chartmogul.com/data_sources/{{DATA_SOURCE_UUID}}/purchases
https://app.chartmogul.com/api/events/google_play_hybrid/62ccsd24dcb179a315aedc2a5bee5215

2. Authenticate

Create a new API key.

3. Submit payloads

The Payloads URL accepts payloads with purchase data and customer data. This allows you as the mobile developer to include customer specific identifiers and metadata. This information will allow you to use ChartMogul's segmentation features.

curl -X POST "https://googleplay.chartmogul.com/data_sources/ds_605e2a3a-4a25-11e9-a2cb-c76ad272868d/purchases" \
     -H 'Content-Type: application/json' \
     -u YOUR_API_KEY: \
     -d '{
     "purchase_data": {
     	"product_id": "monthly_basic",
      	"purchase_token": "oagjjjfmhmagjafhjkhlnijd.AO-J1Oy4f45RuaZIodr1s4nKPvkD1gxXNJfmmLoADyuAHZcqJHUZMm5AZiNIO6sPfaxI6LT9tFoCvE0OLpTMe2iHzoMirYW_UG4d9A4lz2-vzCOWOqFZzQWtP3FfCVpp6cNNIcK9_j0x"
      },
      "customer": {
      	"external_id": "customer_001",
      	"name": "Adam Smith",
        "email": "[email protected]",
        "company": "Acme Inc.",
        "country": "US",
        "state": "CA",
        "city": "San Jose",
        "zip": "95037",
        "lead_created_at": "2019-01-01 16:59:00",
        "trial_started_at": "2019-01-11 10:00:00",
        "attributes": {
            "tags": ["OnePlus", "multi_device"],
            "custom": [
              {
                "type": "String",
                "key": "marketing_campaign",
                "value": "Facebook ads",
                "source": "Internal DB"
              }
            ]
        }
      }
     }'
HTTP status `202 - Accepted`

{
    "message": "payload accepted for processing"
}

The payload JSON object parameters are as follows:

  1. purchase_data - Mandatory - JSON Object - A JSON object containing:
  • product_id - Mandatory - The productId for the product that was purchased. This is also called the subscriptionId or the sku in Google Play's In-App Billing and Developer APIs.
  • purchase_token - Mandatory - The purchaseToken returned by Google Play when a purchase is complete. This is usually returned within the INAPP_PURCHASE_DATA object in the getBuyIntent() method.
  1. customer - Optional but recommended - JSON object containing customer information. The body parameters are the same as the Create a Customer endpoint, excluding the data_source_uuid.

📘

Key information

  • If you haven't historically saved purchase tokens in your server, view these tokens for each order in the Order Management section of the Google Play console.
  • Send purchase tokens in chronological order of purchase time to ensure upgrades, downgrades and re-activations are correctly linked up and reported in ChartMogul.
  • To ensure ChartMogul's reports are as up-to-date as possible, send purchase tokens as soon as you receive them on your servers.
  • Include the subscriber's unique external_id in the payloads, even if you do not include other subscriber attributes. This helps ChartMogul report all in-app subscriptions purchased by the same subscriber under a single customer.
  • If you cannot specify the external_id, ChartMogul generates an anonymous subscriber for each purchase_token that is not linked to another purchase token, and will set the customer external ID to the purchase token.
  • If you import a purchase token for an upgrade/downgrade/reactivation, ChartMogul will be able to link it to a previously imported purchase_token by using the linkedPurchaseToken property in Google Developer APIs.
  • ChartMogul generates its own subscription external IDs to track upgrades/downgrades/reactivations as accurately as possible.
  • Customer custom attributes with Type: String have a limit of 255 characters. Attributes above 255 characters will be truncated.