iOS Native

Tracking Revenue

The Noctua SDK supports purchase and revenue tracking for monetization analytics.

Track Purchase

import com.noctuagames.sdk.Noctua
import com.noctuagames.sdk.model.PurchaseData

val purchaseData = PurchaseData(
    productId = "com.example.coin_pack",
    price = 4.99,
    currency = "USD",
    transactionId = "txn_123456789"
)

Noctua.trackPurchase(purchaseData)

Note

Always pass the correct currency code (ISO 4217 format, e.g., "USD"). Ensure transactionId is unique to avoid duplication.

Track Ad Revenue

You can track ad revenue events using the Noctua SDK to measure monetization performance across ad networks.

Example

import com.noctuagames.sdk.Noctua

val revenueData = mapOf(
    "ad_network" to "AdMob",
    "placement" to "rewarded_video",
    "revenue" to 0.015,
    "currency" to "USD"
)

Noctua.trackEvent("ad_revenue", revenueData)

Parameters

  • source: The source of the ad revenue. Use admob_sdk for AdMob or applovin_max_sdk for AppLovin MAX.
  • revenue: The revenue of the ad.
  • currency: The currency of the ad revenue.
  • parameters: A dictionary of parameters to track with the event.

Data Sources

Applovin

func didPayRevenue(_ ad: MAAd)
{
    let revenue = ad.revenue // In USD

    // Miscellaneous data
    let countryCode = ALSdk.shared().configuration.countryCode // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
    let networkName = ad.networkName // Display name of the network that showed the ad
    let adUnitId = ad.adUnitIdentifier // The MAX Ad Unit ID
    let adFormat = ad.format // The ad format of the ad (e.g. BANNER, MREC, INTERSTITIAL, REWARDED)
    let placement = ad.placement // The placement this ad's postbacks are tied to
    let networkPlacement = ad.networkPlacement // The placement ID from the network that showed the ad

    // Example how to track ad revenue
    Noctua.trackAdRevenue(
        "applovin_max_sdk",
        revenue,
        "USD",
        mapOf(
            "platform" to platform,
            "networkPlacement" to networkPlacement
        )
    )

    // Example how to track custom event with revenue
    Noctua.trackCustomEventWithRevenue(
        "ad_impression",
        revenue,
        currency,
        mapOf(
            "platform" to platform,
            "networkSource" to networkSource
        )
    )
}

Admob

var rewardedAd: RewardedAd?
  func requestRewardedAd() {
    RewardedAd.load(
      with: "AD_UNIT_ID", request: Request()
    ) { (ad, error) in
      if let error = error {
        print("Rewarded ad failed to load with error: \(error.localizedDescription)")
        return
      }
      if let ad = ad {
        self.rewardedAd = ad
        self.rewardedAd?.paidEventHandler = { adValue in
        // TODO: Send the impression-level ad revenue information to your preferred analytics
        // server directly within this callback.

        // Extract the impression-level ad revenue data.
        let revenue = adValue.value
        let precision = adValue.precision
        let currencyCode = adValue.currencyCode

        // Example how to track ad revenue
        Noctua.trackAdRevenue(
            "admob_sdk",
            revenue,
            currencyCode,
            mapOf(
                "adSourceName" to adSourceName
            )
        )

        // Example how to track custom event with revenue
        Noctua.trackCustomEventWithRevenue(
            "ad_impression",
            revenue,
            currencyCode,
            mapOf(
                "adSourceName" to adSourceName
            )
        )
      }
    }
  }
}

Sources

Previous
Custom events tracking