diff --git a/src/Packages/Audience/Runtime/Unity/DeviceCollector.cs b/src/Packages/Audience/Runtime/Unity/DeviceCollector.cs index 9751b8e3e..c65270269 100644 --- a/src/Packages/Audience/Runtime/Unity/DeviceCollector.cs +++ b/src/Packages/Audience/Runtime/Unity/DeviceCollector.cs @@ -47,12 +47,15 @@ internal static Dictionary CollectContext() } internal static Dictionary CollectGameLaunchProperties( - RuntimePlatform? platformOverride = null) + RuntimePlatform? platformOverride = null, + bool? isEditorOverride = null) { var platform = platformOverride ?? Application.platform; + var isEditor = isEditorOverride ?? Application.isEditor; var props = new Dictionary { ["platform"] = PlatformName(platform), + ["isEditor"] = isEditor, ["version"] = Truncate(Application.version, 256), ["buildGuid"] = Truncate(Application.buildGUID, 256), ["unityVersion"] = Truncate(Application.unityVersion, 256), @@ -106,7 +109,11 @@ internal static Dictionary CollectGameLaunchProperties( private static string PlatformName(RuntimePlatform platform) => platform switch { + RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsEditor => "Windows", + RuntimePlatform.OSXPlayer or RuntimePlatform.OSXEditor => "macOS", + RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxEditor => "Linux", RuntimePlatform.IPhonePlayer => "iOS", + RuntimePlatform.Android => "Android", _ => platform.ToString(), }; diff --git a/src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs b/src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs index 4a6ed38c5..0e0d4c712 100644 --- a/src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs +++ b/src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs @@ -1189,7 +1189,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields() { ImmutableAudience.LaunchContextProvider = () => new Dictionary { - ["platform"] = "WindowsPlayer", + ["platform"] = "Windows", ["version"] = "1.2.3", ["buildGuid"] = "a1b2c3d4e5f6", ["unityVersion"] = "2022.3.20f1", @@ -1203,7 +1203,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields() .Select(File.ReadAllText) .FirstOrDefault(c => c.Contains("\"game_launch\"")); Assert.IsNotNull(launchFile, "game_launch should have been enqueued"); - StringAssert.Contains("\"platform\":\"WindowsPlayer\"", launchFile); + StringAssert.Contains("\"platform\":\"Windows\"", launchFile); StringAssert.Contains("\"version\":\"1.2.3\"", launchFile); StringAssert.Contains("\"buildGuid\":\"a1b2c3d4e5f6\"", launchFile); StringAssert.Contains("\"unityVersion\":\"2022.3.20f1\"", launchFile); diff --git a/src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs b/src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs index 32550d0eb..53fcb6d66 100644 --- a/src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs +++ b/src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs @@ -52,7 +52,7 @@ public void CollectGameLaunchProperties_AlwaysContainsCrossPlatformFields() { var props = DeviceCollector.CollectGameLaunchProperties(); foreach (var key in new[] { - "platform", "version", "buildGuid", "unityVersion", + "platform", "isEditor", "version", "buildGuid", "unityVersion", "osFamily", "deviceModel", "gpu", "gpuVendor", "cpu", "cpuCores", "ramMb" }) { @@ -134,11 +134,51 @@ public void CollectGameLaunchProperties_NonIOS_DoesNotContainIdfv() } [Test] - public void CollectGameLaunchProperties_iOS_ContainsPlatformIPhonePlayer() + public void CollectGameLaunchProperties_iOS_PlatformIsIOS() { IDFVBridge.Impl = () => null; var props = DeviceCollector.CollectGameLaunchProperties(RuntimePlatform.IPhonePlayer); Assert.AreEqual("iOS", props["platform"]); } + + // ----------------------------------------------------------------- + // PlatformName mapping: collapse Player/Editor variants to OS name + // ----------------------------------------------------------------- + + [TestCase(RuntimePlatform.WindowsPlayer, "Windows")] + [TestCase(RuntimePlatform.WindowsEditor, "Windows")] + [TestCase(RuntimePlatform.OSXPlayer, "macOS")] + [TestCase(RuntimePlatform.OSXEditor, "macOS")] + [TestCase(RuntimePlatform.LinuxPlayer, "Linux")] + [TestCase(RuntimePlatform.LinuxEditor, "Linux")] + [TestCase(RuntimePlatform.IPhonePlayer, "iOS")] + [TestCase(RuntimePlatform.Android, "Android")] + public void CollectGameLaunchProperties_Platform_MapsToLaymanName( + RuntimePlatform input, string expected) + { + var props = DeviceCollector.CollectGameLaunchProperties(input); + Assert.AreEqual(expected, props["platform"]); + } + + [Test] + public void CollectGameLaunchProperties_Platform_UnmappedFallsBackToEnumName() + { + // Console / unsupported targets must not be silently dropped. + var props = DeviceCollector.CollectGameLaunchProperties(RuntimePlatform.WebGLPlayer); + Assert.AreEqual("WebGLPlayer", props["platform"]); + } + + // ----------------------------------------------------------------- + // isEditor: distinguishes dev runs from production player traffic + // ----------------------------------------------------------------- + + [TestCase(true)] + [TestCase(false)] + public void CollectGameLaunchProperties_IsEditor_ReflectsOverride(bool isEditor) + { + var props = DeviceCollector.CollectGameLaunchProperties( + isEditorOverride: isEditor); + Assert.AreEqual(isEditor, props["isEditor"]); + } } }