update:新增打点需求 review_creative_id 和 ad_placement
--story=1020787 --user=yufei.hu 【中台】【广告】新增打点需求 review_creative_id 和 ad_placement https://www.tapd.cn/33527076/s/1159788 Signed-off-by: huyufei <yufei.hu@castbox.fm>dev
							parent
							
								
									50c5627ac2
								
							
						
					
					
						commit
						400498af17
					
				|  | @ -1,4 +1,5 @@ | |||
| 
 | ||||
| using System; | ||||
| using UnityEngine; | ||||
| 
 | ||||
| namespace Guru | ||||
|  | @ -115,7 +116,7 @@ namespace Guru | |||
|          | ||||
|         private void OnLoadMaxBanner() | ||||
|         { | ||||
| 	        _badsloadStartTime = Time.realtimeSinceStartup; | ||||
| 	        _badsloadStartTime = DateTime.UtcNow; | ||||
| 	        _chanelMax.LoadBannerAD(); | ||||
| 	        OnBannerStartLoad?.Invoke(_chanelMax.MaxBADSSlotID); | ||||
|         } | ||||
|  | @ -147,7 +148,7 @@ namespace Guru | |||
|         } | ||||
| 
 | ||||
|         private void OnLoadMaxIV() { | ||||
| 	        _iadsLoadStartTime = Time.realtimeSinceStartup; // 更新计时器 | ||||
| 	        _iadsLoadStartTime = DateTime.UtcNow; // 更新计时器 | ||||
| 	        _chanelMax.LoadInterstitialAD(); | ||||
| 	        OnInterstitialStartLoad?.Invoke(_chanelMax.MaxIADSSlotID); | ||||
|         } | ||||
|  | @ -180,7 +181,7 @@ namespace Guru | |||
|          | ||||
|         private void OnLoadMaxRV() | ||||
|         { | ||||
| 	        _radsLoadStartTime = Time.realtimeSinceStartup; // 更新计时器 | ||||
| 	        _radsLoadStartTime = DateTime.UtcNow; // 更新计时器 | ||||
| 	        _chanelMax.LoadRewardAD(); | ||||
| 	        OnRewardedStartLoad?.Invoke(_chanelMax.MaxRADSSlotID); | ||||
|         } | ||||
|  |  | |||
|  | @ -213,11 +213,24 @@ namespace Guru | |||
|              | ||||
|             // #2 tch_001 | ||||
|             double revenue = impressionData.value; | ||||
|             CalcTaichi001Value(revenue); | ||||
|             CalcTaichi02Value(revenue); | ||||
|             CalcTch001Value(revenue); | ||||
|             CalcTch02Value(revenue); | ||||
|                  | ||||
|             // #3 adjust_ad_revenue | ||||
|             AdjustService.TrackADRevenue(impressionData); | ||||
| 
 | ||||
| 
 | ||||
|             var adType = impressionData.ad_format.ToUpper(); | ||||
|             // #4 Paid Event | ||||
|             Debug.Log($"{Tag} --- ReportAdsRevenue :: Send Paid Event: {adType}"); | ||||
|             if (adType.Contains("INTER")) | ||||
|             { | ||||
|                 OnInterstitialPaidEvent(impressionData); | ||||
|             } | ||||
|             else if (adType.Contains("REWARD")) | ||||
|             { | ||||
|                 OnRewardedAdPaidEvent(impressionData); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -238,7 +251,7 @@ namespace Guru | |||
|                 else | ||||
|                 { | ||||
|                     // 找不到的话会缓存 adInfo, 等待获取 RCid | ||||
|                     _impressionCache[adInfo.CreativeIdentifier] = CreateImpressionData(adInfo, "", Analytics.AdMAX); | ||||
|                     SetImpressionData(adInfo); | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|  | @ -281,7 +294,7 @@ namespace Guru | |||
|         /// 计算太极001收益 | ||||
|         /// </summary> | ||||
|         /// <param name="revenue"></param> | ||||
|         private void CalcTaichi001Value(double revenue) | ||||
|         private void CalcTch001Value(double revenue) | ||||
|         { | ||||
|             TchAD001RevValue += revenue; | ||||
|             double revenueValue = TchAD001RevValue; | ||||
|  | @ -298,7 +311,7 @@ namespace Guru | |||
|         /// 计算太极02收益 | ||||
|         /// </summary> | ||||
|         /// <param name="revenue"></param> | ||||
|         private void CalcTaichi02Value(double revenue) | ||||
|         private void CalcTch02Value(double revenue) | ||||
|         { | ||||
|             if (!Analytics.EnableTch02Event) return; | ||||
| 
 | ||||
|  | @ -320,21 +333,25 @@ namespace Guru | |||
|         private string _backColorStr = "#50A436"; | ||||
|         private Color _backColor = new Color(0, 0, 0, 0); | ||||
|         private string _badsCategory; | ||||
|         protected float _badsloadStartTime = 0; | ||||
|         protected DateTime _badsloadStartTime; | ||||
|         private bool _bannerVisible = false; | ||||
|         public bool IsBannerVisible => _bannerVisible; | ||||
|         private int _badsloadedNum = 0; | ||||
|         private int _badsLoadFailNum = 0; | ||||
| 
 | ||||
|          | ||||
| 
 | ||||
|         private int GetAdsLoadDuration(ref float startTime) | ||||
|          | ||||
|         /// <summary> | ||||
|         /// 获取动作间隔之间的毫秒数 | ||||
|         /// </summary> | ||||
|         /// <param name="startTime"></param> | ||||
|         /// <returns></returns> | ||||
|         private int GetActionDuration(DateTime startTime) | ||||
|         { | ||||
|             int duration = (int)((Time.realtimeSinceStartup - startTime) * 1000); | ||||
|             startTime = Time.realtimeSinceStartup; | ||||
|             return duration; | ||||
|             var sp = DateTime.UtcNow.Subtract(startTime.ToUniversalTime()).Duration(); | ||||
|             return (int) sp.TotalMilliseconds; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public virtual void RequestBannerAD() | ||||
|         { | ||||
|             _backColor = Color.clear; | ||||
|  | @ -365,12 +382,12 @@ namespace Guru | |||
| 
 | ||||
|         public void OnLoadBads() | ||||
|         { | ||||
|             _badsloadStartTime = Time.realtimeSinceStartup; | ||||
|             _badsloadStartTime = DateTime.UtcNow; | ||||
|         } | ||||
| 
 | ||||
|         protected virtual void OnBadsLoaded() | ||||
|         { | ||||
|             _badsloadStartTime = Time.realtimeSinceStartup; | ||||
|             _badsloadStartTime = DateTime.UtcNow; | ||||
|             OnBannerLoaded?.Invoke(); | ||||
|         } | ||||
|          | ||||
|  | @ -446,7 +463,7 @@ namespace Guru | |||
|             _badsLoadFailNum ++; | ||||
|             // Analytics.ADBadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _badsloadStartTime), _badsCategory); | ||||
|             Analytics.ADBadsFailed(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _badsloadStartTime), category: _badsCategory, | ||||
|                 duration: GetActionDuration(_badsloadStartTime), category: _badsCategory, | ||||
|                 errorCode: (int)errorInfo.Code, | ||||
|                 waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); | ||||
|         } | ||||
|  | @ -488,9 +505,12 @@ namespace Guru | |||
| 
 | ||||
|         private string _iadsCategory = "main"; | ||||
|         private int _interstitialRetryAttempt; | ||||
|         protected float _iadsLoadStartTime; | ||||
|         private Action _interCloseAction; | ||||
|         protected bool _isIadsLoading = false; | ||||
|         protected DateTime _iadsLoadStartTime; | ||||
|         private DateTime _iadsDisplayStartTime; | ||||
|          | ||||
|          | ||||
|         public bool IsIadsLoading => _isIadsLoading; | ||||
| 
 | ||||
|         public virtual void RequestInterstitialAD() | ||||
|  | @ -514,7 +534,7 @@ namespace Guru | |||
| 
 | ||||
|         public void OnLoadIads() | ||||
|         { | ||||
|             _iadsLoadStartTime = Time.realtimeSinceStartup; | ||||
|             _iadsLoadStartTime = DateTime.UtcNow; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -548,6 +568,7 @@ namespace Guru | |||
|             _interCloseAction = dismissAction; | ||||
|             MaxSdk.ShowInterstitial(GetInterstitialID()); | ||||
| 
 | ||||
|             _iadsDisplayStartTime = DateTime.UtcNow; | ||||
|             // RequestInterstitialAD(); // 直接加载下一个广告 | ||||
|         } | ||||
| 
 | ||||
|  | @ -558,7 +579,7 @@ namespace Guru | |||
|             // Reset retry attempt | ||||
|             // Analytics.ADIadsLoaded(adUnitId, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory); | ||||
|             Analytics.ADIadsLoaded(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory)); | ||||
|                 duration: GetActionDuration(_iadsLoadStartTime), category: _iadsCategory)); | ||||
|             _interstitialRetryAttempt = 0; | ||||
| 
 | ||||
|             Debug.Log( $"[SDK][Ads][Loaded] --- adUnitId:{adUnitId}    Revenue:{adInfo.Revenue}    Type:{adInfo.AdFormat}    CreativeId:{adInfo.CreativeIdentifier}"); | ||||
|  | @ -577,8 +598,9 @@ namespace Guru | |||
|             float retryDelay = GetRetryDelaySeconds(_interstitialRetryAttempt); | ||||
|             DelayCall(retryDelay, RequestInterstitialAD); | ||||
|             // Analytics.ADIadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory); | ||||
|             if(string.IsNullOrEmpty(_iadsCategory)) _iadsCategory = "not_set"; | ||||
|             Analytics.ADIadsFailed(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory, | ||||
|                 duration: GetActionDuration(_iadsLoadStartTime), category: _iadsCategory, | ||||
|                 errorCode: (int)errorInfo.Code, | ||||
|                 waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); | ||||
| 
 | ||||
|  | @ -593,42 +615,65 @@ namespace Guru | |||
|                 $"InterstitialFailedToDisplayEvent AdLoadFailureInfo:{errorInfo.AdLoadFailureInfo}, Message: {errorInfo.Message}"); | ||||
|             // Analytics.ADIadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory); | ||||
|             Analytics.ADIadsFailed(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory, | ||||
|                 duration: GetActionDuration(_iadsDisplayStartTime), category: _iadsCategory, | ||||
|                 errorCode: (int)errorInfo.Code, | ||||
|                 waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); | ||||
|             DelayCall(2.0f, RequestInterstitialAD); | ||||
|         } | ||||
| 
 | ||||
