fix:1、接入外部sdk
This commit is contained in:
@@ -1,152 +1,152 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AppsFlyerSDK;
|
||||
using RedHotRoast;
|
||||
using DG.Tweening;
|
||||
using SGModule.Common.Helper;
|
||||
using SGModule.Net;
|
||||
using SGModule.NetKit;
|
||||
using Unity.Advertisement.IosSupport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace IgnoreOPS {
|
||||
internal class AppsFlyerObjectScript1 : MonoBehaviour, IAppsFlyerConversionData {
|
||||
public string appID;
|
||||
public bool is_init;
|
||||
public Coroutine m_Coroutine;
|
||||
|
||||
void Start() {
|
||||
AddListener();
|
||||
|
||||
AppsFlyer.setIsDebug(true);
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
appID = "6749253378";
|
||||
m_Coroutine = CrazyAsyKit.StartCoroutine(loopWaitInitAf());
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void AddListener() {
|
||||
NetworkDispatcher.Instance.AddListener(NetworkMsg.NotNetwork, RequestLogin);
|
||||
}
|
||||
|
||||
private void RemoveListener() {
|
||||
NetworkDispatcher.Instance.RemoveListener(NetworkMsg.NotNetwork, RequestLogin);
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
RemoveListener();
|
||||
}
|
||||
|
||||
void RequestLogin(object obj = null) {
|
||||
if (GameHelper.IsConnect()) {
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Network_reconnection);
|
||||
}
|
||||
|
||||
CrazyAsyKit.StopCoroutine(m_Coroutine);
|
||||
|
||||
m_Coroutine = CrazyAsyKit.StartCoroutine(loopWaitInitAf());
|
||||
}
|
||||
|
||||
private IEnumerator loopWaitInitAf() {
|
||||
|
||||
var isConnect = GameHelper.IsConnect();
|
||||
if (!isConnect)
|
||||
{
|
||||
float retryTime = 0f;
|
||||
const float maxRetryTime = 3f;
|
||||
|
||||
while (!GameHelper.IsConnect() && retryTime < maxRetryTime)
|
||||
{
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
retryTime += 0.2f;
|
||||
}
|
||||
|
||||
// 再次确认网络状态
|
||||
isConnect = GameHelper.IsConnect();
|
||||
|
||||
Log.Info("AF",$"[AF] loopWaitInitAf------1-- {isConnect}");
|
||||
|
||||
if (!isConnect)
|
||||
{
|
||||
// 超时且仍未连接,触发无网络提示
|
||||
Action action = () => {
|
||||
TimerHelper.mEasy.AddTimer(0.5f, () => {
|
||||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.NotNetwork);
|
||||
});
|
||||
};
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.TipsViewUI_Open, action);
|
||||
}
|
||||
}
|
||||
|
||||
Log.Info("AF",$"[AF] loopWaitInitAf------2-- {isConnect}");
|
||||
|
||||
if (isConnect)
|
||||
{
|
||||
TrackKit.TrackLoginFunnel(LoginFunnelEventType.AfSend);
|
||||
|
||||
float a = 0;
|
||||
if (ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
|
||||
ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
|
||||
{
|
||||
ATTrackingStatusBinding.RequestAuthorizationTracking();
|
||||
}
|
||||
|
||||
while ((ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
|
||||
ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED) && (a < 5.0f))
|
||||
{
|
||||
a += 0.5f;
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
}
|
||||
|
||||
AppsFlyer.initSDK("3e36AQrQTJWsVebUrLpexJ", appID, this);
|
||||
AppsFlyer.startSDK();
|
||||
AppsFlyer.AFLog("8888888888888888888",
|
||||
ATTrackingStatusBinding.GetAuthorizationTrackingStatus().ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onConversionDataSuccess(string conversionData) {
|
||||
Log.Info("AF",$"[AF] onConversionDataSuccess-------- {is_init}");
|
||||
if (is_init) return;
|
||||
is_init = true;
|
||||
AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
|
||||
var conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
|
||||
var json = SerializeUtil.ToJsonIndented(conversionDataDictionary);
|
||||
SuperApplication.Instance.attribution =
|
||||
conversionDataDictionary.TryGetValue("af_status", out var afStatus)
|
||||
? afStatus.ToString().ToLower()
|
||||
: "organic";
|
||||
|
||||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
|
||||
TrackKit.TrackLoginFunnel(LoginFunnelEventType.AfRecv, "success");
|
||||
}
|
||||
|
||||
public void onConversionDataFail(string error) {
|
||||
Log.Info("AF",$"[AF] onConversionDataFail-------- {is_init}");
|
||||
if (is_init) return;
|
||||
is_init = true;
|
||||
AppsFlyer.AFLog("onConversionDataFail", error);
|
||||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
|
||||
TrackKit.TrackLoginFunnel(LoginFunnelEventType.AfRecv, "fail");
|
||||
}
|
||||
|
||||
public void onAppOpenAttribution(string attributionData) {
|
||||
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
|
||||
Dictionary<string, object> attributionDataDictionary =
|
||||
AppsFlyer.CallbackStringToDictionary(attributionData);
|
||||
}
|
||||
|
||||
public void onAppOpenAttributionFailure(string error) {
|
||||
AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
// using System;
|
||||
// using System.Collections;
|
||||
// using System.Collections.Generic;
|
||||
// using AppsFlyerSDK;
|
||||
// using RedHotRoast;
|
||||
// using DG.Tweening;
|
||||
// using SGModule.Common.Helper;
|
||||
// using SGModule.Net;
|
||||
// using SGModule.NetKit;
|
||||
// using Unity.Advertisement.IosSupport;
|
||||
// using UnityEngine;
|
||||
//
|
||||
// namespace IgnoreOPS {
|
||||
// internal class AppsFlyerObjectScript1 : MonoBehaviour, IAppsFlyerConversionData {
|
||||
// public string appID;
|
||||
// public bool is_init;
|
||||
// public Coroutine m_Coroutine;
|
||||
//
|
||||
// void Start() {
|
||||
// AddListener();
|
||||
//
|
||||
// AppsFlyer.setIsDebug(true);
|
||||
// #if UNITY_IOS && !UNITY_EDITOR
|
||||
// appID = "6749253378";
|
||||
// m_Coroutine = CrazyAsyKit.StartCoroutine(loopWaitInitAf());
|
||||
// #endif
|
||||
//
|
||||
//
|
||||
// #if UNITY_EDITOR
|
||||
// NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// private void AddListener() {
|
||||
// NetworkDispatcher.Instance.AddListener(NetworkMsg.NotNetwork, RequestLogin);
|
||||
// }
|
||||
//
|
||||
// private void RemoveListener() {
|
||||
// NetworkDispatcher.Instance.RemoveListener(NetworkMsg.NotNetwork, RequestLogin);
|
||||
// }
|
||||
//
|
||||
// void OnDestroy() {
|
||||
// RemoveListener();
|
||||
// }
|
||||
//
|
||||
// void RequestLogin(object obj = null) {
|
||||
// if (GameHelper.IsConnect()) {
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.Network_reconnection);
|
||||
// }
|
||||
//
|
||||
// CrazyAsyKit.StopCoroutine(m_Coroutine);
|
||||
//
|
||||
// m_Coroutine = CrazyAsyKit.StartCoroutine(loopWaitInitAf());
|
||||
// }
|
||||
//
|
||||
// private IEnumerator loopWaitInitAf() {
|
||||
//
|
||||
// var isConnect = GameHelper.IsConnect();
|
||||
// if (!isConnect)
|
||||
// {
|
||||
// float retryTime = 0f;
|
||||
// const float maxRetryTime = 3f;
|
||||
//
|
||||
// while (!GameHelper.IsConnect() && retryTime < maxRetryTime)
|
||||
// {
|
||||
// yield return new WaitForSeconds(0.2f);
|
||||
// retryTime += 0.2f;
|
||||
// }
|
||||
//
|
||||
// // 再次确认网络状态
|
||||
// isConnect = GameHelper.IsConnect();
|
||||
//
|
||||
// Log.Info("AF",$"[AF] loopWaitInitAf------1-- {isConnect}");
|
||||
//
|
||||
// if (!isConnect)
|
||||
// {
|
||||
// // 超时且仍未连接,触发无网络提示
|
||||
// Action action = () => {
|
||||
// TimerHelper.mEasy.AddTimer(0.5f, () => {
|
||||
// NetworkDispatcher.Instance.Dispatch(NetworkMsg.NotNetwork);
|
||||
// });
|
||||
// };
|
||||
// UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.TipsViewUI_Open, action);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Log.Info("AF",$"[AF] loopWaitInitAf------2-- {isConnect}");
|
||||
//
|
||||
// if (isConnect)
|
||||
// {
|
||||
// TrackKit.TrackLoginFunnel(LoginFunnelEventType.AfSend);
|
||||
//
|
||||
// float a = 0;
|
||||
// if (ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
|
||||
// ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
|
||||
// {
|
||||
// ATTrackingStatusBinding.RequestAuthorizationTracking();
|
||||
// }
|
||||
//
|
||||
// while ((ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
|
||||
// ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED) && (a < 5.0f))
|
||||
// {
|
||||
// a += 0.5f;
|
||||
// yield return new WaitForSeconds(0.5f);
|
||||
// }
|
||||
//
|
||||
// AppsFlyer.initSDK("3e36AQrQTJWsVebUrLpexJ", appID, this);
|
||||
// AppsFlyer.startSDK();
|
||||
// AppsFlyer.AFLog("8888888888888888888",
|
||||
// ATTrackingStatusBinding.GetAuthorizationTrackingStatus().ToString());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void onConversionDataSuccess(string conversionData) {
|
||||
// Log.Info("AF",$"[AF] onConversionDataSuccess-------- {is_init}");
|
||||
// if (is_init) return;
|
||||
// is_init = true;
|
||||
// AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
|
||||
// var conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
|
||||
// var json = SerializeUtil.ToJsonIndented(conversionDataDictionary);
|
||||
// SuperApplication.Instance.attribution =
|
||||
// conversionDataDictionary.TryGetValue("af_status", out var afStatus)
|
||||
// ? afStatus.ToString().ToLower()
|
||||
// : "organic";
|
||||
//
|
||||
// NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
//
|
||||
// TrackKit.TrackLoginFunnel(LoginFunnelEventType.AfRecv, "success");
|
||||
// }
|
||||
//
|
||||
// public void onConversionDataFail(string error) {
|
||||
// Log.Info("AF",$"[AF] onConversionDataFail-------- {is_init}");
|
||||
// if (is_init) return;
|
||||
// is_init = true;
|
||||
// AppsFlyer.AFLog("onConversionDataFail", error);
|
||||
// NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
//
|
||||
// TrackKit.TrackLoginFunnel(LoginFunnelEventType.AfRecv, "fail");
|
||||
// }
|
||||
//
|
||||
// public void onAppOpenAttribution(string attributionData) {
|
||||
// AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
|
||||
// Dictionary<string, object> attributionDataDictionary =
|
||||
// AppsFlyer.CallbackStringToDictionary(attributionData);
|
||||
// }
|
||||
//
|
||||
// public void onAppOpenAttributionFailure(string error) {
|
||||
// AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
+158
-158
@@ -1,159 +1,159 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class BIManager : MonoBehaviour
|
||||
{
|
||||
private static BIManager _instance;
|
||||
public static BIManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
var go = new GameObject("BIManager");
|
||||
DontDestroyOnLoad(go);
|
||||
_instance = go.AddComponent<BIManager>();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
// ================= 通用埋点 =================
|
||||
public void TrackEvent(string eventName, Dictionary<string, object> properties = null)
|
||||
{
|
||||
if (properties == null)
|
||||
properties = new Dictionary<string, object>();
|
||||
|
||||
// DataEyeAnalyticsAPI.Track(eventName, properties);
|
||||
// DataEyeAnalyticsAPI.Flush();
|
||||
#if UNITY_IOS&&!UNITY_EDITOR
|
||||
BrigdeIOS.TrackProduct(eventName, JsonConvert.SerializeObject(properties));
|
||||
#endif
|
||||
Debug.Log($"[BI] 事件上报: {eventName}, 属性={JsonConvert.SerializeObject(properties)}");
|
||||
}
|
||||
|
||||
// ================= 预制事件封装 =================
|
||||
|
||||
/// <summary>
|
||||
/// 上报广告事件
|
||||
/// </summary>
|
||||
/// <param name="eventName"></param>
|
||||
/// <param name="adType">Native,RewardedVideo,Banner,Interstitial,Splash</param>
|
||||
/// <param name="placementId">聚合广告位id</param>
|
||||
/// <param name="networkFirmId">广告网络ID</param>
|
||||
public void TrackAdEvent(string eventName, string adType, string placementId = null,
|
||||
string networkFirmId = null, double revenue = 0, string scene = null, string currency = "USD")
|
||||
{
|
||||
var props = new Dictionary<string, object>
|
||||
{
|
||||
{ "ad_type", adType }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(placementId))
|
||||
props["PlacementId"] = placementId;
|
||||
|
||||
if (!string.IsNullOrEmpty(networkFirmId))
|
||||
props["NetworkFirmId"] = networkFirmId;
|
||||
|
||||
if (revenue > 0)
|
||||
{
|
||||
props["Revenue"] = revenue;
|
||||
props["Ecpm"] = revenue * 1000;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(scene))
|
||||
props["scene"] = scene;
|
||||
|
||||
if (!string.IsNullOrEmpty(currency))
|
||||
props["Currency"] = currency;
|
||||
|
||||
|
||||
TrackEvent(eventName, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上报内购事件
|
||||
/// </summary>
|
||||
/// <param name="revenue">收入</param>
|
||||
/// <param name="currency">币种</param>
|
||||
/// <param name="payType">支付方式 0=商店支付,1=三方支付</param>
|
||||
/// <param name="itemId">sku</param>
|
||||
/// <param name="status">order:下单 paid:付费成功 paid_err:扣款失败</param>
|
||||
/// <param name="itemName">商品名称</param>
|
||||
/// <param name="msg">如果遇到异常或相关情况,将err_msg进行上报</param>
|
||||
public void TrackPurchase(double revenue, string currency, string payType, string itemId,
|
||||
string status, string itemName = null, string msg = null)
|
||||
{
|
||||
var props = new Dictionary<string, object>
|
||||
{
|
||||
{ "Revenue", revenue },
|
||||
{ "Currency", currency },
|
||||
{ "type", payType },
|
||||
{ "item_id", itemId },
|
||||
{ "purchase_status", status }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(itemName))
|
||||
props["item_name"] = itemName;
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
props["msg"] = msg;
|
||||
|
||||
TrackEvent(BIEvent.PURCHASE, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上报页面浏览
|
||||
/// </summary>
|
||||
public void TrackPageView(string pageName)
|
||||
{
|
||||
var props = new Dictionary<string, object>
|
||||
{
|
||||
{ "page_name", pageName } // 例如 "loading"、"game"
|
||||
};
|
||||
|
||||
TrackEvent(BIEvent.PAGE_VIEW, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AB 分组埋点
|
||||
/// </summary>
|
||||
public void TrackABConfig(int responseTime)
|
||||
{
|
||||
var props = new Dictionary<string, object>
|
||||
{
|
||||
{ "response_time", responseTime }
|
||||
};
|
||||
|
||||
TrackEvent(BIEvent.AB_CONFIG, props);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class BIEvent
|
||||
{
|
||||
// 自动采集(SDK 开启自动采集即可,不需要手动埋点)
|
||||
public const string APP_INSTALL = "app_install";
|
||||
public const string APP_START = "app_start";
|
||||
public const string APP_END = "app_end";
|
||||
public const string APP_VIEW = "app_view";
|
||||
public const string APP_CRASH = "app_crash";
|
||||
|
||||
// 内部预制事件
|
||||
public const string AD_REQUEST = "ad_request"; // 广告请求
|
||||
public const string AD_INVENTORY = "ad_inventory"; // 广告填充的时候
|
||||
public const string AD_IMP = "ad_imp"; // 广告展示
|
||||
public const string AD_CLICK = "ad_click"; // 广告点击
|
||||
|
||||
public const string PURCHASE = "purchase"; // 内购
|
||||
|
||||
// 页面相关
|
||||
public const string PAGE_VIEW = "page_view_customize";
|
||||
|
||||
// 其他业务事件(AB 测试等)
|
||||
public const string AB_CONFIG = "config"; // AB
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class BIManager : MonoBehaviour
|
||||
{
|
||||
private static BIManager _instance;
|
||||
public static BIManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
var go = new GameObject("BIManager");
|
||||
DontDestroyOnLoad(go);
|
||||
_instance = go.AddComponent<BIManager>();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
// ================= 通用埋点 =================
|
||||
public void TrackEvent(string eventName, Dictionary<string, object> properties = null)
|
||||
{
|
||||
if (properties == null)
|
||||
properties = new Dictionary<string, object>();
|
||||
|
||||
// DataEyeAnalyticsAPI.Track(eventName, properties);
|
||||
// DataEyeAnalyticsAPI.Flush();
|
||||
#if UNITY_IOS&&!UNITY_EDITOR
|
||||
BrigdeIOS.TrackProduct(eventName, JsonConvert.SerializeObject(properties));
|
||||
#endif
|
||||
Debug.Log($"[BI] 事件上报: {eventName}, 属性={JsonConvert.SerializeObject(properties)}");
|
||||
}
|
||||
|
||||
// ================= 预制事件封装 =================
|
||||
|
||||
/// <summary>
|
||||
/// 上报广告事件
|
||||
/// </summary>
|
||||
/// <param name="eventName"></param>
|
||||
/// <param name="adType">Native,RewardedVideo,Banner,Interstitial,Splash</param>
|
||||
/// <param name="placementId">聚合广告位id</param>
|
||||
/// <param name="networkFirmId">广告网络ID</param>
|
||||
public void TrackAdEvent(string eventName, string adType, string placementId = null,
|
||||
string networkFirmId = null, double revenue = 0, string scene = null, string currency = "USD")
|
||||
{
|
||||
// var props = new Dictionary<string, object>
|
||||
// {
|
||||
// { "ad_type", adType }
|
||||
// };
|
||||
//
|
||||
// if (!string.IsNullOrEmpty(placementId))
|
||||
// props["PlacementId"] = placementId;
|
||||
//
|
||||
// if (!string.IsNullOrEmpty(networkFirmId))
|
||||
// props["NetworkFirmId"] = networkFirmId;
|
||||
//
|
||||
// if (revenue > 0)
|
||||
// {
|
||||
// props["Revenue"] = revenue;
|
||||
// props["Ecpm"] = revenue * 1000;
|
||||
// }
|
||||
//
|
||||
// if (!string.IsNullOrEmpty(scene))
|
||||
// props["scene"] = scene;
|
||||
//
|
||||
// if (!string.IsNullOrEmpty(currency))
|
||||
// props["Currency"] = currency;
|
||||
//
|
||||
//
|
||||
// TrackEvent(eventName, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上报内购事件
|
||||
/// </summary>
|
||||
/// <param name="revenue">收入</param>
|
||||
/// <param name="currency">币种</param>
|
||||
/// <param name="payType">支付方式 0=商店支付,1=三方支付</param>
|
||||
/// <param name="itemId">sku</param>
|
||||
/// <param name="status">order:下单 paid:付费成功 paid_err:扣款失败</param>
|
||||
/// <param name="itemName">商品名称</param>
|
||||
/// <param name="msg">如果遇到异常或相关情况,将err_msg进行上报</param>
|
||||
public void TrackPurchase(double revenue, string currency, string payType, string itemId,
|
||||
string status, string itemName = null, string msg = null)
|
||||
{
|
||||
// var props = new Dictionary<string, object>
|
||||
// {
|
||||
// { "Revenue", revenue },
|
||||
// { "Currency", currency },
|
||||
// { "type", payType },
|
||||
// { "item_id", itemId },
|
||||
// { "purchase_status", status }
|
||||
// };
|
||||
//
|
||||
// if (!string.IsNullOrEmpty(itemName))
|
||||
// props["item_name"] = itemName;
|
||||
// if (!string.IsNullOrEmpty(msg))
|
||||
// props["msg"] = msg;
|
||||
//
|
||||
// TrackEvent(BIEvent.PURCHASE, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上报页面浏览
|
||||
/// </summary>
|
||||
public void TrackPageView(string pageName)
|
||||
{
|
||||
var props = new Dictionary<string, object>
|
||||
{
|
||||
{ "page_name", pageName } // 例如 "loading"、"game"
|
||||
};
|
||||
|
||||
TrackEvent(BIEvent.PAGE_VIEW, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AB 分组埋点
|
||||
/// </summary>
|
||||
public void TrackABConfig(int responseTime)
|
||||
{
|
||||
// var props = new Dictionary<string, object>
|
||||
// {
|
||||
// { "response_time", responseTime }
|
||||
// };
|
||||
//
|
||||
// TrackEvent(BIEvent.AB_CONFIG, props);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class BIEvent
|
||||
{
|
||||
// 自动采集(SDK 开启自动采集即可,不需要手动埋点)
|
||||
public const string APP_INSTALL = "app_install";
|
||||
public const string APP_START = "app_start";
|
||||
public const string APP_END = "app_end";
|
||||
public const string APP_VIEW = "app_view";
|
||||
public const string APP_CRASH = "app_crash";
|
||||
|
||||
// 内部预制事件
|
||||
public const string AD_REQUEST = "ad_request"; // 广告请求
|
||||
public const string AD_INVENTORY = "ad_inventory"; // 广告填充的时候
|
||||
public const string AD_IMP = "ad_imp"; // 广告展示
|
||||
public const string AD_CLICK = "ad_click"; // 广告点击
|
||||
|
||||
public const string PURCHASE = "purchase"; // 内购
|
||||
|
||||
// 页面相关
|
||||
public const string PAGE_VIEW = "page_view_customize";
|
||||
|
||||
// 其他业务事件(AB 测试等)
|
||||
public const string AB_CONFIG = "config"; // AB
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using AppsFlyerSDK;
|
||||
using DG.Tweening;
|
||||
using Newtonsoft.Json;
|
||||
using SGModule.NetKit;
|
||||
using SRKZBz0SDK;
|
||||
|
||||
// using AppsFlyerSDK;
|
||||
|
||||
@@ -26,30 +27,48 @@ namespace RedHotRoast
|
||||
|
||||
public static string rewardedADUnitID = "13c3601021e6a8b9";
|
||||
|
||||
|
||||
private const float RevenueThreshold = 0;
|
||||
|
||||
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
MaxSdkCallbacks.OnSdkInitializedEvent += sdkConfiguration =>
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
// 注册 ab事件,0或1,0为自然量版本,1为激励版本
|
||||
SRKZBz0SDK_Utility.Instance.RegistIosParam((i =>
|
||||
{
|
||||
InitializeRewardedAds();
|
||||
InitializeInterstitialAds();
|
||||
};
|
||||
SuperApplication.Instance.attribution = i == 0 ? "organic" : "non_organic";
|
||||
Debug.Log($"ios ab param : {i} attribution=== {SuperApplication.Instance.attribution}");
|
||||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||||
|
||||
}));
|
||||
|
||||
|
||||
MaxSdk.SetSdkKey(SDKKey);
|
||||
|
||||
// var loginModel = GameHelper.GetLoginModel();
|
||||
// user_id = loginModel.uid.ToString();
|
||||
// MaxSdk.SetUserId(loginModel.uid.ToString());
|
||||
// MaxSdk.SetIsAgeRestrictedUser(false);
|
||||
MaxSdk.SetHasUserConsent(true);
|
||||
MaxSdk.SetDoNotSell(false);
|
||||
|
||||
MaxSdk.InitializeSdk();
|
||||
void GameConfig(bool result, string config)
|
||||
{
|
||||
Debug.Log($"************* game config result : {result}, config : {config}");
|
||||
}
|
||||
// SDK初始化方法
|
||||
SRKZBz0SDK_Utility.Instance.Init(null, null, GameConfig);
|
||||
|
||||
#endif
|
||||
// MaxSdkCallbacks.OnSdkInitializedEvent += sdkConfiguration =>
|
||||
// {
|
||||
// InitializeRewardedAds();
|
||||
// InitializeInterstitialAds();
|
||||
// };
|
||||
//
|
||||
//
|
||||
// MaxSdk.SetSdkKey(SDKKey);
|
||||
//
|
||||
// // var loginModel = GameHelper.GetLoginModel();
|
||||
// // user_id = loginModel.uid.ToString();
|
||||
// // MaxSdk.SetUserId(loginModel.uid.ToString());
|
||||
// // MaxSdk.SetIsAgeRestrictedUser(false);
|
||||
// MaxSdk.SetHasUserConsent(true);
|
||||
// MaxSdk.SetDoNotSell(false);
|
||||
//
|
||||
// MaxSdk.InitializeSdk();
|
||||
|
||||
// MaxSdk.ShowMediationDebugger();
|
||||
// #if !UNITY_EDITOR
|
||||
@@ -65,22 +84,42 @@ namespace RedHotRoast
|
||||
|
||||
#region 插屏广告相关
|
||||
public static UnityAction<bool> onInterstitialAdCompleted = null;
|
||||
|
||||
public static bool CheckInterstitialReady()
|
||||
{
|
||||
return SRKZBz0SDK_Utility.Instance.IsInterReady();
|
||||
}
|
||||
public static void ShowInterstitial(string placement = "DefaultInterstitial",
|
||||
UnityAction<bool> onCompleted = null)
|
||||
{
|
||||
if (MaxSdk.IsInterstitialReady(interstitialADUnitID))
|
||||
|
||||
if (CheckInterstitialReady())
|
||||
{
|
||||
// Debug.Log($"广告已经准备好,播放");
|
||||
MaxSdk.ShowInterstitial(interstitialADUnitID, placement);
|
||||
onInterstitialAdCompleted = onCompleted;
|
||||
|
||||
Debug.Log($"广告已经准备好,播放");
|
||||
SRKZBz0SDK_Utility.Instance.ShowInter(placement, () =>
|
||||
{
|
||||
onCompleted?.Invoke(true);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.Log($"广告未准备好,不播放");
|
||||
|
||||
Debug.Log($"广告未准备好,不播放");
|
||||
onCompleted?.Invoke(false);
|
||||
}
|
||||
|
||||
// if (MaxSdk.IsInterstitialReady(interstitialADUnitID))
|
||||
// {
|
||||
// // Debug.Log($"广告已经准备好,播放");
|
||||
// MaxSdk.ShowInterstitial(interstitialADUnitID, placement);
|
||||
// onInterstitialAdCompleted = onCompleted;
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Debug.Log($"广告未准备好,不播放");
|
||||
//
|
||||
// onCompleted?.Invoke(false);
|
||||
// }
|
||||
}
|
||||
|
||||
static int retryAttemptInterstitial;
|
||||
@@ -158,6 +197,11 @@ namespace RedHotRoast
|
||||
public static UnityAction<bool> onVideoAdCompleted = null;
|
||||
private static string _placement = "";
|
||||
private static Coroutine _waitForVideoAd = null;
|
||||
|
||||
public static bool CheckRewardedReady()
|
||||
{
|
||||
return SRKZBz0SDK_Utility.Instance.IsVideoReady();
|
||||
}
|
||||
public static void ShowVideo(string placement = "DefaultVideo", UnityAction<bool> onCompleted = null)
|
||||
{
|
||||
onVideoAdCompleted = onCompleted;
|
||||
@@ -168,18 +212,38 @@ namespace RedHotRoast
|
||||
TrackKit.SendEvent(VideoBehaviorTrack.Event, VideoBehaviorTrack.Property.watch_ad_people);
|
||||
TrackKit.SendEvent(VideoBehaviorTrack.Event, VideoBehaviorTrack.Property.Rewarded_videos_trigger_number);
|
||||
|
||||
if (MaxSdk.IsRewardedAdReady(rewardedADUnitID))
|
||||
if (CheckRewardedReady())
|
||||
{
|
||||
MaxSdk.ShowRewardedAd(rewardedADUnitID, _placement);
|
||||
SRKZBz0SDK_Utility.Instance.ShowRewardVideo(_placement, b =>
|
||||
{
|
||||
onVideoAdCompleted?.Invoke(b);
|
||||
}, ()=>
|
||||
{
|
||||
Debug.Log($"激励广告关闭");
|
||||
if (GameHelper.IsGiftSwitch() && !SaveData.GetSaveObject().is_get_removead && (UnityEngine.Random.Range(0, 100) < GameHelper.GetCommonModel().rewardinsertion))
|
||||
{
|
||||
TrackKit.SendEvent(ADEventTrack.Event, ADEventTrack.Property.afterRewardAdShow);
|
||||
|
||||
GameHelper.ShowInterstitial("AfterReward");
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_waitForVideoAd != null)
|
||||
{
|
||||
CrazyAsyKit.StopCoroutine(_waitForVideoAd);
|
||||
}
|
||||
_waitForVideoAd = CrazyAsyKit.StartCoroutine(WaitForVideoAd());
|
||||
onVideoAdCompleted?.Invoke(false);
|
||||
}
|
||||
// if (MaxSdk.IsRewardedAdReady(rewardedADUnitID))
|
||||
// {
|
||||
// MaxSdk.ShowRewardedAd(rewardedADUnitID, _placement);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (_waitForVideoAd != null)
|
||||
// {
|
||||
// CrazyAsyKit.StopCoroutine(_waitForVideoAd);
|
||||
// }
|
||||
// _waitForVideoAd = CrazyAsyKit.StartCoroutine(WaitForVideoAd());
|
||||
// }
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user