com.amanotes.gdk 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.10 - 2023-02-17]
4
+ ### Release AmaGDK v0.1.10
5
+ ### Support accumulated event within session
6
+
3
7
  ## [0.1.9 - 2023-02-15]
4
8
  ### Release AmaGDK v0.1.9
5
9
  ### Change Documentation URL
@@ -108,7 +108,10 @@ namespace Amanotes.Core
108
108
  void DrawGUI_ConfigDetail()
109
109
  {
110
110
  CreateCachedEditor(configAsset, null, ref editor);
111
+ var lbWidth = EditorGUIUtility.labelWidth;
112
+ EditorGUIUtility.labelWidth = 200f;
111
113
  editor.OnInspectorGUI();
114
+ EditorGUIUtility.labelWidth = lbWidth;
112
115
  }
113
116
 
114
117
  void DrawGUI_ConfigAsset(){
Binary file
@@ -0,0 +1,3 @@
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:313276bb7dcfb6c5dc1a760945f89b413282c7329d1b4856e777c6aee75cc22e
3
+ size 1635
@@ -1,6 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: cfbb48f0167d74afa8a2099a218d698e
3
- folderAsset: yes
2
+ guid: 1a3999539db3049c998b0c84b7f92f07
4
3
  DefaultImporter:
5
4
  externalObjects: {}
6
5
  userData:
@@ -0,0 +1,235 @@
1
+ using System;
2
+ using System.Collections;
3
+
4
+ using UnityEngine;
5
+
6
+ using Amanotes.Core.Internal;
7
+ using static Amanotes.Core.Internal.Logging;
8
+
9
+ namespace Amanotes.Core
10
+ {
11
+ public interface IAds
12
+ {
13
+ bool IsAdReady(AdType Type);
14
+
15
+ #region Interstitial
16
+ event Action InterstitialShowSucceededCallback;
17
+ event Action InterstitialShowFailedCallback;
18
+ event Action InterstitialClickedCallback;
19
+ void RequestInterstitial();
20
+ void ShowInterstitial();
21
+ void ShowInterstitial(string placementName);
22
+ #endregion FullAds
23
+
24
+ #region VideoAds
25
+ event Action RewardedVideoShowFailedCallback;
26
+ event Action RewardedVideoClosedCallback;
27
+ event Action RewardedCallback;
28
+ event Action RewardedVideoClickCallback;
29
+ void RequestRewardedVideo();
30
+ void ShowRewardedVideo();
31
+ void ShowRewardedVideo(string placementName);
32
+ #endregion VideoAds
33
+
34
+ #region Banner
35
+ event Action BannerAdsClickCallback;
36
+ event Action BannerShowCallback;
37
+ void RequestBanner(BannerPosition position = BannerPosition.TOP);
38
+ void RequestBanner(BannerPosition position, string placementName);
39
+ void ShowBanner();
40
+ void HideBanner();
41
+ #endregion Banner
42
+ }
43
+
44
+ public enum BannerPosition
45
+ {
46
+ TOP = 1,
47
+ BOTTOM = 2
48
+ };
49
+
50
+ public enum AdType : byte
51
+ {
52
+ Interstitial,
53
+ Reward,
54
+ Banner
55
+ };
56
+
57
+ public partial class AmaGDK // IAds module
58
+ {
59
+ public static class Ads
60
+ {
61
+ internal static IAds adsModule;
62
+ public static Action<string> OnInterstitalFailCallback;
63
+ public static Action<string> OnRewardedVideoFailCallback;
64
+
65
+ public static void Init()
66
+ {
67
+ var adsModules = Adapter.FindAll<IAds>();
68
+
69
+ if (adsModules == null || adsModules.Count < 1)
70
+ {
71
+ LogError("Ads module not found!");
72
+ return;
73
+ }
74
+
75
+ if (adsModules.Count > 1)
76
+ {
77
+ LogError("Multiple Ads modules is not supported!");
78
+ return;
79
+ }
80
+
81
+ adsModule = adsModules[0].GetAdapterApi<IAds>();
82
+ }
83
+
84
+ public static void RequestBanner(BannerPosition position)
85
+ {
86
+ if (adsModule == null)
87
+ {
88
+ LogWarning("Ads module is not initialized");
89
+ return;
90
+ }
91
+ adsModule.RequestBanner(position);
92
+ }
93
+
94
+ public static void ShowBanner()
95
+ {
96
+ adsModule.ShowBanner();
97
+ }
98
+
99
+ public static void HideBanner()
100
+ {
101
+ if (!adsModule.IsAdReady(AdType.Banner))
102
+ {
103
+ LogWarning("Banner is not ready");
104
+ return;
105
+ }
106
+
107
+ adsModule.HideBanner();
108
+ }
109
+
110
+ public static void RequestInterstitial()
111
+ {
112
+ if (adsModule == null)
113
+ {
114
+ LogWarning("Ads module is not initialized");
115
+ return;
116
+ }
117
+ adsModule.RequestInterstitial();
118
+ }
119
+
120
+ public static void ShowInterstitial()
121
+ {
122
+ if (!adsModule.IsAdReady(AdType.Interstitial))
123
+ {
124
+ LogWarning("Interstitial is not ready");
125
+ BeginCoroutine(IWaitShowInterstitial());
126
+ return;
127
+ }
128
+ adsModule.ShowInterstitial();
129
+ }
130
+
131
+ public static void RequestRewardedVideo()
132
+ {
133
+ if (adsModule == null)
134
+ {
135
+ LogWarning("Ads module is not initialized");
136
+ return;
137
+ }
138
+ adsModule.RequestRewardedVideo();
139
+ }
140
+
141
+ public static void ShowRewardedVideo()
142
+ {
143
+ if (!adsModule.IsAdReady(AdType.Reward))
144
+ {
145
+ LogWarning("Reward is not ready");
146
+ BeginCoroutine(IWaitShowRewardedVideo());
147
+ return;
148
+ }
149
+ adsModule.ShowRewardedVideo();
150
+ }
151
+
152
+ private static IEnumerator IWaitShowRewardedVideo()
153
+ {
154
+ LogWarning("Wait Show Rewarded Video");
155
+ if (adsModule == null)
156
+ {
157
+ OnRewardedVideoFailCallback?.Invoke("Not found ads module");
158
+ OnRewardedVideoFailCallback = null;
159
+ yield break;
160
+ }
161
+
162
+ var startTime = Time.time;
163
+ float timeout = 5;
164
+ string error = null;
165
+ while (!adsModule.IsAdReady(AdType.Reward))
166
+ {
167
+ if (Application.internetReachability == NetworkReachability.NotReachable)
168
+ {
169
+ error = Application.internetReachability.ToString();
170
+ break;
171
+ }
172
+
173
+ if ((Time.time - startTime) > timeout)
174
+ {
175
+ error = "Timeout";
176
+ break;
177
+ }
178
+
179
+ yield return null;
180
+ }
181
+
182
+ if (adsModule.IsAdReady(AdType.Reward))
183
+ {
184
+ adsModule.ShowRewardedVideo();
185
+ }
186
+ else
187
+ {
188
+ OnRewardedVideoFailCallback?.Invoke(error);
189
+ OnRewardedVideoFailCallback = null;
190
+ }
191
+ }
192
+
193
+ private static IEnumerator IWaitShowInterstitial()
194
+ {
195
+ LogWarning("Wait Show Interstitial");
196
+ if (adsModule == null)
197
+ {
198
+ OnInterstitalFailCallback?.Invoke("Not found ads module");
199
+ OnInterstitalFailCallback = null;
200
+ yield break;
201
+ }
202
+
203
+ var startTime = Time.time;
204
+ float timeout = 5;
205
+ string error = null;
206
+ while (!adsModule.IsAdReady(AdType.Interstitial))
207
+ {
208
+ if (Application.internetReachability == NetworkReachability.NotReachable)
209
+ {
210
+ error = Application.internetReachability.ToString();
211
+ break;
212
+ }
213
+
214
+ if ((Time.time - startTime) > timeout)
215
+ {
216
+ error = "Timeout";
217
+ break;
218
+ }
219
+
220
+ yield return null;
221
+ }
222
+
223
+ if (adsModule.IsAdReady(AdType.Interstitial))
224
+ {
225
+ adsModule.ShowInterstitial();
226
+ }
227
+ else
228
+ {
229
+ OnInterstitalFailCallback?.Invoke(error);
230
+ OnInterstitalFailCallback = null;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ }
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 653a76219edea423ca7f51c1c4c9b02b
2
+ guid: 46425c80eac894185a5609143ace732f
3
3
  MonoImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2
@@ -22,6 +22,7 @@ namespace Amanotes.Core
22
22
  public Dictionary<string, object> parameters = new Dictionary<string, object>();
23
23
  public string funnelSignature;
24
24
  public bool accumulated;
25
+ public bool withinSession;
25
26
  public HashSet<string> ignoreAnalyticIds = new HashSet<string>();
26
27
  public HashSet<string> allowAnalyticIds = new HashSet<string>();
27
28
 
@@ -51,15 +52,36 @@ namespace Amanotes.Core
51
52
  return result;
52
53
  }
53
54
 
55
+ public static IEventParamsBuilder LogEvent(string eventName, params (string, object)[] parameters)
56
+ {
57
+ var result = new EventParams(eventName);
58
+ for (var i = 0;i < parameters.Length; i++)
59
+ {
60
+ result.AddParam(parameters[i].Item1, parameters[i].Item2);
61
+ }
62
+ eventQueue.Enqueue(result);
63
+ return result;
64
+ }
65
+
54
66
  public static IEventParamsBuilder LogFunnelEvent(string eventName, string signature = "")
55
67
  {
56
68
  return LogEvent(eventName).SetAsFunnel(signature);
57
69
  }
58
70
 
59
- public static int GetAccumulatedCount(string eventName)
71
+ public static IEventParamsBuilder LogFunnelEvent(string eventName, Dictionary<string, object> parameters, string signature = "")
72
+ {
73
+ return LogEvent(eventName, parameters).SetAsFunnel(signature);
74
+ }
75
+
76
+ public static IEventParamsBuilder LogFunnelEvent(string eventName, string signature = "", params (string, object)[] parameters)
77
+ {
78
+ return LogEvent(eventName, parameters).SetAsFunnel(signature);
79
+ }
80
+
81
+ public static int GetAccumulatedCount(string eventName, bool withinSession = false)
60
82
  {
61
83
  var eventDetail = localData.GetEventDetail(eventName);
62
- return eventDetail != null ? eventDetail.count : 0;
84
+ return eventDetail != null ? (withinSession ? eventDetail.countInSession : eventDetail.totalCount) : 0;
63
85
  }
64
86
 
65
87
  public static void SetLogEventCondition(Predicate<EventDetail> condition)
@@ -116,20 +138,20 @@ namespace Amanotes.Core
116
138
  localData.eventDetails.Add(new EventDetail
117
139
  {
118
140
  eventName = e.Key,
119
- count = e.Value
141
+ totalCount = e.Value
120
142
  });
121
143
  flag |= IntegrityFlag.NewEvent;
122
144
  continue;
123
145
  }
124
146
 
125
- if (eventDetail.count != e.Value)
147
+ if (eventDetail.totalCount != e.Value)
126
148
  {
127
149
  flag |= IntegrityFlag.DifferentCount;
128
150
  }
129
151
 
130
152
  if (sumEventCount)
131
153
  {
132
- eventDetail.count += e.Value;
154
+ eventDetail.totalCount += e.Value;
133
155
  }
134
156
  }
135
157
 
@@ -169,10 +191,13 @@ namespace Amanotes.Core
169
191
  internal static readonly List<AdapterInfo> listAdapters = new List<AdapterInfo>();
170
192
  internal static readonly AnalyticsData localData = new AnalyticsData().LoadJsonFromFile();
171
193
 
172
- internal static void GetAnalyticAdapters()
194
+ internal static void Init()
173
195
  {
174
196
  listAdapters.Clear();
175
197
  listAdapters.AddRange(Adapter.FindAll<IAnalyticAdapter>());
198
+
199
+ _frameUpdate -= ProcessEventQueue;
200
+ _frameUpdate += ProcessEventQueue;
176
201
  }
177
202
 
178
203
  internal static void ProcessEventQueue()
@@ -187,14 +212,14 @@ namespace Amanotes.Core
187
212
  if (!NormalizeEventName(ref eventData.eventName))
188
213
  continue;
189
214
 
190
- var counter = localData.IncreaseCounter(eventData.eventName);
215
+ var (countInSession, totalCount) = localData.IncreaseCounter(eventData.eventName);
191
216
 
192
217
  if (!ShouldSendEvent(eventData))
193
218
  continue;
194
219
 
195
220
  if (eventData.accumulated)
196
221
  {
197
- eventData.AddParam("accumulated_count", counter);
222
+ eventData.AddParam("accumulated_count", eventData.withinSession ? countInSession : totalCount);
198
223
  }
199
224
 
200
225
  foreach (var m in listAdapters)
@@ -202,7 +227,7 @@ namespace Amanotes.Core
202
227
  if (eventData.ignoreAnalyticIds.Contains(m.id))
203
228
  continue;
204
229
  m.GetAdapterApi<IAnalyticAdapter>().LogEvent(eventData);
205
- if (showAnalyticsLog) Debug.Log($"[{m.id}] Sent event <{eventData.eventName}> ({counter})");
230
+ if (showAnalyticsLog) Debug.Log($"[{m.id}] Sent event <{eventData.eventName}> (in session: {countInSession}, total: {totalCount})");
206
231
  }
207
232
  }
