Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 3 additions & 63 deletions articles/preset-purchases.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ That's why you might want to set up a signal in your application to track purcha

You can use these methods to include your purchase data in TelemetryDeck:

- Use the TelemetryDeck Swift SDK directly
- If you're already using RevenueCat, you can use the RevenueCat Integration
- If you're using FreemiumKit, you can connect that to TelemetryDeck

Expand All @@ -27,25 +26,9 @@ See the sections below for a detailed description.
We do not offer any intelligence to correct once reported purchases, such as when users make refunds, or to detect subscription renewals. Therefore, our insights focus on more recent data. For longer-term or 100% correct data, refer to official sources.
{% endnotewarning %}

## Using the TelemetryDeck Swift SDK

If you're using the TelemetryDeck Swift SDK, tracking purchases is incredibly simple. Just call the convenience method when you receive a StoreKit transaction:

```swift
TelemetryDeck.purchaseCompleted(transaction: transaction)
```

That's it! This method automatically:

- Extracts the price from the transaction
- Converts the currency to USD (using hard-coded exchange rates)
- Determines if it's a subscription or one-time purchase
- Includes the storefront country and currency codes
- Sends the properly formatted signal to TelemetryDeck

{% noteinfo "Requirements" %}
The `purchaseCompleted` convenience function is only available on iOS 15 or higher. It accepts the same optional arguments as the `signal` function (namely `parameters` and `customUserID`) in case you want to provide additional context info.
{% endnoteinfo %}
{% notewarning "EOL for TelemetryDeck Purchase Events" %}
For new apps, we're no longer showing the option to fill the Purchase Tab with data collected directly with the TelemetryDeck SDK. This option was not reliable enough, so we have sunset it. Apps that had it enabled already can keep it.
{% endnotewarning %}

## Using TelemetryDeck with RevenueCat

Expand All @@ -55,49 +38,6 @@ If you use [RevenueCat](https://revenuecat.com), you can use our [RevenueCat Set

If you use [FreemiumKit](https://freemiumkit.app), just add their SDKs `.onPurchaseCompleted` view modifier to your main view. It passes the `transaction` parameter to the closure, which you can directly pass to `TelemetryDeck.purchaseCompleted(transaction: transaction)`. Read the related section in their [setup guide](https://freemiumkit.app/documentation/freemiumkit/setupguide#Direct-Access-to-StoreKit-Transactions) to learn more.

## Manual Signal Structure for Other Platforms

{% notewarning "Only Needed for Non-Swift Platforms" %}
The following section describes the manual signal structure only necessary if you are NOT using the TelemetryDeck Swift SDK. Swift developers should use the `purchaseCompleted` convenience method described above.
{% endnotewarning %}

If you're reporting purchases from other platforms (Android, Web, etc.), you'll need to manually construct and send the purchase signal with the following structure:

### Required Fields

- **Event name**: Must be `TelemetryDeck.Purchase.completed`
- **`floatValue`**: The purchase amount in USD

{% notewarning "Manual Currency Conversion Required" %}
When sending purchase signals manually, you MUST convert the transaction value to USD yourself before sending. You can use [an API like this](https://www.exchangerate-api.com/docs/standard-requests) which offers 1,500 requests per month free of charge to get current exchange rates. Alternatively, you could fetch & hard-code exchange rates in your app for a rough estimate if you expect more than 1,500 purchases per month.
{% endnotewarning %}

### Optional but Recommended Payload Keys

To get more detailed insights, include these additional parameters:

- `TelemetryDeck.Purchase.type`: Either `subscription` or `one-time-purchase`
- `TelemetryDeck.Purchase.countryCode`: The country code of the storefront
- `TelemetryDeck.Purchase.currencyCode`: The currency code of the storefront

### Example Manual Implementation (Swift)

Here's what the manual implementation looks like if you need to customize it or understand what the convenience method does internally:

```swift
// Convert price to USD first (you need to handle currency conversion)
let priceInUSD = convertToUSD(transaction.price, from: transaction.currencyCode)

TelemetryDeck.signal(
"TelemetryDeck.Purchase.completed",
parameters: [
"TelemetryDeck.Purchase.type": transaction.subscriptionGroupID != nil ? "subscription" : "one-time-purchase",
"TelemetryDeck.Purchase.countryCode": transaction.storefrontCountryCode,
"TelemetryDeck.Purchase.currencyCode": transaction.currencyCode ?? "???"
],
floatValue: priceInUSD
)
```

## Effect on Privacy & App Tracking Transparency

Expand Down
Loading