Unity error tracking installation
- 1
Install the Unity SDK
RequiredPostHog is available for Unity through the Unity Package Manager.
- Open Window > Package Manager.
- Click the + button and select Add package from git URL.
- Enter
https://github.com/PostHog/posthog-unity.git?path=com.posthog.unity.
The Unity SDK requires Unity 2021.3 LTS or later and the .NET Standard 2.1 API Compatibility Level.
- 2
Configure PostHog
RequiredThe easiest way to configure PostHog is through the Unity Inspector:
- Go to Edit > Project Settings > PostHog.
- Enter your API Key and select your Host.
- Keep Capture Exceptions enabled.
The settings asset is created at
Assets/Resources/PostHogSettings.asset. PostHog automatically initializes when your game starts using these settings.You can also initialize PostHog in code:
C#You can find your project token and instance address in the project settings page in PostHog.
- 3
Capture exceptions
RequiredThe Unity SDK captures exception events automatically by default. On most platforms, it captures exceptions reported through Unity's exception logging pipeline. On WebGL, it listens for Unity exception log messages.
Captured events include Unity and C# stack frames when available, exception type, exception message, whether the exception was handled, and Unity SDK metadata.
For handled exceptions, call
CaptureExceptionmanually:C#Identified usersCall
PostHog.IdentifyAsync(...)after login to link exception events to known users in PostHog. - 4
Configure error tracking options
OptionalAll error tracking options can be set through the Unity Inspector or in
PostHogConfig:Option Type Default Description CaptureExceptionsboolean trueEnables automatic exception capture. ExceptionDebounceIntervalMsinteger 1000Minimum milliseconds between automatic exception captures. Set to 0to disable debouncing.CaptureExceptionsInEditorboolean trueCaptures exceptions while running in the Unity Editor. To disable automatic exception capture:
C# Verify error tracking
RecommendedTrigger a test exception in Play Mode and confirm it appears in the Error Tracking tab.
C#To test automatic capture, report an exception through Unity's logger:
C#