SDK_UnityMoney/Assets/Script/SDKManager/AdjustManager/AdjustManager.cs

126 lines
3.7 KiB
C#
Raw Normal View History

2025-08-30 10:46:34 +00:00
using System.Collections;
using System.Collections.Generic;
using AdjustSdk;
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
{
private AdjustEnvironment environment = AdjustEnvironment.Sandbox; // 测试用Sandbox发布用Production
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-03 03:45:52 +00:00
private string _adNetwork = "_adNetwork";
private string _campaign = "_campaign";
private string _adgroup = "_adgroup";
private string _creative = "_creative";
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-03 03:45:52 +00:00
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-08-31 05:48:26 +00:00
//计时3分钟
AppSDKManager.Instance.Coroutine(AdjustNetwork.Instance.SetOrganic3Min());
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-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-08-31 03:55:05 +00:00
AdjustNetwork.Instance.SetNetwork(attribution.Network);
2025-09-03 03:45:52 +00:00
SaveProperties(attribution);
2025-09-03 05:59:24 +00:00
var properties = new Dictionary<string, object>();
properties.Add("ad_network", AdjustManager.GetAdNetwork());
properties.Add("campaign", AdjustManager.GetCampaign());
properties.Add("adgroup", AdjustManager.GetAdgroup());
properties.Add("creative", AdjustManager.GetCreative());
ShuShuEvent.Instance.UserSet(properties);
AppSDKManager.Instance.SetSuperProperties(properties);
2025-09-03 03:45:52 +00:00
}
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()
{
return PlayerPrefsUtils.GetPlayerPrefsString(AdjustManager.Instance._adNetwork, "");
}
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, "");
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
}