Doanh thu Quảng cáo

The app sends impression revenue data to the AppsFlyer SDK. The SDK then sends it to AppsFlyer. These impression data is collected and processed in AppsFlyer, and the revenue is attributed to the original UA source. To learn more about ad revenue see here.

There are two ways for the SDK to generate an ad revenue event, depending on your SDK version. Use the correct method for your SDK version:

Log ad revenue (for SDK 6.15.0 and above)

When an impression with revenue occurs invoke the logAdRevenue method with the revenue details of the impression.

To implement the method:

  1. Create an instance of AFAdRevenueData with the revenue details of the impression to be logged.
  2. If you want to add additional details to the ad revenue event, populate a dictionary with key-value pairs.
  3. Invoke the  logAdRevenue method with the following arguments:
    • The AFAdRevenueData object you created in step 1.
    • The dictionary with the additional details you created in step 2.

Code Example

import AppsFlyerLib


let my_adRevenueData = AFAdRevenueData(monetizationNetwork: "ironsource",
                        mediationNetwork: MediationNetworkType.googleAdMob,
                        currencyIso4217Code: "USD",
                        eventRevenue: 123.45)
        
var my_additionalParameters: [String: Any] = [:]
my_additionalParameters[kAppsFlyerAdRevenueCountry] = 10
my_additionalParameters[kAppsFlyerAdRevenueAdType] = "Banner"
my_additionalParameters[kAppsFlyerAdRevenueAdUnit] = "89b8c0159a50ebd1"
my_additionalParameters[kAppsFlyerAdRevenuePlacement] = "place"

AppsFlyerLib.shared().logAdRevenue(my_adRevenueData, additionalParameters: my_additionalParameters)

[LEGACY] Log ad revenue (for SDK 6.14.6 and below)

Để tích hợp trình kết nối SDK doanh thu quảng cáo iOS, bạn cần nhập, khởi chạy và kích hoạt SDK.

Import the iOS ad revenue SDK

  1. Trong Podfile của bạn, hãy chỉ định những thông tin sau:
pod 'AppsFlyer-AdRevenue'

Quan trọng: Nếu bạn có pod AppsFlyerFramework trong Podfile của mình, hãy xóa để tránh xung đột.

  1. Chạy cập nhật pod.

Initialize the iOS ad revenue SDK

  • In AppDelegate, trong phương thức didFinishLaunchingWithOptions , gọi ra phương thức AdRevenue start bằng mã sau:
import AppsFlyerLib
import AppsFlyerAdRevenue

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       AppsFlyerAdRevenue.start()
    }

     @objc func applicationDidBecomeActive() {
        AppsFlyerLib.shared().start()        
    }

}

Trigger the logAdRevenue API call

  • Kích hoạt logAdRevenue lệnh gọi API mỗi khi có lượt hiển thị hợp lệ, bao gồm cả đối số bắt buộc và không bắt buộc bất kỳ nào.
let adRevenueParams:[AnyHashable: Any] = [
                    kAppsFlyerAdRevenueCountry : "us",
                    kAppsFlyerAdRevenueAdUnit : "02134568",
                    kAppsFlyerAdRevenueAdType : "Banner",
                    kAppsFlyerAdRevenuePlacement : "place",
                    "foo" : "testcustom",
                    "bar" : "testcustom2"
                ]
                
AppsFlyerAdRevenue.shared().logAdRevenue(
    monetizationNetwork: "facebook",
    mediationNetwork: MediationNetworkType.googleAdMob,
    eventRevenue: 0.026,
    revenueCurrency: "USD",
    additionalParameters: adRevenueParams)