Playvoi/Playvoi.Client/Assets/ShiroginSDK/Runtime/Services/Implementations/AppsFlyerServiceNS/AppsFlyerService.cs

187 lines
No EOL
6.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using ShiroginSDK.Runtime.Core.SDK;
using ShiroginSDK.Runtime.Services.Base;
using ShiroginSDK.Runtime.Services.Interfaces;
using UnityEngine;
#if SHIROGIN_APPSFLYER
using AppsFlyerSDK;
#endif
// artık çakışma yok
namespace ShiroginSDK.Runtime.Services.Implementations.AppsFlyerServiceNS
{
#if SHIROGIN_APPSFLYER
/// <summary>
/// Handles AppsFlyer initialization and event tracking for analytics and attribution.
/// </summary>
public class AppsFlyerService : ServiceBase, IAppsFlyerService, IAppsFlyerConversionData
{
private ShiroginConfig _config;
// ----------------------------------------------------
// Conversion & Attribution Callbacks
// ----------------------------------------------------
public void onConversionDataSuccess(string conversionData)
{
Debug.Log($"[AppsFlyerService] 📈 Conversion data received: {conversionData}");
}
public void onConversionDataFail(string error)
{
Debug.LogError($"[AppsFlyerService] ❌ Conversion data failed: {error}");
}
public void onAppOpenAttribution(string attributionData)
{
Debug.Log($"[AppsFlyerService] 🔗 App open attribution: {attributionData}");
}
public void onAppOpenAttributionFailure(string error)
{
Debug.LogError($"[AppsFlyerService] ❌ Attribution failed: {error}");
}
public bool IsInitialized { get; private set; }
// ----------------------------------------------------
// Event Tracking
// ----------------------------------------------------
public void TrackPurchase(string productId, string currency, double price, int quantity = 1)
{
if (_config == null || !_config.enableAppsFlyerAnalytics) return;
if (!IsInitialized)
{
Debug.LogWarning("[AppsFlyerService] ⚠️ TrackPurchase called before initialization.");
return;
}
var eventValues = new Dictionary<string, string>
{
{ AFInAppEvents.CONTENT_ID, productId },
{ AFInAppEvents.CURRENCY, currency },
{ AFInAppEvents.REVENUE, price.ToString("F2") },
{ AFInAppEvents.QUANTITY, quantity.ToString() }
};
AppsFlyer.sendEvent(AFInAppEvents.PURCHASE, eventValues);
Debug.Log($"[AppsFlyerService] 💰 Purchase tracked: {productId} ({price} {currency})");
}
public void TrackCustomEvent(string eventName, Dictionary<string, string> eventValues = null)
{
if (_config == null || !_config.enableAppsFlyerAnalytics) return;
if (!IsInitialized)
{
Debug.LogWarning("[AppsFlyerService] ⚠️ TrackCustomEvent called before initialization.");
return;
}
AppsFlyer.sendEvent(eventName, eventValues ?? new Dictionary<string, string>());
Debug.Log($"[AppsFlyerService] 🧭 Custom event sent: {eventName}");
}
// ----------------------------------------------------
// Initialization
// ----------------------------------------------------
protected override void OnInitialize()
{
_config = ShiroginConfig.Load();
if (!_config.enableAppsFlyerAnalytics)
{
Debug.LogWarning("[AppsFlyerService] 🛑 AppsFlyer DISABLED in Config. Running in Dummy Mode.");
return;
}
if (_config == null)
{
Debug.LogError("[AppsFlyerService] ❌ SDKConfig not found.");
return;
}
if (string.IsNullOrEmpty(_config.appsFlyerDevKey) || string.IsNullOrEmpty(_config.appsFlyerAppId))
{
Debug.LogError("[AppsFlyerService] ❌ AppsFlyer DevKey or AppId missing in SDKConfig.");
return;
}
#if UNITY_IOS
AppsFlyer.initSDK(_config.appsFlyerDevKey, _config.appsFlyerAppId);
#elif UNITY_ANDROID
AppsFlyer.initSDK(_config.appsFlyerDevKey, _config.appsFlyerAppId);
#else
Debug.LogWarning("[AppsFlyerService] ⚠️ Unsupported platform for AppsFlyer.");
return;
#endif
AppsFlyer.startSDK();
IsInitialized = true;
Debug.Log("[AppsFlyerService] ✅ AppsFlyer initialized successfully.");
}
protected override void OnDispose()
{
IsInitialized = false;
}
}
#else
/// <summary>
/// Handles AppsFlyer initialization and event tracking for analytics and attribution.
/// </summary>
public class AppsFlyerService : ServiceBase, IAppsFlyerService
{
private ShiroginConfig _config;
// ----------------------------------------------------
// Conversion & Attribution Callbacks
// ----------------------------------------------------
public bool IsInitialized { get; private set; }
// ----------------------------------------------------
// Event Tracking
// ----------------------------------------------------
public void TrackPurchase(string productId, string currency, double price, int quantity = 1)
{
Debug.Log($"[AppsFlyerService] Dummy {productId} ({price} {currency})");
}
public void TrackCustomEvent(string eventName, Dictionary<string, string> eventValues = null)
{
Debug.Log($"[AppsFlyerService] Dummy Custom event sent: {eventName}");
}
// ----------------------------------------------------
// Initialization
// ----------------------------------------------------
protected override void OnInitialize()
{
_config = ShiroginConfig.Load();
if (_config == null)
{
Debug.LogError("[AppsFlyerService] Dummy ❌ SDKConfig not found.");
return;
}
if (string.IsNullOrEmpty(_config.appsFlyerDevKey) || string.IsNullOrEmpty(_config.appsFlyerAppId))
{
Debug.LogError("[AppsFlyerService] Dummy AppsFlyer DevKey or AppId missing in SDKConfig.");
return;
}
IsInitialized = true;
Debug.Log("[AppsFlyerService] Dummy AppsFlyer initialized successfully.");
}
protected override void OnDispose()
{
IsInitialized = false;
}
}
#endif
}