修复topon loaded参数为0/快手激励切屏发放奖励/数数属性上报/admob开屏收益获取不到问题,adjust改为生产环境

This commit is contained in:
juncong lee 2025-09-04 14:24:18 +08:00
parent 799a2b32eb
commit 87de004f3d
11 changed files with 156 additions and 108 deletions

View File

@ -1,5 +1,7 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using AdjustSdk; using AdjustSdk;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
@ -7,17 +9,14 @@ using WZ;
public class AdjustManager : D_MonoSingleton<AdjustManager> public class AdjustManager : D_MonoSingleton<AdjustManager>
{ {
private AdjustEnvironment environment = AdjustEnvironment.Sandbox; // 测试用Sandbox发布用Production private AdjustEnvironment environment = AdjustEnvironment.Production;
private long startTime = 0; private long startTime = 0;
private string Adid; private string Adid;
private string Gdid; private string Gdid;
private string callbackNetwork = "";
private string _adNetwork = "_adNetwork"; bool m_start = false;
private string _campaign = "_campaign"; private int callGetTimes = 0;
private string _adgroup = "_adgroup";
private string _creative = "_creative";
public void Init() public void Init()
{ {
@ -39,13 +38,11 @@ public class AdjustManager : D_MonoSingleton<AdjustManager>
LoadAdid(); LoadAdid();
LoadGaid(); LoadGaid();
//计时3分钟
AppSDKManager.Instance.Coroutine(AdjustNetwork.Instance.SetOrganic3Min());
ShuShuEvent.Instance.Track("adjust_init"); ShuShuEvent.Instance.Track("adjust_init");
FireBaseAnalyticsManager.Instance.LogEvent("adjust_init"); FireBaseAnalyticsManager.Instance.LogEvent("adjust_init");
} }
/// <summary> /// <summary>
/// 归因信息 /// 归因信息
/// </summary> /// </summary>
@ -53,50 +50,112 @@ public class AdjustManager : D_MonoSingleton<AdjustManager>
private void AttributionChangedDelegate(AdjustAttribution attribution) private void AttributionChangedDelegate(AdjustAttribution attribution)
{ {
Debug.Log("Attribution changed network: " + attribution.Network + " campaign: " + attribution.Campaign + " adgroup: " + attribution.Adgroup + " creative: " + attribution.Creative); Debug.Log("Attribution changed network: " + attribution.Network + " campaign: " + attribution.Campaign + " adgroup: " + attribution.Adgroup + " creative: " + attribution.Creative);
if (m_start) return;
m_start = true;
callbackNetwork = attribution.Network;
if (IsOrganic(attribution.Network) == false)
{
OnReceiveCallback(attribution);
return;
}
InvokeRepeating(nameof(CallGetAttributionAsync), 0, 1);
}
private async Task CallGetAttributionAsync()
{
callGetTimes++;
AdjustAttribution attribute = await GetAttributionAsync();
LoggerUtils.Debug("[adjust] adjust CallGetAttribution callGetTimes : " + callGetTimes + " attinfo:" + attribute.Network + " clicklabel:" + attribute.ClickLabel);
if (attribute != null)
{
LoggerUtils.Debug("[adjust] adjust 重试次数 : " + callGetTimes + ", attribute : " + attribute.Network + ", callbackNetwork : " + callbackNetwork);
if (attribute.Network.Equals(callbackNetwork) == false)
{
CancelInvoke(nameof(CallGetAttributionAsync));
OnReceiveCallback(attribute);
}
}
if (callGetTimes >= 3*60)
{
if (attribute != null)
{
OnReceiveCallback(attribute);
}
else
{
OnReceiveCallback(null);
}
CancelInvoke(nameof(CallGetAttributionAsync));
}
}
public static Task<AdjustAttribution> GetAttributionAsync()
{
var tcs = new TaskCompletionSource<AdjustAttribution>();
Adjust.GetAttribution(attribution =>
{
try
{
tcs.TrySetResult(attribution);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
});
return tcs.Task;
}
private void OnReceiveCallback(AdjustAttribution attribution)
{
string campaign = "";
string adgroup = "";
string creative = "";
string network = "";
if (attribution != null)
{
campaign = attribution.Campaign;
adgroup = attribution.Adgroup;
creative = attribution.Creative;
network = attribution.Network;
}
else
{
network = "Organic";
}
AdjustNetwork.Instance.SetNetwork(attribution.Network); AdjustNetwork.Instance.SetNetwork(attribution.Network);
SaveProperties(attribution); AdjustNetwork.Instance.LogEventGetSuccess();
ShuShuEvent.Instance.UserSet(new Dictionary<string, object>
{
{ "user_ad_network", network ?? "" },
{ "user_campaign", campaign ?? "" },
{ "user_adgroup", adgroup ?? "" },
{ "user_creative", creative ?? "" },
});
var userProperties = new Dictionary<string, object>(); AppSDKManager.Instance.SetSuperProperties(new Dictionary<string, object>
userProperties.Add("ad_network", AdjustManager.GetAdNetwork()); {
userProperties.Add("campaign", AdjustManager.GetCampaign()); { "ad_network", network ?? "" },
userProperties.Add("adgroup", AdjustManager.GetAdgroup()); { "campaign", campaign ?? "" },
userProperties.Add("creative", AdjustManager.GetCreative()); { "adgroup", adgroup ?? "" },
ShuShuEvent.Instance.UserSet(userProperties); { "creative", creative ?? "" },
});
var publicProperties = new Dictionary<string, object>();
publicProperties.Add("user_ad_network", AdjustManager.GetAdNetwork());
publicProperties.Add("user_campaign", AdjustManager.GetCampaign());
publicProperties.Add("user_adgroup", AdjustManager.GetAdgroup());
publicProperties.Add("user_creative", AdjustManager.GetCreative());
AppSDKManager.Instance.SetSuperProperties(publicProperties);
} }
private void SaveProperties(AdjustAttribution attribution)
{
PlayerPrefsUtils.SavePlayerPrefsString(_adNetwork, attribution.Network.Substring(0, 10));
PlayerPrefsUtils.SavePlayerPrefsString(_campaign, attribution.Campaign.Substring(0, 20));
PlayerPrefsUtils.SavePlayerPrefsString(_adgroup, attribution.Adgroup.Substring(0, 10));
PlayerPrefsUtils.SavePlayerPrefsString(_creative, attribution.Creative.Substring(0, 20));
}
public static string GetAdNetwork() private bool IsOrganic(string _network)
{ {
return PlayerPrefsUtils.GetPlayerPrefsString(AdjustManager.Instance._adNetwork, ""); if (_network.Equals("Organic") || _network.Equals("Untrusted Devices") || _network.Equals(""))
{
return true;
} }
return false;
public static string GetCampaign()
{
return PlayerPrefsUtils.GetPlayerPrefsString(AdjustManager.Instance._campaign, "");
}
public static string GetAdgroup()
{
return PlayerPrefsUtils.GetPlayerPrefsString(AdjustManager.Instance._adgroup, "");
}
public static string GetCreative()
{
return PlayerPrefsUtils.GetPlayerPrefsString(AdjustManager.Instance._creative, "");
} }
public long GetStartTime() public long GetStartTime()

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using AdjustSdk;
using UnityEngine; using UnityEngine;
using WZ; using WZ;
@ -29,31 +29,6 @@ public class AdjustNetwork : D_MonoSingleton<AdjustNetwork>
} }
} }
/// <summary>
/// 3分钟设置自然量
/// </summary>
public IEnumerator SetOrganic3Min()
{
string curNetwork = PlayerPrefs.GetString(KEY_USER_NETWORK, "");
if (!string.IsNullOrEmpty(curNetwork))
{
yield break;
}
//写死3分钟
yield return new WaitForSeconds(3 * 60);
//重新获取
curNetwork = PlayerPrefs.GetString(KEY_USER_NETWORK, "");
if (!string.IsNullOrEmpty(curNetwork))
{
yield break;
}
LogEventGetSuccess();
PlayerPrefs.SetString(KEY_USER_NETWORK, "Organic");
PlayerPrefs.Save();
}
/// <summary> /// <summary>
/// 是否是自然量用户 /// 是否是自然量用户
@ -85,7 +60,7 @@ public class AdjustNetwork : D_MonoSingleton<AdjustNetwork>
/// <summary> /// <summary>
/// 获取adjust信息成功 /// 获取adjust信息成功
/// </summary> /// </summary>
private void LogEventGetSuccess() public void LogEventGetSuccess()
{ {
long startTime = AdjustManager.Instance.GetStartTime(); long startTime = AdjustManager.Instance.GetStartTime();
long endTime = TimeUtils.GetLocalTimestamp(); long endTime = TimeUtils.GetLocalTimestamp();

View File

@ -148,7 +148,7 @@ namespace WZ
public string GetHighestPayingAdUnit() public string GetHighestPayingAdUnit()
{ {
string highestPayingAdUnit = null; string highestPayingAdUnit = null;
double highestRevenue = 0; double highestRevenue = -1;
foreach (var kvp in _adRevenueCache) foreach (var kvp in _adRevenueCache)
{ {

View File

@ -52,6 +52,7 @@ namespace WZ
} }
LoggerUtils.Debug("[Admob] appopen ad loaded with response : " + ad.GetResponseInfo().ToString()+" revenue:"+AdmobUtils.GetAppOpenAdEcpm(ad)); LoggerUtils.Debug("[Admob] appopen ad loaded with response : " + ad.GetResponseInfo().ToString()+" revenue:"+AdmobUtils.GetAppOpenAdEcpm(ad));
LoggerUtils.Debug("[Admob] appopen ad loaded with revenue : " + AdmobUtils.GetAppOpenAdEcpm(ad));
_appOpenAds[adUnitId] = ad; _appOpenAds[adUnitId] = ad;
_adRevenueCache[adUnitId] = AdmobUtils.GetAppOpenAdEcpm(ad); _adRevenueCache[adUnitId] = AdmobUtils.GetAppOpenAdEcpm(ad);
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Splash); AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Splash);

View File

@ -73,7 +73,7 @@ namespace WZ
private static readonly string[] BannerStack = { "zza", "zzj", "zzi", "zze", "zza", "zzk", "zzae" }; private static readonly string[] BannerStack = { "zza", "zzj", "zzi", "zze", "zza", "zzk", "zzae" };
private static readonly string[] SpStack = { "zzb", "zzi", "zze", "zze", "zzae" }; private static readonly string[] SpStack = { "zzb", "zza", "zzc", "zza", "zzk", "zzae" };
private static readonly string[] IvStack = { "zzc", "zzj", "zzf", "zzd", "zzae" }; private static readonly string[] IvStack = { "zzc", "zzj", "zzf", "zzd", "zzae" };
private static readonly string[] RvStack = { "zzb", "zzi", "zze", "zze", "zzae" }; private static readonly string[] RvStack = { "zzb", "zzi", "zze", "zze", "zzae" };
private static readonly string[] NaStack = { "zza", "zzb", "zzf", "zzD", "zzb", "zzae" }; private static readonly string[] NaStack = { "zza", "zzb", "zzf", "zzD", "zzb", "zzae" };

View File

@ -30,13 +30,13 @@ namespace WZ
public float _ivStartLoadTime = 0; public float _ivStartLoadTime = 0;
public string ClientName => "Kwai"; public string ClientName => "Kwai";
public PlatformType Platfrom => PlatformType.Kwai; public PlatformType Platfrom => PlatformType.Kwai;
public bool _initialized { get; private set; } = false; public bool _initialized { get; private set; } = false;
public bool _receivedReward = false;
public void Initialize() public void Initialize()
{ {
LoggerUtils.Debug("KwaiAdsManager Initialize start" + _appId + " token:" + _token + " rewardAdUnitId:" + _rewardAdUnitId + " interstitialAdUnitId:" + _interstitialAdUnitId); LoggerUtils.Debug("KwaiAdsManager Initialize start" + _appId + " token:" + _token + " rewardAdUnitId:" + _rewardAdUnitId + " interstitialAdUnitId:" + _interstitialAdUnitId);
if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_token)|| _initialized) return; if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_token) || _initialized) return;
var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder() var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder()
.SetAppId(_appId) .SetAppId(_appId)
.SetToken(_token) .SetToken(_token)

View File

@ -25,8 +25,9 @@ namespace WZ
AdsType.Rewarded, AdsType.Rewarded,
"", "",
KwaiAdsManager.Instance._rewardAdRevenue); KwaiAdsManager.Instance._rewardAdRevenue);
KwaiAdsManager.Instance._rvCloseCallback?.Invoke(true, KwaiAdsManager.Instance._rewardAdRevenue); KwaiAdsManager.Instance._rvCloseCallback?.Invoke(KwaiAdsManager.Instance._receivedReward, KwaiAdsManager.Instance._rewardAdRevenue);
KwaiAdsManager.Instance._rvCloseCallback = null; KwaiAdsManager.Instance._rvCloseCallback = null;
KwaiAdsManager.Instance._receivedReward = false;
KwaiAdsManager.Instance.LoadRewarded(); KwaiAdsManager.Instance.LoadRewarded();
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdClose"); LoggerUtils.Debug("[kwai] RewardAdListener#OnAdClose");
} }
@ -57,6 +58,7 @@ namespace WZ
{ {
// 获取到激励 | Reward earned // 获取到激励 | Reward earned
LoggerUtils.Debug("[kwai] RewardAdListener#OnRewardEarned"); LoggerUtils.Debug("[kwai] RewardAdListener#OnRewardEarned");
KwaiAdsManager.Instance._receivedReward = true;
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace WZ
public string _topon_rewarded_units; public string _topon_rewarded_units;
private string _rvPos; private string _rvPos;
private string _ivPos; private string _ivPos;
private Action<bool,double> _rvCloseCallback = null; private Action<bool, double> _rvCloseCallback = null;
private Action<double> _ivCloseCallback = null; private Action<double> _ivCloseCallback = null;
private Action _rvShowFailedCallback = null; private Action _rvShowFailedCallback = null;
public bool _initialized { get; private set; } = false; public bool _initialized { get; private set; } = false;
@ -64,7 +64,7 @@ namespace WZ
} }
public void LoadRewarded() { } public void LoadRewarded() { }
public void DisplayRewarded(string adPos, Action<bool,double> rewardCallback = null, Action showFailedCallback = null) public void DisplayRewarded(string adPos, Action<bool, double> rewardCallback = null, Action showFailedCallback = null)
{ {
_rvPos = adPos; _rvPos = adPos;
_rvCloseCallback = rewardCallback; _rvCloseCallback = rewardCallback;
@ -92,7 +92,7 @@ namespace WZ
ATInterstitialAutoAd.Instance.client.onAdShowFailureEvent += OnAdVideoFailureEvent; ATInterstitialAutoAd.Instance.client.onAdShowFailureEvent += OnAdVideoFailureEvent;
ATInterstitialAutoAd.Instance.client.onAdClickEvent += OnAdVideoClickedEvent; ATInterstitialAutoAd.Instance.client.onAdClickEvent += OnAdVideoClickedEvent;
ATInterstitialAutoAd.Instance.addAutoLoadAdPlacementID(new string[] { _topon_interstitial_units }); ATInterstitialAutoAd.Instance.addAutoLoadAdPlacementID(new string[] { _topon_interstitial_units });
AdsActionEvents.TrackAdStartLoad(Platfrom,"","",AdsType.Interstitial); AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Interstitial);
} }
public void LoadInterstitial() { } public void LoadInterstitial() { }
@ -114,20 +114,27 @@ namespace WZ
#region #region
private void OnAdLoadedEvent(object sender, ATAdEventArgs erg) private void OnAdLoadedEvent(object sender, ATAdEventArgs erg)
{ {
AdsActionEvents.TrackAdLoaded(Platfrom,
ClientName + "_" + erg.callbackInfo.network_firm_id,
erg.callbackInfo.adunit_id,
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
0);
if (erg.placementId.Equals(_topon_interstitial_units)) if (erg.placementId.Equals(_topon_interstitial_units))
{ {
LoggerUtils.Debug("[Tpn] ads tpn topon interstitial loaded"); LoggerUtils.Debug("[Tpn] ads tpn topon interstitial loaded");
var info = JsonUtility.FromJson<TopOnCallback>(ATInterstitialAutoAd.Instance.checkAutoAdStatus(erg.placementId));
AdsActionEvents.TrackAdLoaded(Platfrom,
ClientName + "_" + info.adInfo.network_firm_id,
info.adInfo.adunit_id,
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
0);
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial); AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
} }
else if (erg.placementId.Equals(_topon_rewarded_units)) else if (erg.placementId.Equals(_topon_rewarded_units))
{ {
LoggerUtils.Debug("[Tpn] ads tpn topon rewarded loaded"); LoggerUtils.Debug("[Tpn] ads tpn topon rewarded loaded");
var info = JsonUtility.FromJson<TopOnCallback>(ATRewardedAutoVideo.Instance.checkAutoAdStatus(erg.placementId));
AdsActionEvents.TrackAdLoaded(Platfrom,
ClientName + "_" + info.adInfo.network_firm_id,
info.adInfo.adunit_id,
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
0);
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded); AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded);
} }
} }
@ -314,5 +321,22 @@ namespace WZ
AdPlayCountManager.GetAdPlayCount(erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial)); AdPlayCountManager.GetAdPlayCount(erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial));
} }
#endregion #endregion
[Serializable]
public class TopOnCallback
{
public bool isLoading;
public bool isReady;
public TopOnCallbackInfo adInfo;
}
[Serializable]
public class TopOnCallbackInfo
{
public double publisher_revenue;
public string adunit_id;
public int network_firm_id;
}
} }
} }

View File

@ -18,10 +18,10 @@ public class AppSDKManager : D_MonoSingleton<AppSDKManager>
FileParse.Parse(); FileParse.Parse();
// AdConfigParser.Parse(); // AdConfigParser.Parse();
FireBaseSDKManager.Instance.Init(); FireBaseSDKManager.Instance.Init();
ShuShuMangage.Instance.Init();
AdmobAdsManager.Instance.RefreshAdsData(); AdmobAdsManager.Instance.RefreshAdsData();
AdmobAdsManager.Instance.Initialize(); AdmobAdsManager.Instance.Initialize();
AdjustManager.Instance.Init(); AdjustManager.Instance.Init();
ShuShuMangage.Instance.Init();
AdsSDKManager.Instance.InitSDK(action); AdsSDKManager.Instance.InitSDK(action);
EFSdkManager.Instance.Init(); EFSdkManager.Instance.Init();
} }

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using AnyThinkAds.ThirdParty.LitJson;
using ThinkingData.Analytics; using ThinkingData.Analytics;
namespace WZ namespace WZ
@ -11,6 +12,7 @@ namespace WZ
/// </summary> /// </summary>
public void UserSet(Dictionary<string, object> dic) public void UserSet(Dictionary<string, object> dic)
{ {
LoggerUtils.Debug("[shushu] userset:"+JsonMapper.ToJson(dic));
TDAnalytics.UserSet(dic); TDAnalytics.UserSet(dic);
} }
@ -20,6 +22,7 @@ namespace WZ
/// <param name="superProperties"></param> /// <param name="superProperties"></param>
public void SetSuperProperties(Dictionary<string, object> superProperties) public void SetSuperProperties(Dictionary<string, object> superProperties)
{ {
LoggerUtils.Debug("[shushu] public:"+JsonMapper.ToJson(superProperties));
TDAnalytics.SetSuperProperties(superProperties);//设置公共事件属性 TDAnalytics.SetSuperProperties(superProperties);//设置公共事件属性
} }

View File

@ -14,22 +14,6 @@ namespace WZ
TDAnalytics.Init(StaticValue.TDAppID, StaticValue.TDServerURL); TDAnalytics.Init(StaticValue.TDAppID, StaticValue.TDServerURL);
//开启自动采集事件 //开启自动采集事件
TDAnalytics.EnableAutoTrack(TDAutoTrackEventType.AppInstall | TDAutoTrackEventType.AppStart | TDAutoTrackEventType.AppEnd); TDAnalytics.EnableAutoTrack(TDAutoTrackEventType.AppInstall | TDAutoTrackEventType.AppStart | TDAutoTrackEventType.AppEnd);
//如果用户已登录可以设置用户的账号ID作为身份唯一标识
// TDAnalytics.Login("TA");
var userProperties = new Dictionary<string, object>();
userProperties.Add("ad_network", AdjustManager.GetAdNetwork());
userProperties.Add("campaign", AdjustManager.GetCampaign());
userProperties.Add("adgroup", AdjustManager.GetAdgroup());
userProperties.Add("creative", AdjustManager.GetCreative());
ShuShuEvent.Instance.UserSet(userProperties);
var publicProperties = new Dictionary<string, object>();
publicProperties.Add("user_ad_network", AdjustManager.GetAdNetwork());
publicProperties.Add("user_campaign", AdjustManager.GetCampaign());
publicProperties.Add("user_adgroup", AdjustManager.GetAdgroup());
publicProperties.Add("user_creative", AdjustManager.GetCreative());
AppSDKManager.Instance.SetSuperProperties(publicProperties);
} }
} }