2025-09-04 06:24:18 +00:00
|
|
|
using System;
|
2025-08-30 10:46:34 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2025-09-04 06:24:18 +00:00
|
|
|
using System.Threading.Tasks;
|
2025-08-30 10:46:34 +00:00
|
|
|
using AdjustSdk;
|
2025-09-05 07:42:51 +00:00
|
|
|
using ThinkingData.Analytics;
|
2025-08-30 10:46:34 +00:00
|
|
|
using Unity.VisualScripting;
|
|
|
|
using UnityEngine;
|
2025-09-01 10:32:50 +00:00
|
|
|
using WZ;
|
2025-08-30 10:46:34 +00:00
|
|
|
|
2025-09-02 09:14:49 +00:00
|
|
|
public class AdjustManager : D_MonoSingleton<AdjustManager>
|
2025-08-30 10:46:34 +00:00
|
|
|
{
|
2025-09-04 06:24:18 +00:00
|
|
|
private AdjustEnvironment environment = AdjustEnvironment.Production;
|
2025-08-30 10:46:34 +00:00
|
|
|
|
2025-09-02 03:45:05 +00:00
|
|
|
private long startTime = 0;
|
2025-09-02 09:36:19 +00:00
|
|
|
private string Adid;
|
|
|
|
private string Gdid;
|
2025-09-04 06:24:18 +00:00
|
|
|
private string callbackNetwork = "";
|
|
|
|
bool m_start = false;
|
|
|
|
private int callGetTimes = 0;
|
2025-09-02 09:36:19 +00:00
|
|
|
|
2025-08-31 03:55:05 +00:00
|
|
|
public void Init()
|
2025-08-30 10:46:34 +00:00
|
|
|
{
|
2025-09-02 03:45:05 +00:00
|
|
|
//开始计时
|
|
|
|
startTime = TimeUtils.GetLocalTimestamp();
|
2025-09-05 07:42:51 +00:00
|
|
|
Adjust.AddGlobalCallbackParameter("ta_distinct_id", TDAnalytics.GetDistinctId());
|
2025-09-02 09:50:19 +00:00
|
|
|
AdjustConfig config = new AdjustConfig(StaticValue.AdjustToken, environment);
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-08-30 10:46:34 +00:00
|
|
|
// 设置归因变更回调函数
|
|
|
|
config.AttributionChangedDelegate = AttributionChangedDelegate;
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-08-30 10:46:34 +00:00
|
|
|
// (可选)设置其他配置,如日志级别
|
|
|
|
config.LogLevel = AdjustLogLevel.Verbose;
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-08-30 10:46:34 +00:00
|
|
|
// 初始化Adjust SDK
|
|
|
|
Adjust.InitSdk(config);
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-09-02 09:36:19 +00:00
|
|
|
//id
|
|
|
|
LoadAdid();
|
|
|
|
LoadGaid();
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-09-02 03:45:05 +00:00
|
|
|
ShuShuEvent.Instance.Track("adjust_init");
|
|
|
|
FireBaseAnalyticsManager.Instance.LogEvent("adjust_init");
|
2025-08-30 10:46:34 +00:00
|
|
|
}
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-09-04 06:24:18 +00:00
|
|
|
|
2025-08-30 10:46:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// 归因信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="attribution"></param>
|
2025-09-03 03:45:52 +00:00
|
|
|
private void AttributionChangedDelegate(AdjustAttribution attribution)
|
2025-08-30 10:46:34 +00:00
|
|
|
{
|
2025-09-03 03:45:52 +00:00
|
|
|
Debug.Log("Attribution changed network: " + attribution.Network + " campaign: " + attribution.Campaign + " adgroup: " + attribution.Adgroup + " creative: " + attribution.Creative);
|
2025-09-04 06:24:18 +00:00
|
|
|
if (m_start) return;
|
|
|
|
m_start = true;
|
|
|
|
callbackNetwork = attribution.Network;
|
|
|
|
if (IsOrganic(attribution.Network) == false)
|
|
|
|
{
|
|
|
|
OnReceiveCallback(attribution);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
InvokeRepeating(nameof(CallGetAttributionAsync), 0, 1);
|
2025-09-03 03:45:52 +00:00
|
|
|
}
|
|
|
|
|
2025-09-04 06:24:18 +00:00
|
|
|
private async Task CallGetAttributionAsync()
|
2025-09-03 03:45:52 +00:00
|
|
|
{
|
2025-09-04 06:24:18 +00:00
|
|
|
callGetTimes++;
|
2025-09-03 03:45:52 +00:00
|
|
|
|
2025-09-04 06:24:18 +00:00
|
|
|
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));
|
|
|
|
}
|
2025-09-03 03:45:52 +00:00
|
|
|
}
|
|
|
|
|
2025-09-04 06:24:18 +00:00
|
|
|
public static Task<AdjustAttribution> GetAttributionAsync()
|
2025-09-03 03:45:52 +00:00
|
|
|
{
|
2025-09-04 06:24:18 +00:00
|
|
|
var tcs = new TaskCompletionSource<AdjustAttribution>();
|
|
|
|
|
|
|
|
Adjust.GetAttribution(attribution =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tcs.TrySetResult(attribution);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
tcs.TrySetException(ex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return tcs.Task;
|
2025-09-03 03:45:52 +00:00
|
|
|
}
|
|
|
|
|
2025-09-04 06:24:18 +00:00
|
|
|
private void OnReceiveCallback(AdjustAttribution attribution)
|
2025-09-03 03:45:52 +00:00
|
|
|
{
|
2025-09-04 06:24:18 +00:00
|
|
|
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.LogEventGetSuccess();
|
|
|
|
ShuShuEvent.Instance.UserSet(new Dictionary<string, object>
|
|
|
|
{
|
|
|
|
{ "user_ad_network", network ?? "" },
|
|
|
|
{ "user_campaign", campaign ?? "" },
|
|
|
|
{ "user_adgroup", adgroup ?? "" },
|
|
|
|
{ "user_creative", creative ?? "" },
|
|
|
|
});
|
|
|
|
|
2025-09-08 05:37:51 +00:00
|
|
|
RushSDKManager.Instance.SetSuperProperties(new Dictionary<string, object>
|
2025-09-04 06:24:18 +00:00
|
|
|
{
|
|
|
|
{ "ad_network", network ?? "" },
|
|
|
|
{ "campaign", campaign ?? "" },
|
|
|
|
{ "adgroup", adgroup ?? "" },
|
|
|
|
{ "creative", creative ?? "" },
|
|
|
|
});
|
2025-09-03 03:45:52 +00:00
|
|
|
}
|
|
|
|
|
2025-09-04 06:24:18 +00:00
|
|
|
|
|
|
|
private bool IsOrganic(string _network)
|
2025-09-03 03:45:52 +00:00
|
|
|
{
|
2025-09-04 06:24:18 +00:00
|
|
|
if (_network.Equals("Organic") || _network.Equals("Untrusted Devices") || _network.Equals(""))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2025-08-30 10:46:34 +00:00
|
|
|
}
|
2025-09-02 03:45:05 +00:00
|
|
|
|
|
|
|
public long GetStartTime()
|
|
|
|
{
|
|
|
|
return startTime;
|
|
|
|
}
|
2025-08-30 10:46:34 +00:00
|
|
|
|
2025-09-02 09:36:19 +00:00
|
|
|
private void LoadGaid()
|
|
|
|
{
|
|
|
|
Adjust.GetGoogleAdId(googleAdId => {
|
|
|
|
Gdid = googleAdId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetGdid()
|
|
|
|
{
|
|
|
|
return Gdid;
|
|
|
|
}
|
2025-08-30 10:46:34 +00:00
|
|
|
|
2025-09-02 09:36:19 +00:00
|
|
|
private void LoadAdid()
|
|
|
|
{
|
|
|
|
Adjust.GetAdid(adid =>
|
|
|
|
{
|
|
|
|
Adid = adid;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetAdid()
|
|
|
|
{
|
|
|
|
return Adid;
|
|
|
|
}
|
2025-08-30 10:46:34 +00:00
|
|
|
}
|