|          | ||||
|         // iads_imp | ||||
|         protected virtual void OnInterstitialDisplayEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) | ||||
|         { | ||||
|             // Analytics.ADIadsImp(adUnitId, _iadsCategory); | ||||
|             Analytics.ADIadsImp(AdParams.Build(adUnitId, category: _iadsCategory)); | ||||
|             string reviewCreativeId = GetReviewCreativeId(adInfo.CreativeIdentifier); | ||||
|             Analytics.ADIadsImp(AdParams.Build(adUnitId, adInfo, category: _iadsCategory, reviewCreativeId:reviewCreativeId)); | ||||
|         } | ||||
| 
 | ||||
|         protected virtual void OnInterstitialClickEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) | ||||
|         { | ||||
|             // Analytics.ADIadsClick(adUnitId, _iadsCategory); | ||||
|             Analytics.ADIadsClick(AdParams.Build(adUnitId, category: _iadsCategory)); | ||||
|             string reviewCreativeId = GetReviewCreativeId(adInfo.CreativeIdentifier); | ||||
|             var impressionData = CreateImpressionData(adInfo, reviewCreativeId); | ||||
|             var data = impressionData.BuildEventData(); | ||||
|             if(string.IsNullOrEmpty(_iadsCategory)) _iadsCategory = "not_set"; | ||||
|             data["item_category"] = _iadsCategory; | ||||
|             data.Remove("ad_format"); | ||||
|             Analytics.ADIadsClick(data); | ||||
|         } | ||||
| 
 | ||||
|          | ||||
|         // Close  | ||||
|         protected virtual void OnInterstitialDismissedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) | ||||
|         { | ||||
|             // Interstitial ad is hidden. Pre-load the next ad | ||||
|             _interCloseAction?.Invoke(); | ||||
|             OnInterstitialClosed?.Invoke(); | ||||
|             // Analytics.ADIadsClose(adUnitId, _iadsCategory); | ||||
|             Analytics.ADIadsClose(AdParams.Build(adUnitId, category: _iadsCategory)); | ||||
|             Analytics.ADIadsClose(AdParams.Build(adUnitId,  | ||||
|                 duration:GetActionDuration(_iadsDisplayStartTime),  | ||||
|                 category: _iadsCategory)); | ||||
|              | ||||
|             //延时加载下一个广告 | ||||
|             DelayCall(2.0f, RequestInterstitialAD); | ||||
|         } | ||||
| 
 | ||||
