وقتی یک نمایش رخ میدهد، Google Mobile Ads SDK دادههای درآمد تبلیغات مرتبط با آن نمایش را ارائه میکند. میتوانید از دادهها برای محاسبه ارزش طول عمر کاربر استفاده کنید، یا دادهها را به سیستمهای مرتبط دیگر ارسال کنید.
این راهنما برای کمک به شما در پیادهسازی جمعآوری دادههای درآمد تبلیغاتی در سطح نمایش در پروژه Unity طراحی شده است.
هر قالب تبلیغاتی یک رویداد OnAdPaid دارد. در طول چرخه حیات یک رویداد تبلیغاتی، Google Mobile Ads SDK رویدادهای نمایش را نظارت میکند و کنترلکننده را با AdValue که نشاندهنده ارزش کسبشده است، فراخوانی میکند.
مثال زیر به رویدادهای پولی برای یک تبلیغ پاداش میپردازد:
privatevoidLoadRewardedAd(){// Send the request to load the ad.AdRequestadRequest=newAdRequest();RewardedAd.Load("AD_UNIT_ID",adRequest,(RewardedAdrewardedAd,LoadAdErrorerror)=>
{// If the operation failed with a reason.if(error!=null){Debug.LogError("Rewarded ad failed to load an ad with error : "+error);return;}rewardedAd.OnAdPaid+=this.HandleAdPaidEvent;});}publicvoidHandleAdPaidEvent(AdValueadValue){// TODO: Send the impression-level ad revenue information to your// preferred analytics server directly within this callback.longvalueMicros=adValue.Value;stringcurrencyCode=adValue.CurrencyCode;PrecisionTypeprecision=adValue.Precision;ResponseInforesponseInfo=rewardedAd.GetResponseInfo();stringresponseId=responseInfo.GetResponseId();AdapterResponseInfoloadedAdapterResponseInfo=responseInfo.GetLoadedAdapterResponseInfo();stringadSourceId=loadedAdapterResponseInfo.AdSourceId;stringadSourceInstanceId=loadedAdapterResponseInfo.AdSourceInstanceId;stringadSourceInstanceName=loadedAdapterResponseInfo.AdSourceInstanceName;stringadSourceName=loadedAdapterResponseInfo.AdSourceName;stringadapterClassName=loadedAdapterResponseInfo.AdapterClassName;longlatencyMillis=loadedAdapterResponseInfo.LatencyMillis;Dictionary<string,string>credentials=loadedAdapterResponseInfo.AdUnitMapping;Dictionary<string,string>extras=responseInfo.GetResponseExtras();stringmediationGroupName=extras["mediation_group_name"];stringmediationABTestName=extras["mediation_ab_test_name"];stringmediationABTestVariant=extras["mediation_ab_test_variant"];}
نام منبع آگهی رویداد سفارشی را شناسایی کنید
برای منابع تبلیغات رویداد سفارشی، ویژگی AdSourceName نام منبع تبلیغ را به شما می دهد Custom Event . اگر از چندین رویداد سفارشی استفاده میکنید، نام منبع آگهی به اندازه کافی برای تمایز بین چندین رویداد سفارشی مشخص نیست. برای مکان یابی یک رویداد سفارشی خاص، مراحل زیر را انجام دهید:
ویژگی AdapterClassName را دریافت کنید.
یک نام منبع آگهی منحصر به فرد تنظیم کنید.
مثال زیر یک نام منبع آگهی منحصر به فرد را برای یک رویداد سفارشی تنظیم می کند:
privatestringGetAdSourceName(AdapterResponseInfoloadedAdapterResponseInfo){if(loadedAdapterResponseInfo==null){returnstring.Empty;}stringadSourceName=loadedAdapterResponseInfo.AdSourceName;if(adSourceName=="Custom Event"){#if UNITY_ANDROIDif(loadedAdapterResponseInfo.AdapterClassName=="com.google.ads.mediation.sample.customevent.SampleCustomEvent"){adSourceName="Sample Ad Network (Custom Event)";}#elif UNITY_IPHONEif(loadedAdapterResponseInfo.AdapterClassName=="SampleCustomEvent"){adSourceName="Sample Ad Network (Custom Event)";}#endif}returnadSourceName;}
رویداد OnPaidEvent را بلافاصله پس از ایجاد یا دسترسی به شیء تبلیغ، و قطعاً قبل از نمایش آگهی، تنظیم کنید. این اطمینان حاصل می کند که هیچ تماسی را از دست ندهید.
اطلاعات درآمد تبلیغات در سطح نمایش را فوراً در کنترلر OnPaidEvent خود به سرور تجزیه و تحلیل ترجیحی خود ارسال کنید. این اطمینان حاصل می کند که به طور تصادفی هیچ تماسی را رها نمی کنید و از اختلاف داده ها جلوگیری می کند.
AdValue
AdValue کلاسی است که ارزش پولی کسب شده برای یک آگهی را نشان می دهد، از جمله کد ارز ارزش و نوع دقیق آن که به صورت زیر کدگذاری شده است.
AdValue.PrecisionType
توضیحات
Unknown
یک ارزش تبلیغاتی که ناشناخته است. وقتی پینگ بک LTV فعال باشد اما داده کافی در دسترس نباشد، این مورد برگردانده می شود.
Estimated
یک ارزش تبلیغاتی که از دادههای جمعآوری شده تخمین زده میشود.
PublisherProvided
یک ناشر ارزش تبلیغاتی مانند CPM های دستی در یک گروه میانجی ارائه کرد.
Precise
ارزش دقیق این آگهی
در صورت میانجیگری، AdMob سعی میکند یک مقدار Estimated برای منابع تبلیغاتی بهینهسازی شده ارائه دهد. برای منابع تبلیغاتی بهینه نشده، یا در مواردی که دادههای انبوه کافی برای گزارش یک تخمین معنادار وجود ندارد، مقدار PublisherProvided برگردانده میشود.
نتایج را از منابع آگهی مناقصه آزمایش کنید
پس از اینکه یک رویداد درآمد تبلیغات در سطح نمایش برای منبع آگهی مناقصه از طریق یک درخواست آزمایشی رخ داد، فقط مقادیر زیر را دریافت میکنید:
Unknown : نوع دقت را نشان می دهد.
0 : ارزش تبلیغ را نشان می دهد.
قبلاً، ممکن است نوع دقیق را به عنوان مقداری غیر از Unknown و مقدار تبلیغاتی بیش از 0 مشاهده کرده باشید.
تاریخ آخرین بهروزرسانی 2025-09-02 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-09-02 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eImplement impression-level ad revenue data capture in your Unity project to calculate user lifetime value or forward data to other systems.\u003c/p\u003e\n"],["\u003cp\u003eBefore implementation, ensure the feature is enabled in AdMob, use Unity plugin 5.0.0 or higher, complete Get Started, and implement at least one ad format (Banner, Interstitial, Rewarded, Rewarded Interstitial, or Native).\u003c/p\u003e\n"],["\u003cp\u003eIntegrate the \u003ccode\u003eOnAdPaid\u003c/code\u003e event handler for each ad format to receive ad revenue data via the \u003ccode\u003eAdValue\u003c/code\u003e object, containing value, currency, precision, and ad source information.\u003c/p\u003e\n"],["\u003cp\u003eForward the received impression-level ad revenue data to your analytics server directly within the \u003ccode\u003eOnPaidEvent\u003c/code\u003e handler for real-time processing and to prevent data loss.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAdValue\u003c/code\u003e object provides the monetary value earned for an ad in micros, along with its currency code and precision type (Unknown, Estimated, PublisherProvided, or Precise).\u003c/p\u003e\n"]]],["The Google Mobile Ads SDK provides impression-level ad revenue data upon each ad impression. To capture this data in a Unity project, ensure the feature is enabled in AdMob, use Unity plugin 5.0.0+, and implement at least one ad format. Each format has an `OnAdPaid` event triggered by the SDK, passing an `AdValue` object. This object, including currency code and precision, is handled in the `HandleAdPaidEvent` function where you send the data to your analytics server. Integration with partners like Adjust and AppsFlyer is possible, and best practice is to set the `OnPaidEvent` immediately.\n"],null,["Select platform: [Android](/admob/android/impression-level-ad-revenue \"View this page for the Android platform docs.\") [iOS](/admob/ios/impression-level-ad-revenue \"View this page for the iOS platform docs.\") [Unity](/admob/unity/impression-level-ad-revenue \"View this page for the Unity platform docs.\")\n\n\u003cbr /\u003e\n\nWhen an impression occurs, Google Mobile Ads SDK provides ad revenue data\nassociated with that impression. You can use the data to calculate a user's\nlifetime value, or forward the data downstream to other relevant systems.\n\nThis guide is intended to help you implement the impression-level ad revenue\ndata capture in your Unity project.\n\nPrerequisites\n\n- Make sure you have [turned on the impression-level ad revenue\n feature](//support.google.com/admob/answer/11322405) in the AdMob UI.\n- Unity plugin 5.0.0 or higher.\n- Complete [Get Started](/admob/unity/quick-start). Your Unity app should already have the Google Mobile Ads Unity plugin imported.\n- Before you can receive any impression-level ad revenue data, you need to\n implement at least one ad format:\n\n - [Banner](/admob/unity/banner)\n - [Interstitial](/admob/unity/interstitial)\n - [Rewarded](/admob/unity/rewarded)\n - [Rewarded interstitial](/admob/unity/rewarded-interstitial)\n - [Native](/admob/unity/native-advanced-unified)\n\nImplementing a paid event handler\n\nEach ad format has an `OnAdPaid` event. During the lifecycle of an ad event,\nGoogle Mobile Ads SDK monitors impression events and invokes the handler\nwith a `AdValue` representing the earned value.\n\nThe following example handles paid events for a rewarded ad: \n\n private void LoadRewardedAd()\n {\n // Send the request to load the ad.\n AdRequest adRequest = new AdRequest();\n RewardedAd.Load(\"\u003cvar class=\"readonly\" translate=\"no\"\u003eAD_UNIT_ID\u003c/var\u003e\", adRequest, (RewardedAd rewardedAd, LoadAdError error) =\u003e\n {\n // If the operation failed with a reason.\n if (error != null)\n {\n Debug.LogError(\"Rewarded ad failed to load an ad with error : \" + error);\n return;\n }\n\n rewardedAd.OnAdPaid += this.HandleAdPaidEvent;\n });\n }\n\n public void HandleAdPaidEvent(AdValue adValue)\n {\n // TODO: Send the impression-level ad revenue information to your\n // preferred analytics server directly within this callback.\n long valueMicros = adValue.Value;\n string currencyCode = adValue.CurrencyCode;\n PrecisionType precision = adValue.Precision;\n ResponseInfo responseInfo = rewardedAd.GetResponseInfo();\n string responseId = responseInfo.GetResponseId();\n AdapterResponseInfo loadedAdapterResponseInfo = responseInfo.GetLoadedAdapterResponseInfo();\n string adSourceId = loadedAdapterResponseInfo.AdSourceId;\n string adSourceInstanceId = loadedAdapterResponseInfo.AdSourceInstanceId;\n string adSourceInstanceName = loadedAdapterResponseInfo.AdSourceInstanceName;\n string adSourceName = loadedAdapterResponseInfo.AdSourceName;\n string adapterClassName = loadedAdapterResponseInfo.AdapterClassName;\n long latencyMillis = loadedAdapterResponseInfo.LatencyMillis;\n Dictionary\\\u003cstring, string\\\u003e credentials = loadedAdapterResponseInfo.AdUnitMapping;\n Dictionary\\\u003cstring, string\\\u003e extras = responseInfo.GetResponseExtras();\n string mediationGroupName = extras\\[\"mediation_group_name\"\\];\n string mediationABTestName = extras\\[\"mediation_ab_test_name\"\\];\n string mediationABTestVariant = extras\\[\"mediation_ab_test_variant\"\\];\n }\n\nIdentify a custom event ad source name\n\nFor custom event ad sources, `AdSourceName` property gives you the ad source\nname `Custom Event`. If you use multiple custom events, the ad source name isn't\ngranular enough to distinguish between multiple custom events. To locate a\nspecific custom event, do the following steps:\n\n1. Get the `AdapterClassName` property.\n2. Set a unique ad source name.\n\nThe following example sets a unique ad source name for a custom event: \n\n private string GetAdSourceName(AdapterResponseInfo loadedAdapterResponseInfo)\n {\n if (loadedAdapterResponseInfo == null)\n {\n return string.Empty;\n }\n\n string adSourceName = loadedAdapterResponseInfo.AdSourceName;\n\n if (adSourceName == \"Custom Event\")\n {\n\n #if UNITY_ANDROID\n if (loadedAdapterResponseInfo.AdapterClassName ==\n \"com.google.ads.mediation.sample.customevent.SampleCustomEvent\")\n {\n adSourceName = \"Sample Ad Network (Custom Event)\";\n }\n #elif UNITY_IPHONE\n if (loadedAdapterResponseInfo.AdapterClassName == \"SampleCustomEvent\")\n {\n adSourceName = \"Sample Ad Network (Custom Event)\";\n }\n #endif\n\n }\n return adSourceName;\n } \n https://github.com/googleads/googleads-mobile-unity/blob/0f0ef22a4a4b1894951539831f9e3947ff634a75/samples/HelloWorld/Snippets/ResponseInfoSnippets.cs#L12-L39\n\nFor more information on the winning ad source, see [Retrieve information about\nthe ad response](/admob/unity/response-info).\n\nIntegrate with App Attribution Partners (AAP)\n\nFor complete details on forwarding ad revenue data to analytics platforms,\nrefer to the partner's guide:\n\n| Partner SDK |\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [Adjust](//dev.adjust.com/en/sdk/unity/integrations/admob) |\n| [AppsFlyer](//support.appsflyer.com/hc/en-us/articles/4416353506833) |\n| [Singular](//support.singular.net/hc/en-us/articles/360037635452-Unity-SDK-Integration-Guide#42_Adding_Ad_Revenue_Attribution_Support) |\n| [Tenjin](//docs.tenjin.com/en/send-events/unity.html#ilrd) |\n\nImplementation best practices\n\n- Set the `OnPaidEvent` event immediately once you create or get access to the ad object, and definitely before showing the ad. This makes sure that you don't miss any callbacks.\n- Send the impression-level ad revenue information to your preferred analytics server immediately in your `OnPaidEvent` handler. This makes sure that you don't accidentally drop any callbacks and avoids data discrepancies.\n\nAdValue\n\n`AdValue` is a class that represents the monetary value earned for an ad,\nincluding the value's currency code and its precision type encoded as follows.\n| **Key Point:** The value of `AdValue` is a micro value that represents each ad's worth. For example, a value of 5,000 indicates that this ad is estimated to be worth $0.005.\n\n| `AdValue.PrecisionType` | Description |\n|-------------------------|--------------------------------------------------------------------------------------------------------------------|\n| `Unknown` | An ad value that's unknown. This gets returned when LTV pingback is enabled but there isn't enough data available. |\n| `Estimated` | An ad value estimated from aggregated data. |\n| `PublisherProvided` | A publisher provided ad value, such as manual CPMs in a mediation group. |\n| `Precise` | The precise value of this ad. |\n\nIn case of mediation, AdMob tries to provide an `Estimated`value for ad sources\nthat are [optimized](//support.google.com/admob/answer/7374110). For\nnon-optimized ad sources, or in cases where there aren't enough aggregated data\nto report a meaningful estimation, the `PublisherProvided` value is returned.\n\nTest impressions from bidding ad sources\n\nAfter an impression-level ad revenue event occurs for\na bidding ad source through a test request, you receive only the following\nvalues:\n\n- `Unknown`: indicates the precision type.\n\n\u003c!-- --\u003e\n\n- `0`: indicates the ad value.\n\nPreviously, you might have seen the precision type as a value other than\n`Unknown`\nand an ad value more than `0`.\n\nFor details on sending a test ad request, see\n[Enable test devices](/admob/unity/test-ads#enable-test-devices)."]]