You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(audience-unity): add Unity integration layer for context, lifecycle, and performance (SDK-146)
AudienceUnityHooks installs on SubsystemRegistration and wires:
- DefaultPersistentDataPathProvider from Application.persistentDataPath
- LaunchContextProvider with DeviceCollector's one-shot game_launch
fields (platform, version, buildGuid, unityVersion, osFamily,
deviceModel, gpu*, cpu*, ramMb, screenDpi)
- ContextProvider with userAgent / locale / timezone / screen, merged
into every outgoing message.context
- PerformanceSnapshotProvider returns the fpsAvg / fpsMin /
memoryUsedMb / memoryReservedMb accumulated since the last read;
Session.OnHeartbeat reads and merges it
- Application.quitting -> ImmutableAudience.Shutdown
- UnityLifecycleBridge forwards OnApplicationPause / OnApplicationFocus
to ImmutableAudience.OnPause / OnResume
New Unity-layer files (Runtime/Unity/):
- DeviceCollector.cs — IL2CPP-safe SystemInfo / Screen / Application
readers. Strings capped at 256 chars to mirror the Web SDK identifier
cap (core/src/validation.ts MAX_STRING_LENGTH)
- PerformanceCollector.cs — per-frame fps + memory accumulator read
off the main thread via SnapshotAndReset
- UnityLifecycleBridge.cs — lifecycle forwarder + per-frame tick
Core changes in ImmutableAudience:
- LaunchContextProvider / ContextProvider typed as
Func<IReadOnlyDictionary<string, object>>? so the cached snapshot
cannot be mutated by any downstream reader
- PerformanceSnapshotProvider added with the same one-shot-capture
contract
- All three Session constructor sites (Init, Reset-creates-session,
None -> Anonymous/Full upgrade in SetConsent) pass
PerformanceSnapshotProvider as the second arg
- MergeUnityContext merges ContextProvider output into every outgoing
message.context before EnqueueChecked; throws and null returns are
swallowed so a misbehaving layer cannot drop events
Build and test infrastructure:
- Directory.Build.props redirects bin/obj to repo-root artifacts/ so
dotnet output doesn't leak into Unity's asset importer scan path
- ConstantsTests walks up from the test binary to find the package
root so the Directory.Build.props redirect doesn't break it
- com.immutable.audience / .unity asmdefs updated
- link.xml preserves Unity hooks from IL2CPP stripping
- .gitignore adds artifacts/
Tests:
- ContextProvider_Set / _Throwing / _ReturnsNull pin the merge +
swallow behaviour
- PerformanceSnapshotProvider_ReachesHeartbeat variants pin Init,
consent upgrade, and Reset ctor sites — dropping the provider from
any single site fails a distinct test
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments