Skip to content

Conversation

ekcoh
Copy link
Collaborator

@ekcoh ekcoh commented Dec 18, 2023

Description

This PR introduces Unity Editor analytics support for getting insight into Input Action editor engagement and usage. Analytics have been designed to enable differentiation between an editor embedded into Project Settings (Project-wide actions) as well as a free-floating asset based editor, but otherwise be comparable. The analytics currently only track engagement on a high-level without being specific about specific user actions. Defined metrics are tracked via associated DASD ticket, see ISX-1546 for reference.

Note that this PR has been marked as a CHANGE instead of NEW since it doesn't introduce new user features.

Changes made

Added new class InputActionsEditorSessionAnalytic acting as a proxy object around InputActionsEditorSessionData to provide abstraction around counting operations to prevent direct access and possible related mistakes in code providing metrics. The purpose of this class is to track and report analytics related to .inputactions asset editor windows.

Added new classes to track editor (Inspector) editor changes for the following components:

  • PlayerInputEditorAnalytic tracking selected changes to configuration of PlayerInput.
  • PlayerInputManagerEditorAnalytic tracking selected changes to configuration of PlayerInputManager.
  • OnScreenStickEditorAnalytic tracking selected changes to configuration of OnScreenStick.
  • VirtualMouseInput tracking selected changes to configuration of VirtualMouseInput

Added new class InputComponentEditorAnalytic tracking statistics of how often an Inspector with the associated component editor is displayed for the following components:

  • PlayerInput
  • PlayerInputManager
  • OnScreenStick
  • OnScreenButton
  • VirtualMouseInput
  • TouchSimulation
  • StandaloneInputModule
  • InputSystemUIInputModule

Added new class InputBuildAnalytic that reports statistics on settings when a project is being built. Currently all InputSettings are being logged, see associated spreadsheet (via internal ticket) for details.

Other changes

  • Modified new analytics code to conditionally utilise UnityEngine.Analytics.IAnalytic.IData when compiled on Unity 2023.2 or later and otherwise use legacy setup for analytics. This is achieved by conditionally defining the new IInputAnalytic to either derive from the new IAnalytic or to define a similar interface. This simplifies test and usage code.
  • Refactored existing analytics collection code and reduced number of allocations by using arrays directly instead of lists.
  • Refactored existing analytics constants into C# constants.
  • Refactored analytics tests based on above changed.
  • Refactored IInputRuntime interface and derived classes NativeInputRuntime and InputTestRuntime.
  • Potentially fixed a bug in NativeInputRuntime since previously did not send analytics unless UNITY_ANALYTICS was defined, but this do not seem to be defined in editor anyway. Any insight into this from reviewers would be useful.
  • Modified existing analytics code (Not introduced in this PR) to conditionally utilise UnityEngine.Analytics.IAnalytic.IData when compiled on Unity 2023.2 or later and otherwise use legacy setup for analytics.
  • Added test cases to cover new editor session analytics.
  • Added hooks to UTIK editor to measure action map, action, binding and control scheme edits in addition to explicit and implicit saves as well as reset.
  • FIX for ISXB-930 (Visualisation components)

Notes

Development guidelines for how to integrate editor analytics and test them are linked form the internal ISX ticket.
This PR do not introduce analytics for legacy IMGUI editor. If this is needed additional work is needed to setup corresponding hooks for that editor.

This PR can be reviewed and tested as is but should likely not be merged until verified with help of backend engineers so it doesn't introduce regressions for existing analytics and to verify that new analytics are correct.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests added to CoreTests_Analytics.cs
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

ekcoh added 13 commits October 3, 2023 09:16
# Conflicts:
#	Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorSettingsProvider.cs
#	Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
# Conflicts:
#	Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorSettingsProvider.cs
#	Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindowUtils.cs
@ekcoh ekcoh added the work in progress Indicates that the PR is work in progress and any review efforts can be post-poned. label Dec 18, 2023
@ekcoh ekcoh changed the title Input Action Editor Session Analytics Support (ISX-1546) WIP: Input Action Editor Session Analytics Support (ISX-1546) Dec 18, 2023
@ekcoh ekcoh changed the title WIP: Input Action Editor Session Analytics Support (ISX-1546) Input Action Editor Session Analytics Support (ISX-1546) Dec 21, 2023
@ekcoh
Copy link
Collaborator Author

ekcoh commented Dec 21, 2023