|         private void OnInterstitialPaidEvent(AdImpressionData impressionData) | ||||
|         { | ||||
|             var data = impressionData.BuildEventData(); | ||||
|             if(string.IsNullOrEmpty(_iadsCategory)) _iadsCategory = "not_set"; | ||||
|             data["item_category"] = _iadsCategory; | ||||
|             data.Remove("ad_format"); | ||||
|             Analytics.ADIadsPaid(data); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region Rewarded Ads | ||||
| 
 | ||||
|         private string _rewardCategory = "main"; | ||||
|         private int _rewardRetryAttempt; | ||||
|         protected float _radsLoadStartTime; | ||||
|         protected DateTime _radsLoadStartTime; | ||||
|         protected DateTime _radsShowStartTime; | ||||
|         private Action _rvRewardAction; | ||||
|         private Action<string> _rvFailAction; | ||||
|         private Action _rvDismissAction; | ||||
|  | @ -661,7 +706,7 @@ namespace Guru | |||
| 
 | ||||
|         public void OnLoadRads() | ||||
|         { | ||||
|             _radsLoadStartTime = Time.realtimeSinceStartup; | ||||
|             _radsLoadStartTime = DateTime.UtcNow; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -700,6 +745,8 @@ namespace Guru | |||
|             _rvDismissAction = dismissAction; | ||||
|             MaxSdk.ShowRewardedAd(GetRewardedID()); | ||||
| 
 | ||||
|             _radsShowStartTime = DateTime.UtcNow; | ||||
|              | ||||
|             // RequestRewardedAD(); | ||||
|         } | ||||
| 
 | ||||
|  | @ -712,7 +759,7 @@ namespace Guru | |||
|             // this.Log("OnRewardedAdLoadedEvent"); | ||||
|             // Analytics.ADRadsLoaded(adUnitId, GetAdsLoadDuration(ref _radsLoadStartTime), _rewardCategory); | ||||
|             Analytics.ADRadsLoaded(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _radsLoadStartTime), category: _iadsCategory)); | ||||
|                 duration: GetActionDuration(_radsLoadStartTime), category: _iadsCategory)); | ||||
|             _rewardRetryAttempt = 0; | ||||
|              | ||||
|             Debug.Log( $"[SDK][Ads][Loaded] --- adUnitId:{adUnitId}    Revenue:{adInfo.Revenue}    Type:{adInfo.AdFormat}    CreativeId:{adInfo.CreativeIdentifier}"); | ||||
|  | @ -730,7 +777,7 @@ namespace Guru | |||
|                 $"OnRewardedAdFailedEvent AdLoadFailureInfo:{errorInfo.AdLoadFailureInfo}, Message: {errorInfo.Message}"); | ||||
|             // Analytics.ADRadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _radsLoadStartTime), _rewardCategory); | ||||
|             Analytics.ADRadsFailed(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _radsLoadStartTime), category: _rewardCategory, | ||||
|                 duration: GetActionDuration(_radsLoadStartTime), category: _rewardCategory, | ||||
|                 errorCode: (int)errorInfo.Code, | ||||
|                 waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); | ||||
|             _rewardRetryAttempt++; | ||||
|  | @ -748,7 +795,7 @@ namespace Guru | |||
|                 $"OnRewardedAdFailedToDisplayEvent AdLoadFailureInfo:{errorInfo.AdLoadFailureInfo}, Message: {errorInfo.Message}"); | ||||
|             // Analytics.ADRadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _radsLoadStartTime), _rewardCategory); | ||||
|             Analytics.ADRadsFailed(AdParams.Build(adUnitId, | ||||
|                 duration: GetAdsLoadDuration(ref _radsLoadStartTime), category: _rewardCategory, | ||||
|                 duration: GetActionDuration(_radsShowStartTime), category: _rewardCategory, | ||||
|                 errorCode: (int)errorInfo.Code, | ||||
|                 waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); | ||||
|             _rvFailAction?.Invoke("OnRewardedAdFailedToDisplayEvent"); | ||||
|  | @ -761,16 +808,23 @@ namespace Guru | |||
|         { | ||||
|             this.Log("OnRewardedAdDisplayedEvent"); | ||||
|             // Analytics.ADRadsImp(adUnitId, _rewardCategory); | ||||
|             Analytics.ADRadsImp(AdParams.Build(adUnitId, category: _rewardCategory)); | ||||
|             string reviewCreativeId = GetReviewCreativeId(adInfo.CreativeIdentifier); | ||||
|             Analytics.ADRadsImp(AdParams.Build(adUnitId, adInfo, category: _rewardCategory, reviewCreativeId:reviewCreativeId)); | ||||
|         } | ||||
| 
 | ||||
|         protected virtual void OnRewardedAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) | ||||
|         { | ||||
|             this.Log("OnRewardedAdClickedEvent"); | ||||
|             // Analytics.ADRadsClick(adUnitId, _rewardCategory); | ||||
|             Analytics.ADRadsClick(AdParams.Build(adUnitId, category: _rewardCategory)); | ||||
|             var impressionData = CreateImpressionData(adInfo, GetReviewCreativeId(adInfo.CreativeIdentifier)); | ||||
|             var data = impressionData.BuildEventData(); | ||||
|             if(string.IsNullOrEmpty(_rewardCategory)) _rewardCategory = "not_set"; | ||||
|             data["item_category"] = _rewardCategory; | ||||
|             data.Remove("ad_format"); | ||||
|             Analytics.ADRadsClick(data); | ||||
|         } | ||||
| 
 | ||||
