1
0

IAnalyticsService.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using Unity.Services.Analytics.Internal;
  4. namespace Unity.Services.Analytics
  5. {
  6. public interface IAnalyticsService
  7. {
  8. /// <summary>
  9. /// This is the URL for the Unity Analytics privacy policy. This policy page should
  10. /// be presented to the user in a platform-appropriate way along with the ability to
  11. /// opt out of data collection.
  12. /// </summary>
  13. string PrivacyUrl { get; }
  14. /// <summary>
  15. /// Forces an immediately upload of all recorded events to the server, if there is an internet connection.
  16. /// </summary>
  17. /// <exception cref="ConsentCheckException">Thrown if the required consent flow cannot be determined..</exception>
  18. void Flush();
  19. void AdImpression(AdImpressionParameters parameters);
  20. /// <summary>
  21. /// Record a Transaction event.
  22. /// </summary>
  23. /// <param name="transactionParameters">(Required) Helper object to handle parameters.</param>
  24. void Transaction(TransactionParameters transactionParameters);
  25. /// <summary>
  26. /// Record a TransactionFailed event.
  27. /// </summary>
  28. /// <param name="parameters">(Required) Helper object to handle parameters.</param>
  29. void TransactionFailed(TransactionFailedParameters parameters);
  30. /// <summary>
  31. /// Record a custom event. A schema for this event must exist on the dashboard or it will be ignored.
  32. /// </summary>
  33. void CustomData(string eventName, IDictionary<string, object> eventParams);
  34. /// <summary>
  35. /// Returns identifiers of required consents we need to gather from the user
  36. /// in order to be allowed to sent analytics events.
  37. /// This method must be called every time the game starts - without checking the geolocation,
  38. /// no event will be sent (even if the consent was already given).
  39. /// If the required consent was already given, an empty list is returned.
  40. /// If the user already opted out from the current legislation, an empty list is returned.
  41. /// It involves the GeoIP call.
  42. /// `ConsentCheckException` is thrown if the GeoIP call was unsuccessful.
  43. ///
  44. /// </summary>
  45. /// <returns>A list of consent identifiers that are required for sending analytics events.</returns>
  46. /// <exception cref="ConsentCheckException">Thrown if the GeoIP call was unsuccessful.</exception>
  47. Task<List<string>> CheckForRequiredConsents();
  48. /// <summary>
  49. /// Sets the consent status for the specified opt-in-based legislation (PIPL etc).
  50. /// The required legislation identifier can be found by calling `CheckForRequiredConsents` method.
  51. /// If this method is tried to be used for the incorrect legislation (PIPL outside China etc),
  52. /// the `ConsentCheckException` is thrown.
  53. ///
  54. /// </summary>
  55. /// <param name="identifier">The legislation identifier for which the consent status should be changed.</param>
  56. /// <param name="consent">The consent status which should be set for the specified legislation.</param>
  57. /// <exception cref="ConsentCheckException">Thrown if the incorrect legislation was being provided or
  58. /// the required consent flow cannot be determined.</exception>
  59. void ProvideOptInConsent(string identifier, bool consent);
  60. /// <summary>
  61. /// Opts the user out of sending analytics from all legislations.
  62. /// To deny consent for a specific opt-in legislation, like PIPL, use `ProvideConsent(string key, bool consent)` method)
  63. /// All existing cached events and any subsequent events will be discarded immediately.
  64. /// A final 'forget me' signal will be uploaded which will trigger purge of analytics data for this user from the back-end.
  65. /// If this 'forget me' event cannot be uploaded immediately (e.g. due to network outage), it will be reattempted regularly
  66. /// until successful upload is confirmed.
  67. /// Consent status is stored in PlayerPrefs so that the opted-out status is maintained over app restart.
  68. /// This action cannot be undone.
  69. /// </summary>
  70. /// <exception cref="ConsentCheckException">Thrown if the required consent flow cannot be determined..</exception>
  71. void OptOut();
  72. /// <summary>
  73. /// Allows other sources to write events with common analytics parameters to the Analytics service. This is primarily for use
  74. /// by other packages - as this method adds common parameters that may not be expected in the general case, for custom events
  75. /// you should use the <c>CustomData</c> method instead.
  76. /// </summary>
  77. /// <param name="eventToRecord">Internal event to record</param>
  78. void RecordInternalEvent(Event eventToRecord);
  79. /// <summary>
  80. /// Record an acquisitionSource event.
  81. /// </summary>
  82. /// <param name="acquisitionSourceParameters">(Required) Helper object to handle parameters.</param>
  83. void AcquisitionSource(AcquisitionSourceParameters acquisitionSourceParameters);
  84. /// <summary>
  85. /// Allows you to disable the Analytics service. When the service gets disabled all currently cached data both in RAM and on disk
  86. /// will be deleted and any new events will be voided. By default the service is enabled so you do not need to call this method on start.
  87. /// Will return instantly when disabling, must be awaited when re-enabling.
  88. /// <example>
  89. /// To disable the Analytics Service before the game starts
  90. /// <code>
  91. /// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  92. /// static void DisableAnalytics()
  93. /// {
  94. /// AnalyticsService.Instance.SetAnalyticsEnabled(false);
  95. /// }
  96. /// </code>
  97. /// </example>
  98. /// </summary>
  99. Task SetAnalyticsEnabled(bool enabled);
  100. /// <summary>
  101. /// Converts an amount of currency to the minor units required for the objects passed to the Transaction method.
  102. /// This method uses data from ISO 4217. Note that this method expects you to pass in currency in the major units for
  103. /// conversion - if you already have data in the minor units you don't need to call this method.
  104. /// For example - 1.99 USD would be converted to 199, 123 JPY would be returned unchanged.
  105. /// </summary>
  106. /// <param name="currencyCode">The ISO4217 currency code for the input currency. For example, USD for dollars, or JPY for Japanese Yen</param>
  107. /// <param name="value">The major unit value of currency, for example 1.99 for 1 dollar 99 cents.</param>
  108. /// <returns>The minor unit value of the input currency, for example for an input of 1.99 USD 199 would be returned.</returns>
  109. long ConvertCurrencyToMinorUnits(string currencyCode, double value);
  110. }
  111. }