One problem with this PR/branch is that I noticed formatter fails on InputAnalytics.cs with issue relating to matching an opening bracket early in the file. Not sure why this is, if someone spots the error that I fail to find it would be very helpful.

@ekcoh ekcoh removed the work in progress Indicates that the PR is work in progress and any review efforts can be post-poned. label Dec 21, 2023
@ekcoh ekcoh changed the title Input Action Editor Session Analytics Support (ISX-1546) Input Action Editor Session Analytics Support + Refactor (ISX-1546) Dec 21, 2023
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failures in CI need to be looked at and this also introduces errors when adding new maps and actions in the custom action asset window.

For example:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.Editor.Commands+<>c.<AddActionMap>b__2_0 (UnityEngine.InputSystem.Editor.InputActionsEditorState& state) (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs:33)
UnityEngine.InputSystem.Editor.StateContainer.Dispatch (UnityEngine.InputSystem.Editor.Command command) (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/StateContainer.cs:35)
UnityEngine.InputSystem.Editor.ViewBase`1[TViewState].Dispatch (UnityEngine.InputSystem.Editor.Command command) (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs:70)
UnityEngine.InputSystem.Editor.ActionMapsView.AddActionMap () (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs:113)
UnityEngine.UIElements.Clickable.Invoke (UnityEngine.UIElements.EventBase evt) (at D:/Gitrepo/unity/Modules/UIElements/Core/Clickable.cs:245)
UnityEngine.UIElements.Clickable.ProcessUpEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.Vector2 localPosition, System.Int32 pointerId) (at D:/Gitrepo/unity/Modules/UIElements/Core/Clickable.cs:342)
UnityEngine.UIElements.Clickable.OnPointerUp (UnityEngine.UIElements.PointerUpEvent evt) (at D:/Gitrepo/unity/Modules/UIElements/Core/Clickable.cs:209)
UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt) (at D:/Gitrepo/unity/Modules/UIElements/Core/Events/EventCallback.cs:64)
UnityEngine.UIElements.EventCallbackRegistry+DynamicCallbackList.Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target) (at D:/Gitrepo/unity/Modules/UIElements/Core/Events/EventCallbackRegistry.cs:228)
UnityEngine.UIElements.EventDispatchUtilities.HandleEventAcrossPropagationPathWithCompatibilityEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.EventBase compatibilityEvt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target, System.Boolean isCapturingTarget) (at D:/Gitrepo/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:310)
UnityEngine.UIElements.EventDispatchUtilities.DispatchToCapturingElementOrElementUnderPointer (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, System.Int32 pointerId, UnityEngine.Vector2 position) (at D:/Gitrepo/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:578)
UnityEngine.UIElements.PointerEventBase`1[T].Dispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at D:/Gitrepo/unity/Modules/UIElements/Core/Events/PointerEvents.cs:1180)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at D:/Gitrepo/unity/Modules/UIElements/Core/EventDispatcher.cs:336)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at D:/Gitrepo/unity/Modules/UIElements/Core/EventDispatcher.cs:200)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at D:/Gitrepo/unity/Modules/UIElements/Core/Panel.cs:625)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at D:/Gitrepo/unity/Modules/UIElements/Core/UIElementsUtility.cs:506)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at D:/Gitrepo/unity/Modules/UIElements/Core/UIElementsUtility.cs:225)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at D:/Gitrepo/unity/Modules/UIElements/Core/UIElementsUtility.cs:74)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at D:/Gitrepo/unity/Modules/UIElements/Core/UIElementsUtility.cs:28)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at D:/Gitrepo/unity/Modules/IMGUI/GUIUtility.cs:206)

@ekcoh
Copy link
Collaborator Author

ekcoh commented Jan 8, 2024

Thanks @Pauliusd01 I'll check and follow-up with additional changes

Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is one line that needs fixing

@ekcoh ekcoh removed the work in progress Indicates that the PR is work in progress and any review efforts can be post-poned. label Jun 28, 2024
Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the field fix - follow on tidy ups look reasonable.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Jun 28, 2024

All associated events have been verified to be received in backend.

@Pauliusd01 Pauliusd01 self-requested a review July 1, 2024 14:05
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, checked the basic input actions window functionality that was throwing errors before, most of the sample scene functionality and checked analytics using the internal testing package

@ekcoh ekcoh merged commit badaef8 into develop Jul 5, 2024
@ekcoh ekcoh deleted the isxb-1546-analytics branch July 5, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants