Track Purchase
Records an in-app purchase and links it to a prior attribution. The affiliate (creator) is automatically resolved from the attribution record.
/v1/purchasesTrack an in-app purchase and associate it with the affiliate who drove the install.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
app_id | string | Optional | Your app ID. Used for scoping and duplicate detection. |
attribution_id | string | Required | The attribution ID returned by the /v1/attribution endpoint. Links this purchase to the install and its affiliate. |
product_id | string | Required | The product identifier (e.g. "premium_monthly", "coins_500"). |
revenue | number | Required | The purchase amount (e.g. 9.99). Stored as a number. |
currency | string | Optional | ISO 4217 currency code (e.g. "USD", "EUR"). Defaults to "USD". |
transaction_id | string | Optional | The platform transaction ID from the App Store or Google Play. Used for duplicate detection. |
Example Request
curl -X POST https://us-central1-appfiliate-5a18b.cloudfunctions.net/api/v1/purchases \
-H "Content-Type: application/json" \
-d '{
"app_id": "app_myapp",
"attribution_id": "m1abc123_x9f2k4p1",
"product_id": "premium_monthly",
"revenue": 9.99,
"currency": "USD",
"transaction_id": "GPA.1234-5678-9012-34567"
}'Responses
Successful purchase
{
"status": "ok",
"purchase_id": "m1def456_y8g3h5j2"
}Duplicate transaction
If a purchase with the same transaction_id and app_id already exists, the API returns the existing purchase instead of creating a duplicate.
{
"status": "duplicate",
"purchase_id": "m1def456_y8g3h5j2"
}Missing required fields
{
"error": "Missing required fields"
}Duplicate detection
Always pass transaction_id when available. The API uses it together with app_id to detect and prevent duplicate purchase records. This makes it safe to retry failed requests without risking double-counted revenue.
Automatic creator resolution
You do not need to pass a creator_id. The API automatically looks up the attribution record to find the affiliate (creator) who drove the original install. The purchase is stored with the resolved creator_id so revenue can be attributed correctly.