208
233
 
@@ -264,7 +289,9 @@ namespace Amanotes.Core
264
289
  public class EventDetail
265
290
  {
266
291
  public string eventName;
267
- public int count;
292
+ public int totalCount;
293
+ [NonSerialized]
294
+ public int countInSession;
268
295
  }
269
296
 
270
297
  [Flags]
@@ -330,12 +357,13 @@ namespace Amanotes.Core
330
357
  return true;
331
358
  }
332
359
 
333
- internal int IncreaseCounter(string eventName)
360
+ internal (int countInSession, int totalCount) IncreaseCounter(string eventName)
334
361
  {
335
362
  var result = GetEventDetail(eventName, true);
336
- result.count++;
363
+ result.totalCount++;
364
+ result.countInSession++;
337
365
  _dirty = true;
338
- return result.count;
366
+ return (result.countInSession, result.totalCount);
339
367
  }
340
368
 
341
369
  internal void SaveIfDirty()
@@ -383,11 +411,13 @@ namespace Amanotes.Core
383
411
  data.funnelSignature = string.IsNullOrEmpty(signature) ? data.eventName : signature;
384
412
  return ap;
385
413
  }
386
- public static IEventParamsBuilder SetAsAccumulated(this IEventParamsBuilder ap)
414
+ public static IEventParamsBuilder SetAsAccumulated(this IEventParamsBuilder ap, bool withinSession = false)
387
415
  {
388
416
  if (ap == null) return null;
389
417
 
390
- (ap as EventParams).accumulated = true;
418
+ EventParams data = ap as EventParams;
419
+ data.accumulated = true;
420
+ if (withinSession) data.withinSession = true;
391
421
  return ap;
392
422
  }
