Compare commits

..

4 Commits

Author SHA1 Message Date
胡宇飞 5c1f73fc18 update: 完善 AdjustId 的缓存机制和二次上报机制
Signed-off-by: huyufei <yufei.hu@castbox.fm>
2024-07-17 09:57:44 +08:00
胡宇飞 8a81ed78b4 update: 修正 AdjustID 获取的回调和时机
--story=1020639 --user=yufei.hu 【Unity】-【BI】Firebase 数据新增上报用户属性 adjust_id https://www.tapd.cn/58098289/s/1157505

Signed-off-by: huyufei <yufei.hu@castbox.fm>
2024-07-16 21:04:46 +08:00
胡宇飞 76fc4f5c26 update: 上报Firebase用户属性 adjust_id
--story=1020972 --user=yufei.hu 【中台】【SDK】新增 Firebase 用户属性打点: adjust_id https://www.tapd.cn/33527076/s/1157507

Signed-off-by: huyufei <yufei.hu@castbox.fm>
2024-07-16 19:19:04 +08:00
胡宇飞 72bf076537 fix: 广告 SDK 优化广告重试时间 从最高间隔 8 秒 -> 64 秒, 减少无网时高频请求
--story=1020971 --user=yufei.hu 【中台】【ADS】优化 IV 和 RV 广告加载失败后的重试等待时间 https://www.tapd.cn/33527076/s/1157502

Signed-off-by: huyufei <yufei.hu@castbox.fm>
2024-07-16 18:46:16 +08:00
3 changed files with 56 additions and 32 deletions

View File