|          | ||||
|         // rads_close | ||||
|         protected virtual void OnRewardedAdDismissedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) | ||||
|         { | ||||
|             this.Log("OnRewardedAdDismissedEvent"); | ||||
|  | @ -779,24 +833,37 @@ namespace Guru | |||
|             OnRewardClosed?.Invoke(); | ||||
|              | ||||
|             // Analytics.ADRadsClose(adUnitId, _rewardCategory); | ||||
|             Analytics.ADRadsClose(AdParams.Build(adUnitId, category: _rewardCategory)); | ||||
|             Analytics.ADRadsClose(AdParams.Build(adUnitId, duration:GetActionDuration(_radsShowStartTime), category: _rewardCategory)); | ||||
|              | ||||
|             //延时加载下一个广告 | ||||
|             DelayCall(2.0f, RequestRewardedAD); | ||||
|              | ||||
|              | ||||
|         } | ||||
| 
 | ||||
|          | ||||
|         // rads_rewarded | ||||
|         protected virtual void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward, | ||||
|             MaxSdkBase.AdInfo arg3) | ||||
|             MaxSdkBase.AdInfo adInfo) | ||||
|         { | ||||
|             this.Log("OnRewardedAdReceivedRewardEvent"); | ||||
|             // Analytics.ADRadsRewarded(adUnitId, _rewardCategory); | ||||
|             Analytics.ADRadsRewarded(AdParams.Build(adUnitId, category: _rewardCategory)); | ||||
|             var impressionData = CreateImpressionData(adInfo, GetReviewCreativeId(adInfo.CreativeIdentifier));  | ||||
|             var data = impressionData.BuildEventData(); | ||||
|             if(string.IsNullOrEmpty(_rewardCategory)) _rewardCategory = "not_set"; | ||||
|             data["item_category"] = _rewardCategory; | ||||
|             data.Remove("ad_format"); | ||||
|             Analytics.ADRadsRewarded(data); | ||||
|             // Rewarded ad was displayed and user should receive the reward | ||||
|             _rvRewardAction?.Invoke(); | ||||
|         } | ||||
| 
 | ||||
|         // rads_paid | ||||
|         private void OnRewardedAdPaidEvent(AdImpressionData impressionData) | ||||
|         { | ||||
|             var data = impressionData.BuildEventData(); | ||||
|             if(string.IsNullOrEmpty(_rewardCategory)) _rewardCategory = "not_set"; | ||||
|             data["item_category"] = _rewardCategory; | ||||
|             data.Remove("ad_format"); | ||||
|             Analytics.ADRadsPaid(data); | ||||
|         } | ||||
|         #endregion | ||||
| 
 | ||||
|         #region Ad Settings | ||||
|  | @ -840,7 +907,36 @@ namespace Guru | |||
|         #endregion | ||||
| 
 | ||||
|         #region CreativeID | ||||
|          | ||||
| 
 | ||||
|         private string GetReviewCreativeId(string creativeId) | ||||
|         { | ||||
|             if (_reviewCreativeIds == null) | ||||
|             { | ||||
|                 return ""; | ||||
|             } | ||||
|              | ||||
|             if (_reviewCreativeIds.TryGetValue(creativeId, out var reviewCreativeId)) | ||||
|             { | ||||
|                 return reviewCreativeId; | ||||
|             } | ||||
|             return ""; | ||||
|         } | ||||
| 
 | ||||
|         private void SetReviewCreativeId(string creativeId, string reviewCreativeId) | ||||
|         { | ||||
|             if (_reviewCreativeIds == null) _reviewCreativeIds = new Dictionary<string, string>(10); | ||||
| 
 | ||||
|             if (string.IsNullOrEmpty(reviewCreativeId)) return; | ||||
| 
 | ||||
|             _reviewCreativeIds[creativeId] = reviewCreativeId; | ||||
|         } | ||||
| 
 | ||||
|         private void SetImpressionData(MaxSdkBase.AdInfo adInfo, string reviewCreativeId = "", string platform = "") | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(platform)) platform = Analytics.AdMAX; | ||||
|             _impressionCache[adInfo.CreativeIdentifier] = CreateImpressionData(adInfo, reviewCreativeId, platform); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 获取 AdReviewCreativeId | ||||
|         /// </summary> | ||||
|  | @ -856,14 +952,8 @@ namespace Guru | |||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if (_reviewCreativeIds == null) _reviewCreativeIds = new Dictionary<string, string>(10); | ||||
| 
 | ||||
|              | ||||
|             // 尝试直接上报广告收益 (可能存在异步上报的情况) | ||||
|             if (!TryReportImpression(adInfo, reviewCreativeId)) | ||||
|             { | ||||
|                 _reviewCreativeIds[adInfo.CreativeIdentifier] = reviewCreativeId; // 如果上报未成功, 则缓存reviewCreativeId   | ||||
|             } | ||||
|             TryReportImpression(adInfo, reviewCreativeId); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|  | @ -872,10 +962,9 @@ namespace Guru | |||
|         /// <param name="adInfo"></param> | ||||
|         /// <param name="reviewCreativeId"></param> | ||||
|         /// <returns></returns> | ||||
|         private bool TryReportImpression(MaxSdk.AdInfo adInfo, string reviewCreativeId = "") | ||||
|         private void TryReportImpression(MaxSdk.AdInfo adInfo, string reviewCreativeId = "") | ||||
|         { | ||||
|             string creativeId = adInfo.CreativeIdentifier; | ||||
|             bool result = false; | ||||
|             List<string> removeList = new List<string>(); | ||||
|              | ||||
|             if (_impressionCache.TryGetValue(creativeId, out var impressionData)) | ||||
|  | @ -885,7 +974,11 @@ namespace Guru | |||
|                  | ||||
|                 ReportAdsRevenue(impressionData); | ||||
|                 removeList.Add(creativeId); | ||||
|                 result = true; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // 如果上报未成功, 则缓存reviewCreativeId  | ||||
|                 SetReviewCreativeId(adInfo.CreativeIdentifier, reviewCreativeId);   | ||||
|             } | ||||
| 
 | ||||
|             // 清理超过 3 秒未上报的数据 | ||||
|  | @ -906,8 +999,6 @@ namespace Guru | |||
|                     _reviewCreativeIds.Remove(k); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return result; | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|  |  | |||
|  | @ -1,5 +1,7 @@ | |||
| 
 | ||||
| 
 | ||||
| using System.Collections.Generic; | ||||
| 
 | ||||
| namespace Guru | ||||
| { | ||||
|     using System; | ||||
|  | @ -36,5 +38,23 @@ namespace Guru | |||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public Dictionary<string, object> BuildEventData() | ||||
|         { | ||||
|             var data = new Dictionary<string, object>() | ||||
|             { | ||||
|                 { "value", value }, | ||||
|                 { "currency", currency }, | ||||
|                 { "ad_platform", ad_platform }, | ||||
|                 { "ad_format", ad_format }, | ||||
|                 { "ad_source", ad_source }, | ||||
|                 { "ad_unit_name", ad_unit_name }, | ||||
|                 { "ad_placement", ad_placement }, | ||||
|                 { "ad_creative_id", ad_creative_id }, | ||||
|                 { "review_creative_id", review_creative_id }, | ||||
|             }; | ||||
|              | ||||
|             return data; | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | @ -36,15 +36,37 @@ namespace Guru | |||
| 
 | ||||
| 		    if (adParams.duration > 0)  | ||||
| 			    data[ParameterDuration] = adParams.duration; | ||||
| 		     | ||||
| 		    if (adParams.errorCode != 0)  | ||||
| 			    data[ParameterErrorCode] = adParams.errorCode; | ||||
| 		     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.networkName))  | ||||
| 			    data[ParameterNetworkName] = adParams.networkName; | ||||
| 		    if (!string.IsNullOrEmpty(adParams.networkPlacement))  | ||||
| 
 | ||||
