@@ -23,35 +23,9 @@ namespace Unity.MLAgents.Analytics
2323{
2424 internal static class TrainingAnalytics
2525 {
26- const string k_VendorKey = "unity.ml-agents" ;
27- const string k_TrainingEnvironmentInitializedEventName = "ml_agents_training_environment_initialized" ;
28- const string k_TrainingBehaviorInitializedEventName = "ml_agents_training_behavior_initialized" ;
29- const string k_RemotePolicyInitializedEventName = "ml_agents_remote_policy_initialized" ;
30-
31- private static readonly string [ ] s_EventNames =
32- {
33- k_TrainingEnvironmentInitializedEventName ,
34- k_TrainingBehaviorInitializedEventName ,
35- k_RemotePolicyInitializedEventName
36- } ;
37-
38- /// <summary>
39- /// Hourly limit for this event name
40- /// </summary>
41- const int k_MaxEventsPerHour = 1000 ;
42-
43- /// <summary>
44- /// Maximum number of items in this event.
45- /// </summary>
46- const int k_MaxNumberOfElements = 1000 ;
47-
4826 private static bool s_SentEnvironmentInitialized ;
4927
5028#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
51- /// <summary>
52- /// Whether or not we've registered this particular event yet
53- /// </summary>
54- static bool s_EventsRegistered ;
5529
5630 /// <summary>
5731 /// Behaviors that we've already sent events for.
@@ -69,19 +43,6 @@ internal static class TrainingAnalytics
6943 internal static bool EnableAnalytics ( )
7044 {
7145#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
72- if ( s_EventsRegistered )
73- {
74- return true ;
75- }
76- foreach ( var eventName in s_EventNames )
77- {
78- AnalyticsResult result = EditorAnalytics . RegisterEventWithLimit ( eventName , k_MaxEventsPerHour , k_MaxNumberOfElements , k_VendorKey ) ;
79- if ( result != AnalyticsResult . Ok )
80- {
81- return false ;
82- }
83- }
84- s_EventsRegistered = true ;
8546
8647 if ( s_SentRemotePolicyInitialized == null )
8748 {
@@ -90,7 +51,7 @@ internal static bool EnableAnalytics()
9051 s_TrainingSessionGuid = Guid . NewGuid ( ) ;
9152 }
9253
93- return s_EventsRegistered ;
54+ return true ;
9455#else
9556 return false ;
9657#endif // MLA_UNITY_ANALYTICS_MODULE
@@ -137,12 +98,12 @@ public static void TrainingEnvironmentInitialized(TrainingEnvironmentInitialized
13798
13899 // Note - to debug, use JsonUtility.ToJson on the event.
139100 // Debug.Log(
140- // $"Would send event {k_TrainingEnvironmentInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
101+ // $"Would send event ml_agents_training_environment_initialized with body {JsonUtility.ToJson(tbiEvent, true)}"
141102 // );
142103#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS
143104 if ( AnalyticsUtils . s_SendEditorAnalytics )
144105 {
145- EditorAnalytics . SendEventWithLimit ( k_TrainingEnvironmentInitializedEventName , tbiEvent ) ;
106+ EditorAnalytics . SendAnalytic ( tbiEvent ) ;
146107 }
147108#endif
148109 }
@@ -175,11 +136,11 @@ IList<IActuator> actuators
175136 var data = GetEventForRemotePolicy ( behaviorName , sensors , actionSpec , actuators ) ;
176137 // Note - to debug, use JsonUtility.ToJson on the event.
177138 // Debug.Log(
178- // $"Would send event {k_RemotePolicyInitializedEventName} with body {JsonUtility.ToJson(data, true)}"
139+ // $"Would send event ml_agents_remote_policy_initialized with body {JsonUtility.ToJson(data, true)}"
179140 // );
180141 if ( AnalyticsUtils . s_SendEditorAnalytics )
181142 {
182- EditorAnalytics . SendEventWithLimit ( k_RemotePolicyInitializedEventName , data ) ;
143+ EditorAnalytics . SendAnalytic ( data ) ;
183144 }
184145#endif
185146 }
@@ -203,7 +164,7 @@ internal static TrainingBehaviorInitializedEvent SanitizeTrainingBehaviorInitial
203164 // Context: The config field was added at the same time as trainer side hashing, so messages including it should already be hashed.
204165 if ( tbiEvent . Config . Length == 0 || tbiEvent . BehaviorName . Length != 64 )
205166 {
206- tbiEvent . BehaviorName = AnalyticsUtils . Hash ( k_VendorKey , tbiEvent . BehaviorName ) ;
167+ tbiEvent . BehaviorName = AnalyticsUtils . Hash ( AnalyticsConstants . k_VendorKey , tbiEvent . BehaviorName ) ;
207168 }
208169
209170 return tbiEvent ;
@@ -233,11 +194,11 @@ public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent
233194
234195 // Note - to debug, use JsonUtility.ToJson on the event.
235196 // Debug.Log(
236- // $"Would send event {k_TrainingBehaviorInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
197+ // $"Would send event ml_agents_training_behavior_initialized with body {JsonUtility.ToJson(tbiEvent, true)}"
237198 // );
238199 if ( AnalyticsUtils . s_SendEditorAnalytics )
239200 {
240- EditorAnalytics . SendEventWithLimit ( k_TrainingBehaviorInitializedEventName , tbiEvent ) ;
201+ EditorAnalytics . SendAnalytic ( tbiEvent ) ;
241202 }
242203#endif
243204 }
@@ -252,7 +213,7 @@ IList<IActuator> actuators
252213 var remotePolicyEvent = new RemotePolicyInitializedEvent ( ) ;
253214
254215 // Hash the behavior name so that there's no concern about PII or "secret" data being leaked.
255- remotePolicyEvent . BehaviorName = AnalyticsUtils . Hash ( k_VendorKey , behaviorName ) ;
216+ remotePolicyEvent . BehaviorName = AnalyticsUtils . Hash ( AnalyticsConstants . k_VendorKey , behaviorName ) ;
256217
257218 remotePolicyEvent . TrainingSessionGuid = s_TrainingSessionGuid . ToString ( ) ;
258219 remotePolicyEvent . ActionSpec = EventActionSpec . FromActionSpec ( actionSpec ) ;
0 commit comments