393
423
 
@@ -39,6 +39,7 @@ namespace Amanotes.Core.Internal
39
39
  {
40
40
  "FirebaseAnalyticsAdapter_v9.1.0",
41
41
  //"AppsflyerAdapter_v6.5.4",
42
+ // "IronsourceAdapter_v7.2.6",
42
43
  };
43
44
  }
44
45
 
package/Runtime/AmaGDK.cs CHANGED
@@ -12,9 +12,10 @@ namespace Amanotes.Core
12
12
  {
13
13
  public partial class AmaGDK : MonoBehaviour
14
14
  {
15
- public const string VERSION = "0.1.9";
15
+ public const string VERSION = "0.1.10";
16
16
 
17
17
  internal static AmaGDK _instance;
18
+ internal static event Action _frameUpdate;
18
19
  private static ConfigAsset _config = null;
19
20
  internal static ConfigAsset Config {
20
21
  get {
@@ -24,7 +25,7 @@ namespace Amanotes.Core
24
25
  return _config;
25
26
  }
26
27
  }
27
-
28
+
28
29
  internal static Status _status = Status.None;
29
30
  internal static Action _onReadyCallback;
30
31
  internal static bool _allowInit = false;
@@ -97,9 +98,10 @@ namespace Amanotes.Core
97
98
  Log($"Adapter {adapter.id} inited!");
98
99
  }
99
100
 
100
- // Init adapters
101
- Analytics.GetAnalyticAdapters();
102
-
101
+ // Init modules (Adapter managers)
102
+ Analytics.Init();
103
+ Ads.Init();
104
+
103
105
  _status = Status.Ready;
104
106
  _onReadyCallback?.Invoke();
105
107
  _onReadyCallback = null;
@@ -109,7 +111,7 @@ namespace Amanotes.Core
109
111
  private void Update()
110
112
  {
111
113
  if (!isReady) return;
112
- Analytics.ProcessEventQueue();
114
+ _frameUpdate?.Invoke();
113
115
  }
114
116
  }