@ -1,11 +1,14 @@
namespace Guru
{
using UnityEngine;
using com.adjust.sdk;
using System;
using System.Collections;
public static class AdjustService
public class AdjustService
{
public const string Version = "1.6.1";
public const string AdjustVersion = "4.38.0"; // Adjust SDK Version
@ -15,6 +18,8 @@ namespace Guru
public const string K_IAP_PURCHASE = "iap_purchase"; // 固定点位事件
public const string K_SUB_PURCHASE = "sub_purchase"; // 固定点位事件
private static Action<string> _onSessionSuccessCallback;
private static string _adId = "";
public static string AdId
@ -45,7 +50,7 @@ namespace Guru
/// </summary>
/// <param name="appToken"></param>
/// <param name="fbAppId">MIR 追踪 AppID</param>
public static void StartService(string appToken, string fbAppId = "")
public static void StartService(string appToken, string fbAppId = "", Action<string> onSessionSuccess = null)
{
if (string.IsNullOrEmpty(appToken))
{
@ -53,6 +58,8 @@ namespace Guru
return;
}
_onSessionSuccessCallback = onSessionSuccess;
InstallEvent(IPMConfig.FIREBASE_ID, IPMConfig.IPM_DEVICE_ID); // 注入启动参数
AdjustEnvironment environment = GetAdjustEnvironment();
@ -61,6 +68,7 @@ namespace Guru
config.setDelayStart(DelayTime);
config.setPreinstallTrackingEnabled(true); // Adjust Preinstall
config.setSessionSuccessDelegate(OnSessionSuccessCallback); // SessionSuccess
#if UNITY_ANDROID
if (!string.IsNullOrEmpty(fbAppId)) config.setFbAppId(fbAppId); // 注入 MIR ID
@ -71,7 +79,7 @@ namespace Guru
config.setLogDelegate(log => LogI(LOG_TAG, log));
config.setEventSuccessDelegate(OnEventSuccessCallback);
config.setEventFailureDelegate(OnEventFailureCallback);
config.setSessionSuccessDelegate(OnSessionSuccessCallback);
config.setSessionFailureDelegate(OnSessionFailureCallback);
config.setAttributionChangedDelegate(OnAttributionChangedCallback);
#endif
@ -272,27 +280,10 @@ namespace Guru
private static void OnSessionSuccessCallback(AdjustSessionSuccess sessionSuccessData)
{
LogI(LOG_TAG,"Session tracked successfully!");
LogI(LOG_TAG,$"{LOG_TAG} --- Session tracked successfully!");
if (sessionSuccessData.Message != null)
{
LogI(LOG_TAG,"Message: " + sessionSuccessData.Message);
}
if (sessionSuccessData.Timestamp != null)
{
LogI(LOG_TAG,"Timestamp: " + sessionSuccessData.Timestamp);
}
if (sessionSuccessData.Adid != null)
{
LogI(LOG_TAG, "Adid: " + sessionSuccessData.Adid);
}
if (sessionSuccessData.JsonResponse != null)
{
LogI(LOG_TAG, "JsonResponse: " + sessionSuccessData.GetJsonResponse());
}
var adid = sessionSuccessData.Adid;
_onSessionSuccessCallback?.Invoke(adid);
}
private static void OnSessionFailureCallback(AdjustSessionFailure sessionFailureData)

View File

@ -22,6 +22,8 @@ namespace Guru
public bool IsInitialized => MaxSdk.IsInitialized() || _isServiceStarted;
protected bool IsNetworkEnabled => Application.internetReachability != NetworkReachability.NotReachable;
private const int MAX_ADS_RELOAD_INTERVAL = 6; // 广告加载最高时间为 2 的 6 次方 = 64秒
private bool _isServiceStarted;
protected Action _onSdkInitReady;
@ -149,6 +151,13 @@ namespace Guru
set => Model.BuyNoAds = value;
}
private float GetRetryDelaySeconds(int retryCount)
{
// 最低 2^retryCount 秒
// 最高 2^6 = 64 秒
return (float)Math.Pow(2, Math.Min(MAX_ADS_RELOAD_INTERVAL, retryCount));
}
#region Lifecycele
public void OnAppPaused(bool paused)
@ -511,8 +520,8 @@ namespace Guru
this.LogError(
$"OnInterstitialFailedEvent AdLoadFailureInfo:{errorInfo.AdLoadFailureInfo}, Message: {errorInfo.Message}");
_interstitialRetryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(3, _interstitialRetryAttempt));
DelayCall((float)retryDelay, RequestInterstitialAD);
float retryDelay = GetRetryDelaySeconds(_interstitialRetryAttempt);
DelayCall(retryDelay, RequestInterstitialAD);
// Analytics.ADIadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory);
Analytics.ADIadsFailed(AdParams.Build(adUnitId,
duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory,
@ -669,8 +678,8 @@ namespace Guru
errorCode: (int)errorInfo.Code,
waterfallName: errorInfo?.WaterfallInfo?.Name ?? ""));
_rewardRetryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(3, _rewardRetryAttempt));
DelayCall((float)retryDelay, RequestRewardedAD);
float retryDelay = GetRetryDelaySeconds(_rewardRetryAttempt);
DelayCall(retryDelay, RequestRewardedAD);
OnRewardFailed?.Invoke();
}

View File

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using Firebase;
using Firebase.Analytics;
using Firebase.Extensions;
using UnityEngine;
namespace Guru
{
@ -117,10 +117,34 @@ namespace Guru
// 启动 AdjustService
string appToken = GuruSettings.Instance.AdjustSetting?.GetAppToken() ?? "";
string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId;
AdjustService.StartService(appToken, fbAppId);
if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID))
{
ReportAdjustId(IPMConfig.ADJUST_ID); // 二次启动后,若有值则立即上报属性
}
AdjustService.StartService(appToken, fbAppId, adjustId =>
{
// 获取 ADID
if (string.IsNullOrEmpty(adjustId))
{
adjustId = "not_set";
}
else
{
IPMConfig.ADJUST_ID = adjustId;
}
ReportAdjustId(adjustId);
});
});
}
private static void ReportAdjustId(string adjustId)
{
FirebaseAnalytics.SetUserProperty("adjust_id", adjustId); // 仅上报 Firebase 用户属性
Debug.Log($"[SDK] --- Firebase + Adjust ID: {adjustId}");
}