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.

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:

// `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 our dedicated https://github.com/context-sdk/docs/blob/main/context-decision/revenue-outcomes/storekit1.md for complete examples and best practices.

Third-party frameworks

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:) for StoreKit 2 or logStoreKit1RevenueOutcome(from:) for StoreKit 1.

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?