115
117
 
@@ -145,6 +147,16 @@ namespace Amanotes.Core
145
147
  _instance = sdk.AddComponent<AmaGDK>();
146
148
  }
147
149
 
150
+ public static void BeginCoroutine(IEnumerator enumerator)
151
+ {
152
+ _instance.StartCoroutine(enumerator);
153
+ }
154
+
155
+ public static void EndCoroutine(IEnumerator enumerator)
156
+ {
157
+ _instance.StopCoroutine(enumerator);
158
+ }
159
+
148
160
  public static void AddCallback(Action onReady)
149
161
  {
150
162
  if (onReady == null)
@@ -123,7 +123,7 @@ public class MigrationTest
123
123
  analyticsData.eventDetails.Add(new EventDetail
124
124
  {
125
125
  eventName = e.Key,
126
- count = e.Value
126
+ totalCount = e.Value
127
127
  });
128
128
  }
129
129
 
@@ -132,7 +132,7 @@ public class MigrationTest
132
132
  analyticsData.eventDetails.Add(new EventDetail
133
133
  {
134
134
  eventName = "migration_error",
135
- count = migrationError
135
+ totalCount = migrationError
136
136
  });
137
137
  }
138
138
 
@@ -154,7 +154,7 @@ public class MigrationTest
154
154
  var eventDetail = analyticsData.GetEventDetail(errEventName);
155
155
  if (eventDetail != null)
156
156
  {
157
- Assert.IsTrue(eventDetail.count == 1);
157
+ Assert.IsTrue(eventDetail.totalCount == 1);
158
158
  }
159
159
  else
160
160
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2020.3",
@@ -1,6 +0,0 @@
1
- using System.Collections.Generic;
2
-
3
- namespace Amanotes.Core
4
- {
5
-
6
- }
@@ -1,8 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: d1a686515ec7946df9492f35e9638fea
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant: