Unity SDK - 広告収入のトラッキング

ドキュメント

広告収益の帰属

メディエーションプラットフォームからの広告収入を追跡し、ユーザーを獲得したマーケティングキャンペーンに帰属させることで、キャンペーンコスト、アプリ内課金、広告収益化を網羅した完全なROIの可視性を提供します。

概要

広告収益アトリビューションとは

広告収益アトリビューションは、モバイルアプリの広告収益をアプリのインストールを促進したユーザー獲得キャンペーンに結び付け、広告収益化を含むキャンペーンの真の収益性を測定できるようにします。

主なメリット

  • 統一されたROIビュー:キャンペーンコスト、アプリ内収益、広告収益を単一のダッシュボードで確認できます。
  • キャンペーンの最適化:広告収益データを広告ネットワークに送信し、入札とターゲティングを改善します。
  • LTV測定:広告収益化を含む完全なユーザー生涯価値の算出

データソース:広告収益データは通常、ユーザーレベルまたはインプレッションレベルで、お客様のメディエーションプラットフォーム(AdMob、AppLovin MAX、IronSourceなど)から提供されます。Singularはこのデータを受け取るための複数の統合方法をサポートしています。

詳細はこちら:セットアップ、レポート、トラブルシューティングの包括的な詳細については、広告収入アトリビューションFAQをご覧ください。


実装要件

重要なガイドライン

データの正確性が重要です

  1. 通貨コード:3文字のISO 4217通貨コード(例:USD、EUR、INR)を使用してください。多くのメディエーション・プラットフォームはUSDでレポートします。
  2. 送信前に検証する: SingularSDK.AdRevenue() を呼び出す前に、必ず収益および通貨データを検証してください。 間違ったデータは、送信後に修正することはできません。
  3. プラットフォームの違い:AdMobは、UnityとAndroidではマイクロ単位(1,000,000で割る)で収益を報告しますが、iOSでは標準単位で報告します。プラットフォームのドキュメントをご確認ください。

セットアップステップ

広告収益のアトリビューションを実装するには、以下の手順に従ってください:

  1. SDKを更新する:最新のSingular SDKバージョンを使用していることを確認してください。
  2. インテグレーションを選択します:セットアップに合ったメディエーションプラットフォームのインテグレーションを選択します。
  3. コールバックを実装します:プラットフォーム固有の有料イベントリスナーを追加し、収益データを取得します。
  4. データを検証します:収益レポートをテストし、データがSingularダッシュボードに表示されることを確認します。

プラットフォームインテグレーション

AdMobインテグレーション

インプレッションレベルの収益レポート用の有料イベントリスナーを使用して、Google AdMobからの広告収益をトラッキングします。

要件

プラットフォームの収益レポート:AdMobの収益レポートはプラットフォームによって異なります。0.005ドルの広告収益は、UnityとAndroidプラットフォームでは5000として返されますが、iOSでは0.005として返されます。iOSの場合は、Singular SDKに直接0.005を送信してください。その他のプラットフォームでは、広告価値をマイクロからドルに変換してからSingularに送信してください。

実装

広告の読み込み時にOnAdPaid イベントハンドラを登録し、収益データを取得してSingularに送信します。

C#
using UnityEngine;
using Singular;
using GoogleMobileAds.Api;

public class AdMobRevenueTracking : MonoBehaviour
{
    private const string AD_UNIT_ID = "YOUR_AD_UNIT_ID";
    private RewardedAd rewardedAd;
    
    void Start()
    {
        // Initialize Mobile Ads SDK
        MobileAds.Initialize(initStatus =>
        {
            Debug.Log("AdMob initialized");
            LoadRewardedAd();
        });
    }
    
    private void LoadRewardedAd()
    {
        // Create ad request
        AdRequest adRequest = new AdRequest();
        
        // Load rewarded ad
        RewardedAd.Load(AD_UNIT_ID, adRequest, (RewardedAd ad, LoadAdError error) =>
        {
            if (error != null || ad == null)
            {
                Debug.LogError($"Rewarded ad failed to load: {error}");
                return;
            }
            
            Debug.Log("Rewarded ad loaded");
            rewardedAd = ad;
            
            // Register event handlers
            RegisterEventHandlers(ad);
        });
    }
    
    private void RegisterEventHandlers(RewardedAd ad)
    {
        // Raised when the ad is estimated to have earned money
        ad.OnAdPaid += (AdValue adValue) =>
        {
            // Validate and ensure revenue data is within an expected range
            float revenue = adValue.Value / 1_000_000f; // Convert micros to dollars
            string currency = adValue.CurrencyCode;
            
            // Check if revenue is positive and currency is valid
            if (revenue > 0 && !string.IsNullOrEmpty(currency))
            {
                // Construct and send the Singular Ad Revenue Event
                SingularAdData data = new SingularAdData(
                    "AdMob",
                    currency,
                    revenue
                );
                
                SingularSDK.AdRevenue(data);
                
                // Log the revenue data for debugging purposes
                Debug.Log($"Ad Revenue reported to Singular: {data}");
            }
            else
            {
                Debug.LogError($"Invalid ad revenue data: revenue = {revenue}, currency = {currency}");
            }
        };
        
        // Additional event handlers
        ad.OnAdFullScreenContentOpened += () =>
        {
            Debug.Log("Rewarded ad full screen content opened");
        };
        
        ad.OnAdFullScreenContentClosed += () =>
        {
            Debug.Log("Rewarded ad full screen content closed");
            // Load next ad
            LoadRewardedAd();
        };
        
        ad.OnAdFullScreenContentFailed += (AdError error) =>
        {
            Debug.LogError($"Rewarded ad failed to show: {error}");
            // Load next ad
            LoadRewardedAd();
        };
    }
    
    public void ShowRewardedAd()
    {
        if (rewardedAd != null && rewardedAd.CanShowAd())
        {
            rewardedAd.Show((Reward reward) =>
            {
                Debug.Log($"User earned reward: {reward.Type} - {reward.Amount}");
            });
        }
        else
        {
            Debug.Log("Rewarded ad is not ready yet");
        }
    }
}

AppLovin MAXとの統合

AppLovin Impression-Level User Revenue APIを使ってインプレッションレベルの広告収益をトラッキングします。

要件

  • AppLovin MAX SDK for Unityを実装する(スタートガイドを参照
  • 使用しているすべての広告フォーマットに収益支払いコールバックをアタッチする。

実装

OnAdRevenuePaidEvent コールバックを登録し、収益データをキャプチャしてSingularに送信します。

C#
using UnityEngine;
using Singular;

public class AppLovinRevenueTracking : MonoBehaviour
{
    void Start()
    {
        // Attach callbacks based on the ad format(s) you are using
        MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
        MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
        MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
        MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
    }
    
    private void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
    {
        double revenue = adInfo.Revenue;
        
        if (revenue > 0)
        {
            // Create a SingularAdData object with relevant information
            SingularAdData adData = new SingularAdData(
                "AppLovin",
                "USD", // AppLovin typically reports in USD
                revenue
            );
            
            // Send ad revenue data to Singular
            SingularSDK.AdRevenue(adData);
            
            Debug.Log($"Ad Revenue reported to Singular: {revenue} USD from {adUnitId}");
        }
        else
        {
            Debug.LogError("Failed to parse valid revenue value from ad info or revenue is not greater than 0");
        }
    }
    
    void OnDestroy()
    {
        // Detach callbacks to prevent memory leaks
        MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
        MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
        MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
        MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
    }
}

Unity LevelPlay(IronSource)の統合

IronSource SDKを使用して、IronSourceおよび仲介ネットワークからのインプレッションレベルの収益をトラッキングします。

要件

  • IronSource Unity SDKを実装する(スタートガイドを参照
  • IronSourceダッシュボードでARM SDK Postbacksフラグを有効にする。
  • 収益コールバックを受信するインプレッションデータリスナーを設定する

詳細セットアップの詳細については、IronSource Ad Revenue Documentationを参照してください。

実装

ImpressionDataReadyEvent 、収益データを取得して送信します。

C#
using UnityEngine;
using Singular;

public class IronSourceRevenueTracking : MonoBehaviour
{
    void Start()
    {
        // Ensure the listener is added before initializing the SDK
        IronSourceEvents.onImpressionDataReadyEvent += ImpressionDataReadyEvent;
        
        // Initialize the IronSource SDK here if not already done
        // IronSource.Agent.init("YOUR_IRONSOURCE_APP_KEY");
    }
    
    private void ImpressionDataReadyEvent(IronSourceImpressionData impressionData)
    {
        if (impressionData != null)
        {
            // Ensure revenue value is valid
            double? revenue = impressionData.revenue;
            
            if (revenue.HasValue && revenue.Value > 0)
            {
                // Create SingularAdData object with appropriate values
                SingularAdData adData = new SingularAdData(
                    "IronSource",
                    "USD", // IronSource typically reports in USD
                    revenue.Value
                );
                
                // Send the Ad Revenue data to Singular
                SingularSDK.AdRevenue(adData);
                
                // Log the data for debugging
                Debug.Log($"Ad Revenue reported to Singular: AdPlatform: {adData.AdPlatform}, " +
                         $"Currency: {adData.Currency}, Revenue: {adData.Revenue}");
            }
            else
            {
                Debug.LogError($"Invalid revenue value: {revenue}");
            }
        }
        else
        {
            Debug.LogError("Impression data is null");
        }
    }
    
    void OnDestroy()
    {
        // Detach the callback to prevent memory leaks
        IronSourceEvents.onImpressionDataReadyEvent -= ImpressionDataReadyEvent;
    }
}

TradPlusとの統合

グローバルインプレッションリスナーを使用してTradPlusメディエーションから広告収益をキャプチャします。

要件

  • TradplusAds.Instance().AddGlobalAdImpression() 経由でグローバル広告インプレッションリスナーを追加する。
  • OnGlobalAdImpression コールバックを処理し、収益データを受信する。
  • eCPMをミリ単位から標準通貨に変換(1000で割る)

実装

すべての広告インプレッションと収益を追跡するグローバルインプレッションリスナーを登録する。

C#
using UnityEngine;
using Singular;
using System.Collections.Generic;
using System.Globalization;

public class TradPlusRevenueTracking : MonoBehaviour
{
    private const string TAG = "TradPlusRevenue";
    
    void Start()
    {
        // Add Global Ad Impression Listener
        TradplusAds.Instance().AddGlobalAdImpression(OnGlobalAdImpression);
    }
    
    void OnGlobalAdImpression(Dictionary<string, object> adInfo)
    {
        // Ensure adInfo is not null
        if (adInfo == null)
        {
            Debug.LogError($"{TAG}: AdInfo is null");
            return;
        }
        
        // Ensure eCPM is present and valid
        if (!adInfo.ContainsKey("ecpm") || adInfo["ecpm"] == null)
        {
            Debug.LogError($"{TAG}: eCPM value is null or missing");
            return;
        }
        
        // Parse the eCPM value
        if (!double.TryParse(adInfo["ecpm"].ToString(), NumberStyles.Float | NumberStyles.AllowThousands, 
            CultureInfo.InvariantCulture, out double revenue))
        {
            Debug.LogError($"{TAG}: Failed to parse eCPM value");
            return;
        }
        
        // Convert eCPM to revenue (eCPM is in milli-units)
        revenue = revenue / 1000.0;
        
        // Validate the revenue value
        if (revenue <= 0)
        {
            Debug.LogError($"{TAG}: Ad Revenue value out of expected range: {revenue}");
            return;
        }
        
        // Create SingularAdData object with the necessary fields
        SingularAdData data = new SingularAdData(
            "TradPlus",
            "USD",
            revenue
        );
        
        // Send the Ad Revenue data to Singular
        SingularSDK.AdRevenue(data);
        
        // Log the data for debugging purposes
        Debug.Log($"{TAG}: Ad Revenue reported to Singular: AdPlatform: {data.AdPlatform}, " +
                 $"Currency: {data.Currency}, Revenue: {data.Revenue}");
    }
}

汎用統合(その他のプラットフォーム)

一般的なSingularAdData インターフェイスを使用して、任意のメディエーションプラットフォームを統合します。

要件

  • 媒介プラットフォームからのインプレッションレベルの収益データへのアクセス
  • 標準通貨単位での収益額(マイクロは不可)
  • ISO 4217通貨コード(例:USD、EUR、INR)

データの正確性:Singularに送信する前に、収益と通貨データを検証してください。不正確なデータは送信後に修正できません。

実装

プラットフォーム名、通貨、収益でSingularAdData オブジェクトを作成し、SingularSDK.AdRevenue() を呼び出します。

C#
using UnityEngine;
using Singular;

public class GenericAdRevenueTracking : MonoBehaviour
{
    // Function to report ad revenue to Singular
    public void ReportAdRevenue(string adPlatform, string currency, float revenue)
    {
        // Validate the input: ensure revenue is positive and currency is not null or empty
        if (revenue > 0 && !string.IsNullOrEmpty(currency))
        {
            // Create a SingularAdData object with the validated data
            SingularAdData data = new SingularAdData(
                adPlatform,
                currency,
                revenue
            );
            
            // Send the ad revenue data to Singular
            SingularSDK.AdRevenue(data);
            
            // Log the reported data for debugging
            Debug.Log($"Ad Revenue reported to Singular: Platform = {adPlatform}, " +
                     $"Currency = {currency}, Revenue = {revenue}");
        }
        else
        {
            // Log a warning if validation fails
            Debug.LogWarning($"Invalid ad revenue data: Platform = {adPlatform}, " +
                           $"Revenue = {revenue}, Currency = {currency}");
        }
    }
    
    // Example usage
    void ExampleUsage()
    {
        // Report revenue from a custom mediation platform
        ReportAdRevenue("MyMediationPlatform", "USD", 0.05f);
    }
}

テストと検証

収益レポートの検証

広告収益の実装をテストし、データが正しくSingularに流れることを確認します。

  1. ログを確認する:収益コールバックのログがUnity Consoleに正しい値と通貨で表示されることを確認します。
  2. 広告のテストテスト広告をロードして表示し、収益イベントをトリガーします。
  3. ダッシュボードの検証:24時間以内にSingularダッシュボードに収益が表示されることを確認
  4. データの正確性:収益額がメディエーションプラットフォームのレポートと一致するか確認します。

トラブルシューティング収益がSingularに表示されない場合は、以下を確認してください:

  • 広告収益のアトリビューションがSingularアカウントで有効になっている。
  • 収益の値が0より大きい
  • 通貨コードが有効なISO 4217コードである。
  • プラットフォーム名がSingularの予想フォーマットと一致している
  • 広告がロードされる前にイベントハンドラが適切に登録されているか。