1
+ using System ;
2
+ using UnityEngine . Analytics ;
3
+
4
+ namespace UnityEditor . VSAttribution . OneSignalSDK
5
+ {
6
+ public static class VSAttribution
7
+ {
8
+ const int k_VersionId = 4 ;
9
+ const int k_MaxEventsPerHour = 10 ;
10
+ const int k_MaxNumberOfElements = 1000 ;
11
+
12
+ const string k_VendorKey = "unity.vsp-attribution" ;
13
+ const string k_EventName = "vspAttribution" ;
14
+
15
+ static bool RegisterEvent ( )
16
+ {
17
+ AnalyticsResult result = EditorAnalytics . RegisterEventWithLimit ( k_EventName , k_MaxEventsPerHour ,
18
+ k_MaxNumberOfElements , k_VendorKey , k_VersionId ) ;
19
+
20
+ var isResultOk = result == AnalyticsResult . Ok ;
21
+ return isResultOk ;
22
+ }
23
+
24
+ [ Serializable ]
25
+ struct VSAttributionData
26
+ {
27
+ public string actionName ;
28
+ public string partnerName ;
29
+ public string customerUid ;
30
+ public string extra ;
31
+ }
32
+
33
+ /// <summary>
34
+ /// Registers and attempts to send a Verified Solutions Attribution event.
35
+ /// </summary>
36
+ /// <param name="actionName">Name of the action, identifying a place this event was called from.</param>
37
+ /// <param name="partnerName">Identifiable Verified Solutions Partner's name.</param>
38
+ /// <param name="customerUid">Unique identifier of the customer using Partner's Verified Solution.</param>
39
+ public static AnalyticsResult SendAttributionEvent ( string actionName , string partnerName , string customerUid )
40
+ {
41
+ try
42
+ {
43
+ // Are Editor Analytics enabled ? (Preferences)
44
+ if ( ! EditorAnalytics . enabled )
45
+ return AnalyticsResult . AnalyticsDisabled ;
46
+
47
+ if ( ! RegisterEvent ( ) )
48
+ return AnalyticsResult . InvalidData ;
49
+
50
+ // Create an expected data object
51
+ var eventData = new VSAttributionData
52
+ {
53
+ actionName = actionName ,
54
+ partnerName = partnerName ,
55
+ customerUid = customerUid ,
56
+ extra = "{}"
57
+ } ;
58
+
59
+ return EditorAnalytics . SendEventWithLimit ( k_EventName , eventData , k_VersionId ) ;
60
+ }
61
+ catch
62
+ {
63
+ // Fail silently
64
+ return AnalyticsResult . AnalyticsDisabled ;
65
+ }
66
+ }
67
+ }
68
+ }
0 commit comments