Events.AdImpression.deprecated.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using UnityEngine;
  3. namespace Unity.Services.Analytics
  4. {
  5. public static partial class Events
  6. {
  7. [Obsolete("This enum has been moved outside the Events class. Please use that instead. This enum will be removed in an upcoming release.")]
  8. public enum AdCompletionStatus
  9. {
  10. /// <summary>
  11. /// If the ad is fully viewed and therefore will count as an impression for the ad network.
  12. /// </summary>
  13. Completed = 0,
  14. /// <summary>
  15. /// If there is an option to exit the ad before generating revenue.
  16. /// </summary>
  17. Partial = 1,
  18. /// <summary>
  19. /// If the ad is not viewed at all (alternatively, don’t record the adImpression event in.
  20. /// </summary>
  21. Incomplete = 2
  22. }
  23. [Obsolete("This enum has been moved outside the Events class. Please use that instead. This enum will be removed in an upcoming release.")]
  24. public enum AdProvider
  25. {
  26. AdColony = 0,
  27. AdMob = 1,
  28. Amazon = 2,
  29. AppLovin = 3,
  30. ChartBoost = 4,
  31. Facebook = 5,
  32. Fyber = 6,
  33. Hyprmx = 7,
  34. Inmobi = 8,
  35. Maio = 9,
  36. Pangle = 10,
  37. Tapjoy = 11,
  38. UnityAds = 12,
  39. Vungle = 13,
  40. IrnSource = 14,
  41. Other = 15
  42. }
  43. /// <summary>
  44. /// Helper object to handle arguments for recording an AdImpression event.
  45. /// </summary>
  46. [Obsolete("This class has been aligned with other interfaces. Please use AdImpressionParameters with the AnalyticsService.Instance API instead. This class will be removed in an upcoming release")]
  47. public class AdImpressionArgs
  48. {
  49. /// <param name="adCompletionStatus">(Required) Indicates a successful Ad view. Select one of the `AdCompletionStatus` values.</param>
  50. /// <param name="adProvider">(Required) The Ad SDK that provided the Ad. Select one of the `AdProvider` values.</param>
  51. /// <param name="placementID">(Required) The unique identifier for the placement as integrated into the game.</param>
  52. /// <param name="placementName">(Required) If there is a place in the game that can show Ads from multiple networks, there won’t be a single placementId. This field compensates for that by providing a single name for your placement. Ideally, this would be an easily human-readable name such as ‘revive’ or ‘daily bonus’. This value is here for reporting purposes only.</param>
  53. public AdImpressionArgs(AdCompletionStatus adCompletionStatus, AdProvider adProvider, string placementID, string placementName)
  54. {
  55. AdCompletionStatus = adCompletionStatus;
  56. AdProvider = adProvider;
  57. PlacementID = placementID;
  58. PlacementName = placementName;
  59. }
  60. /// <summary>
  61. /// Indicates whether the Ad view was successful or not.
  62. /// </summary>
  63. public AdCompletionStatus AdCompletionStatus { get; set; }
  64. /// <summary>
  65. /// The Ad SDK that provided the Ad.
  66. /// </summary>
  67. public AdProvider AdProvider { get; set; }
  68. /// <summary>
  69. /// The unique identifier for the placement where the Ad appeared as integrated into the game.
  70. /// </summary>
  71. public string PlacementID { get; set; }
  72. /// <summary>
  73. /// If there is a place in the game that can show Ads from multiple networks, there won’t be a single placementId. This field compensates for that by providing a single name for your placement. Ideally, this would be an easily human-readable name such as ‘revive’ or ‘daily bonus’.
  74. /// This value is here for reporting purposes only.
  75. /// </summary>
  76. public string PlacementName { get; set; }
  77. /// <summary>
  78. /// Optional.
  79. /// The placementType should indicate what type of Ad is shown.
  80. /// This value is here for reporting purposes only.
  81. /// </summary>
  82. public string PlacementType { get; set; }
  83. /// <summary>
  84. /// Optional.
  85. /// The estimated ECPM in USD, you should populate this value if you can.
  86. /// </summary>
  87. public double? AdEcpmUsd { get; set; }
  88. /// <summary>
  89. /// Optional.
  90. /// The Ad SDK version you are using.
  91. /// </summary>
  92. public string SdkVersion { get; set; }
  93. /// <summary>
  94. /// Optional.
  95. /// </summary>
  96. public string AdImpressionID { get; set; }
  97. /// <summary>
  98. /// Optional.
  99. /// </summary>
  100. public string AdStoreDstID { get; set; }
  101. /// <summary>
  102. /// Optional.
  103. /// </summary>
  104. public string AdMediaType { get; set; }
  105. /// <summary>
  106. /// Optional.
  107. /// </summary>
  108. public Int64? AdTimeWatchedMs { get; set; }
  109. /// <summary>
  110. /// Optional.
  111. /// </summary>
  112. public Int64? AdTimeCloseButtonShownMs { get; set; }
  113. /// <summary>
  114. /// Optional.
  115. /// </summary>
  116. public Int64? AdLengthMs { get; set; }
  117. /// <summary>
  118. /// Optional.
  119. /// </summary>
  120. public bool? AdHasClicked { get; set; }
  121. /// <summary>
  122. /// Optional.
  123. /// </summary>
  124. public string AdSource { get; set; }
  125. /// <summary>
  126. /// Optional.
  127. /// </summary>
  128. public string AdStatusCallback { get; set; }
  129. }
  130. /// <summary>
  131. /// Record an Ad Impression event.
  132. /// </summary>
  133. /// <param name="args">(Required) Helper object to handle arguments.</param>
  134. [Obsolete("The interface provided by this method has moved to AnalyticsService.Instance.AdImpression, and should be accessed from there instead. This API will be removed in an upcoming release.")]
  135. public static void AdImpression(AdImpressionArgs args)
  136. {
  137. // Enum.TryParse will fill out placementType if possible, but if it returns false or we get passed a null value we need to provide a default value to prevent runtime problems.
  138. if (!string.IsNullOrEmpty(args.PlacementType) || !Enum.TryParse(args.PlacementType, out AdPlacementType placementType))
  139. {
  140. placementType = AdPlacementType.BANNER;
  141. }
  142. var newParams = new AdImpressionParameters
  143. {
  144. AdCompletionStatus = (Analytics.AdCompletionStatus)(int)args.AdCompletionStatus,
  145. AdProvider = (Analytics.AdProvider)(int)args.AdProvider,
  146. AdEcpmUsd = args.AdEcpmUsd,
  147. AdHasClicked = args.AdHasClicked,
  148. AdImpressionID = args.AdImpressionID,
  149. AdLengthMs = args.AdLengthMs,
  150. AdMediaType = args.AdMediaType,
  151. AdSource = args.AdSource,
  152. AdStatusCallback = args.AdStatusCallback,
  153. AdStoreDstID = args.AdStoreDstID,
  154. AdTimeCloseButtonShownMs = args.AdTimeCloseButtonShownMs,
  155. AdTimeWatchedMs = args.AdTimeWatchedMs,
  156. PlacementID = args.PlacementID,
  157. PlacementName = args.PlacementName,
  158. PlacementType = placementType,
  159. SdkVersion = args.SdkVersion
  160. };
  161. AnalyticsService.Instance.AdImpression(newParams);
  162. }
  163. }
  164. }