# Revenue Outcomes

{% hint style="warning" %}
This API is only available in iOS at the moment. Please reach out to our team if you need this API in Android.
{% endhint %}

## What is a revenue outcome?

A revenue outcome represents the result of a monetization event in your app, such as an in-app purchase or an ad impression.

## Why is it important?

Understanding how and when users contribute to revenue allows ContextSDK to make informed predictions about the best moments to display monetization opportunities. Logging revenue outcomes helps ContextSDK optimize your ML models, ensuring that monetization decisions align with real-world user behavior, so we can optimize your app for revenue generation.

## When should I log revenue outcomes?

Log a revenue outcome whenever the user generates revenue. This includes in-app purchases, ad clicks, ad impressions, tips, or other sources of revenue.

Use revenue outcomes only for events that directly lead to revenue. For non-revenue actions that are positive, like permission prompts or rating requests, use standalone positive outcomes instead of revenue outcomes.

**When NOT to log revenue outcomes:**

* If the user dismisses the offer or doesn't convert, log a standalone negative outcome, not a revenue outcome
* If a purchase transaction fails due to technical issues (network problems, payment method issues, etc.), don't log anything - these failures don't reflect user intent or context quality

## How to log revenue outcomes

Here's a few examples of how to log revenue outcomes for different scenarios.

### In-app purchases

#### StoreKit 2 (iOS 15+)

If you're using **StoreKit 2**, log a purchase like this:

```swift
// `product` is the StoreKit 2 product that was purchased.
context.logRevenueOutcome(from: product)
```

#### StoreKit 1 (iOS 8+)

If your app uses **StoreKit 1** or needs to support iOS 14 and earlier, see [StoreKit1 Docs](/context-decision/revenue-outcomes/logging-revenue-with-storekit-1.md).

#### Third-party frameworks

If you're using **Superwall**, see [Using ContextSDK with Superwall](/context-decision/revenue-outcomes/superwall.md)

If you're using **Purchasely**, see [Using ContextSDK with Purchasely](/context-decision/revenue-outcomes/purchasely.md)

If you're using **RevenueCat**, see [Logging Revenue with RevenueCat](/context-decision/revenue-outcomes/revenuecat.md)

If you're using a different in-app purchase framework, retrieve the equivalent StoreKit product object and pass it to `logRevenueOutcome(from:)` for StoreKit 2 or `logStoreKit1RevenueOutcome(from:)` for StoreKit 1.

{% hint style="success" %}
There's no need to call `context.log(.positive)` after logging a revenue outcome from a `Product`, as the positive outcome is already logged internally. Alternatively, you can customize the outcome to be logged directly, via `logRevenueOutcome(from:outcome:)`.

For a list of all available outcomes see [Alternative Outcomes](/context-decision/advanced/alternative-outcomes.md).
{% endhint %}

### Ad clicks and impressions

For an **ad click**, log the revenue outcome as follows:

```swift
let event = RevenueEvent(source: .adClick, revenue: 0.09, currency: .usd)
context.logRevenueOutcome(from: event, outcome: .positiveAdTapped)
```

Or for an **ad impression**:

```swift
let event = RevenueEvent(source: .adImpression, revenue: 0.00175, currency: .usd)
context.logRevenueOutcome(from: event, outcome: .negativeNotInteracted)
```

The revenue values in these examples are placeholders. Use the actual revenue values from your ad network's SDK, preferring the most precise values available. If exact values aren't provided, an estimate is acceptable, however, greater precision improves accuracy.

Some ad networks may provide callbacks that contain live revenue data. Use this data to log revenue outcomes in real-time, ensuring that the revenue data is as accurate as possible.

## Best practices

* **Avoid duplicate logging:** Use `logRevenueOutcomeIfNotLoggedYet(from:)` for events where duplicate logging may occur.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.contextsdk.com/context-decision/revenue-outcomes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