| 		    if (!string.IsNullOrEmpty(adParams.networkPlacement)) | ||||
| 		    { | ||||
| 			    data[ParameterNetworkPlacement] = adParams.networkPlacement; | ||||
| 			    data[ParameterAdPlacement] = adParams.networkPlacement; | ||||
| 		    } | ||||
| 			     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.waterfallName))  | ||||
| 			    data[ParameterWaterfall] = adParams.waterfallName; | ||||
| 		     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.creativeId))  | ||||
| 			    data[ParameterAdCreativeId] = adParams.creativeId; | ||||
| 		     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.reviewCreativeId))  | ||||
| 			    data[ParameterReviewCreativeId] = adParams.reviewCreativeId; | ||||
| 		     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.adPlatform)) | ||||
| 			    data[ParameterAdPlatform] = adParams.adPlatform; | ||||
| 		     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.adSource)) | ||||
| 			    data[ParameterAdSource] = adParams.adSource; | ||||
| 		     | ||||
| 		    if (!string.IsNullOrEmpty(adParams.adFormat)) | ||||
| 			    data[ParameterAdFormat] = adParams.adFormat; | ||||
| 		     | ||||
| 		    if (extra != null && extra.Count > 0) | ||||
| 		    { | ||||
| 			    foreach (var k in extra.Keys) | ||||
|  | @ -128,7 +150,12 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		public static void ADIadsClick(AdParams adParams) | ||||
| 		{ | ||||
| 			TrackEvent(EventIadsClick, BuildAdEventData(adParams)); | ||||
| 			ADIadsClick(BuildAdEventData(adParams)); | ||||
| 		} | ||||
| 		 | ||||
| 		public static void ADIadsClick(Dictionary<string, object> data) | ||||
| 		{ | ||||
| 			TrackEvent(EventIadsClick, data); | ||||
| 		} | ||||
| 
 | ||||
| 		/// <summary> | ||||
|  | @ -139,6 +166,15 @@ namespace Guru | |||
| 			TrackEvent(EventIadsClose, BuildAdEventData(adParams)); | ||||
| 		} | ||||
| 		 | ||||
| 		/// <summary> | ||||
| 		/// 插屏广告收到奖励 | ||||
| 		/// </summary> | ||||
| 		/// <param name="data"></param> | ||||
| 		public static void ADIadsPaid(Dictionary<string, object> data) | ||||
| 		{ | ||||
| 			TrackEvent(EventIadsPaid, data); | ||||
| 		} | ||||
| 		 | ||||
| 	    //---------------------- REWARDS ------------------------- | ||||
| 		/// <summary> | ||||
| 		/// 广告开始加载 | ||||
|  | @ -173,7 +209,11 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		public static void ADRadsRewarded(AdParams adParams) | ||||
| 		{ | ||||
| 			var data = BuildAdEventData(adParams); | ||||
| 			ADRadsRewarded(BuildAdEventData(adParams)); | ||||
| 		} | ||||
| 		 | ||||
| 		public static void ADRadsRewarded(Dictionary<string, object> data) | ||||
| 		{ | ||||
| 			TrackEvent(EventRadsRewarded, data); | ||||
| 			 | ||||
| 			if (RadsRewardCount == 0) | ||||
|  | @ -183,6 +223,15 @@ namespace Guru | |||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		/// <summary> | ||||
| 		/// 插屏广告收到奖励 | ||||
| 		/// </summary> | ||||
| 		/// <param name="data"></param> | ||||
| 		public static void ADRadsPaid(Dictionary<string, object> data) | ||||
| 		{ | ||||
| 			TrackEvent(EventRadsPaid, data); | ||||
| 		} | ||||
| 		 | ||||
| 
 | ||||
| 		private static int RadsRewardCount | ||||
| 		{ | ||||
|  | @ -203,7 +252,12 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		public static void ADRadsClick(AdParams adParams) | ||||
| 		{ | ||||
| 			TrackEvent(EventRadsClick, BuildAdEventData(adParams)); | ||||
| 			ADRadsClick(BuildAdEventData(adParams)); | ||||
| 		} | ||||
| 		 | ||||
| 		public static void ADRadsClick(Dictionary<string, object> data) | ||||
| 		{ | ||||
| 			TrackEvent(EventRadsClick, data); | ||||
| 		} | ||||
| 
 | ||||
| 		/// <summary> | ||||
|  | @ -260,10 +314,15 @@ namespace Guru | |||
| 	    public string category; | ||||
| 	    public string networkName; | ||||
| 	    public string networkPlacement; | ||||
| 	    public string adPlatform; | ||||
| 	    public string adSource; | ||||
| 	    public string adFormat; | ||||
| 	    public string waterfallName; | ||||
| 	    public string adUnitId; | ||||
| 	    public int errorCode = 0;  | ||||
| 	    public int duration = 0; | ||||
| 	    public string creativeId; | ||||
| 	    public string reviewCreativeId; | ||||
| 
 | ||||
| 
 | ||||
| 	    /// <summary> | ||||
|  | @ -275,31 +334,47 @@ namespace Guru | |||
| 	    /// <param name="duration"></param> | ||||
| 	    /// <param name="errorCode"></param> | ||||
| 	    /// <param name="waterfallName"></param> | ||||
| 	    /// <param name="reviewCreativeId"></param> | ||||
| 	    /// <param name="adPlatform"></param> | ||||
| 	    /// <returns></returns> | ||||
| 	    public static AdParams Build(string adUnitId, MaxSdkBase.AdInfo adInfo = null, string category = "",  | ||||
| 		    int duration = 0, int errorCode = 0, string waterfallName = "") | ||||
| 		    int duration = 0, int errorCode = 0, string waterfallName = "", string reviewCreativeId = "", string adPlatform = "") | ||||
| 	    { | ||||
| 		    if (string.IsNullOrEmpty(adUnitId) && adInfo != null) adUnitId = adInfo.AdUnitIdentifier; | ||||
| 		    var networkName = ""; | ||||
| 		    var networkPlacement = ""; | ||||
| 		    var creativeId = ""; | ||||
| 		    var adSource = ""; | ||||
| 		    var adFormart = ""; | ||||
| 
 | ||||
| 		    if (string.IsNullOrEmpty(adPlatform)) adPlatform = Analytics.AdMAX; | ||||
| 		    if (adInfo != null) | ||||
| 		    { | ||||
| 			    networkName = adInfo.NetworkName; | ||||
| 			    networkPlacement = adInfo.NetworkPlacement; | ||||
| 			    creativeId = adInfo.CreativeIdentifier; | ||||
| 			    adSource = adInfo.NetworkName; | ||||
| 			    adFormart = adInfo.AdFormat; | ||||
| 
 | ||||
| 			    if (string.IsNullOrEmpty(waterfallName)) | ||||
| 				    waterfallName = adInfo.WaterfallInfo?.Name ?? ""; | ||||
| 			     | ||||
| 		    } | ||||
| 
 | ||||
| 		    var p = new AdParams() | ||||
| 		    { | ||||
| 			    adUnitId = adUnitId, | ||||
| 			    adPlatform = adPlatform, | ||||
| 			    adSource = adSource, | ||||
| 			    adFormat = adFormart, | ||||
| 			    duration = duration, | ||||
| 			    networkName = networkName, | ||||
| 			    networkPlacement = networkPlacement, | ||||
| 			    waterfallName = waterfallName, | ||||
| 			    category = category, | ||||
| 			    errorCode = errorCode, | ||||
| 			    creativeId = creativeId, | ||||
| 			    reviewCreativeId = reviewCreativeId, | ||||
| 		    }; | ||||
| 		    return p; | ||||
| 	    } | ||||
|  |  | |||
|  | @ -161,7 +161,7 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		public static void SetUserProperty(string propertyName, string propertyValue) | ||||
| 		{ | ||||
| 			Log.I(TAG,$"SetUserProperty -> propertyName:{propertyName}, propertyValue:{propertyValue}"); | ||||
| 			Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{propertyName}, propertyValue:{propertyValue}"); | ||||
|          | ||||
| 			if (!IsReady) | ||||
| 				return; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue