using System; using System.Collections.Generic; using UnityEngine; using Voodoo.Tiny.Sauce.Internal.Analytics; using Voodoo.Tiny.Sauce.Privacy; public static class TinySauce { private const string TAG = "TinySauce"; public const string Version = "6.6.2"; private const string ABCohortKey = "ABCohort"; private const string DebugCohortKey = "DebugCohortKey"; public static event Action ConsentGiven; #region GameStart Methods /// /// Method to call whenever the user starts a game. /// public static void OnGameStarted(int levelNumber, Dictionary eventProperties = null) { OnGameStarted(levelNumber.ToString(), eventProperties); } /// /// Method to call whenever the user starts a game. /// /// The game Level, this parameter is optional for game without level public static void OnGameStarted(string levelName, Dictionary eventProperties = null) { AnalyticsManager.TrackGameStarted(levelName, eventProperties); } /// /// Method to call whenever the user starts a game using the dim1:dim2:dim3 format. /// /// The first dimension of the level /// The second dimension of the level /// The third dimension of the level, this parameter is optional public static void OnGameStarted(string dimension1, string dimension2, string dimension3 = null, Dictionary eventProperties = null) { AnalyticsManager.TrackGameStarted(dimension1, dimension2, dimension3, eventProperties); } #endregion #region GameFinish Methods /// /// Method to call whenever the user completes a game with levels. /// /// The score of the game public static void OnGameFinished(float score) { OnGameFinished(true, score, null, null); } /// /// Method to call whenever the user finishes a game, even when leaving a game. /// /// Whether the user finished the game /// The score of the game public static void OnGameFinished(bool levelComplete, float score, Dictionary eventProperties = null) { OnGameFinished(levelComplete, score, null, eventProperties); } /// /// Method to call whenever the user finishes a game, even when leaving a game. /// /// Whether the user finished the game /// The score of the game /// The level number public static void OnGameFinished(bool levelComplete, float score, int levelNumber, Dictionary eventProperties = null) { OnGameFinished(levelComplete, score, levelNumber.ToString(), eventProperties); } /// /// Method to call whenever the user finishes a game, even when leaving a game. /// /// Whether the user finished the game /// The score of the game /// The level name public static void OnGameFinished(bool levelComplete, float score, string levelName, Dictionary eventProperties = null) { AnalyticsManager.TrackGameFinished(levelComplete, score, levelName, eventProperties); } /// /// Method to call whenever the user finishes a game, even when leaving a game. /// /// Whether the user finished the game /// The score of the game /// The first dimension of the level /// The second dimension of the level /// The third dimension of the level, this parameter is optional public static void OnGameFinished(bool levelComplete, float score, string dimension1, string dimension2, string dimension3 = null, Dictionary eventProperties = null) { AnalyticsManager.TrackGameFinished(levelComplete, score, dimension1, dimension2, dimension3, eventProperties); } #endregion #region Upgrade Methods /// /// Method to call whenever the user makes an upgrade on the game. /// /// The name of the upgrade /// The level of the upgrade public static void OnUpgradeEvent(string upgradeName, int upgradeLevel, Dictionary eventProperties = null, string type = null, List analyticsProviders = null) { AnalyticsManager.TrackUpgradeEvent(null, upgradeName, upgradeLevel, eventProperties, type, analyticsProviders); } /// /// Method to call whenever the user makes an upgrade on the game. /// /// The category of the upgrade /// The name of the upgrade /// The level of the upgrade public static void OnUpgradeEvent(string upgradeCategory, string upgradeName, int upgradeLevel, Dictionary eventProperties = null, string type = null, List analyticsProviders = null) { AnalyticsManager.TrackUpgradeEvent(upgradeCategory, upgradeName, upgradeLevel, eventProperties, type, analyticsProviders); } #endregion [Obsolete("This method is deprecated, please check the TinySauce Optional Event documentation")] public static void DeclareCurrency(string currencyName) { Debug.LogError("DeclareCurrency method is deprecated, please check the \"TinySauce Optional Event\" documentation"); } [Obsolete("This method is deprecated, please check the TinySauce Optional Event documentation")] public static void DeclareItemType(string itemTypeName) { Debug.LogError("DeclareItemType method is deprecated, please check the \"TinySauce Optional Event\" documentation"); } /// /// Track when the player receive some currency /// /// The name of the currency /// The amount of the currency /// The name of the item type /// The id of the item transaction public static void OnCurrencyGiven(string currency, int currencyAmount, string itemType, string itemId) { AnalyticsManager.TrackResourceSourceEvent(currency, currencyAmount, itemType, itemId); } /// /// Track when the player loses some currency /// /// The name of the currency /// The amount of the currency /// The name of the item type /// The id of the item transaction public static void OnCurrencyTaken(string currency, int currencyAmount, string itemType, string itemId) { AnalyticsManager.TrackResourceSinkEvent(currency, currencyAmount, itemType, itemId); } /// /// Track any real money transaction in-game. /// /// Currency code in ISO 4217 format. (e.g. USD). /// Amount in cents (int). (e.g. 99). /// Item Type bought. (e.g. Gold Pack). /// Item bought. (e.g. 1000 gold). /// Cart type. public static void OnIAPPurchase(string currency, int amount, string itemType, string itemId, string cartType) { AnalyticsManager.TrackIAPEvent(currency, amount, itemType, itemId, cartType); } #region CustomEvent Method /// /// Call this method to track any custom event you want. /// /// The name of the event to track /// An optional list of properties to send along with the event /// type of the event /// The list of analytics provider you want to track your custom event to. If this list is null or empty, the event will be tracked in GameAnalytics and Mixpanel (if the user is in a cohort) public static void TrackCustomEvent(string eventName, Dictionary eventProperties = null, string type = null, List analyticsProviders = null) { AnalyticsManager.TrackCustomEvent(eventName, eventProperties, type, analyticsProviders); } #endregion [Obsolete("This function will be deprecated soon, please use SubscribeOnInitFinishedEvent instead")] public static void SubscribeToConsentGiven(Action onConsentGiven) { SubscribeOnInitFinishedEvent(onConsentGiven); } public static void SubscribeOnInitFinishedEvent(Action onConsentGiven) { if (!PrivacyManager.ConsentReady) PrivacyManager.OnConsentGiven += onConsentGiven; else onConsentGiven?.Invoke(PrivacyManager.AdConsent, PrivacyManager.AnalyticsConsent); } [Obsolete("This function will be deprecated soon, please use UnsubscribeOnInitFinishedEvent instead")] public static void UnsubscribeToConsentGiven(Action onConsentGiven) { UnsubscribeOnInitFinishedEvent(onConsentGiven); } public static void UnsubscribeOnInitFinishedEvent(Action onConsentGiven) { PrivacyManager.OnConsentGiven -= onConsentGiven; } public static string GetABTestCohort() { #if UNITY_EDITOR if (!string.IsNullOrEmpty(PlayerPrefs.GetString(DebugCohortKey))) { return PlayerPrefs.GetString(DebugCohortKey); } #endif return PlayerPrefs.GetString(ABCohortKey); } public enum AnalyticsProvider { VoodooAnalytics, GameAnalytics, } }