Revenue Outcomes

Learn when and how to log revenue outcomes in ContextSDK to optimize monetization and improve model accuracy.

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.

If the user dismisses the offer or doesn’t convert, log a standalone negative outcome, not a revenue outcome.

How to log revenue outcomes

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

In-app purchases

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

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

If your app still uses Store Kit 1, fetch the SKProduct and access its productIdentifier. With this identifier, you can fetch the StoreKit 2 product using products(for:) :

let products = try await Product.products(for: productIdentifier)
if let product = products.first {
    context.logRevenueOutcome(from: products.first!)
} else {
    // Handle this scenario, even though it shouldn't be possible
}

If you're using RevenueCat, see Logging Revenue with RevenueCat

If you’re using a different in-app purchase framework, retrieve the equivalent StoreKit product object and pass it to logRevenueOutcome(from:).

Ad clicks and impressions

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

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

Or for an ad impression:

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.

Last updated

Was this helpful?