Skip to content

Commit fffbebd

Browse files
feat(audience): normalize platform/osFamily wire values, add isEditor (SDK-343)
- platform now sends Windows, macOS, Linux, iOS, Android. WindowsPlayer/WindowsEditor and OSXPlayer/OSXEditor and LinuxPlayer/LinuxEditor each collapse to one OS string. Studios no longer need LIKE 'Windows%' to filter by OS. - osFamily rewrites MacOSX to macOS so the wire value matches Apple's branding. Windows, Linux, Other unchanged. - New isEditor bool on game_launch sources from Application.isEditor. Replaces the Player vs Editor signal previously buried inside platform, so studios can filter dev runs cleanly. - Unmapped RuntimePlatform values (console, WebGL, server builds) still fall back to the raw enum string so console traffic is not silently dropped. - DeviceCollectorTests covers the new mappings and isEditor true/false. ImmutableAudienceTests provider example updated to "Windows". Breaking wire-format change. Blocks immutable/documentation#83 (SDK-319). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d4998a8 commit fffbebd

3 files changed

Lines changed: 77 additions & 6 deletions

File tree

src/Packages/Audience/Runtime/Unity/DeviceCollector.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,21 @@ internal static Dictionary<string, object> CollectContext()
4747
}
4848

4949
internal static Dictionary<string, object> CollectGameLaunchProperties(
50-
RuntimePlatform? platformOverride = null)
50+
RuntimePlatform? platformOverride = null,
51+
OperatingSystemFamily? osFamilyOverride = null,
52+
bool? isEditorOverride = null)
5153
{
5254
var platform = platformOverride ?? Application.platform;
55+
var osFamily = osFamilyOverride ?? SystemInfo.operatingSystemFamily;
56+
var isEditor = isEditorOverride ?? Application.isEditor;
5357
var props = new Dictionary<string, object>
5458
{
5559
["platform"] = PlatformName(platform),
60+
["isEditor"] = isEditor,
5661
["version"] = Truncate(Application.version, 256),
5762
["buildGuid"] = Truncate(Application.buildGUID, 256),
5863
["unityVersion"] = Truncate(Application.unityVersion, 256),
59-
["osFamily"] = SystemInfo.operatingSystemFamily.ToString(),
64+
["osFamily"] = OsFamilyName(osFamily),
6065
["deviceModel"] = Truncate(SystemInfo.deviceModel, 256),
6166
["gpu"] = Truncate(SystemInfo.graphicsDeviceName, 256),
6267
["gpuVendor"] = Truncate(SystemInfo.graphicsDeviceVendor, 256),
@@ -106,10 +111,20 @@ internal static Dictionary<string, object> CollectGameLaunchProperties(
106111

107112
private static string PlatformName(RuntimePlatform platform) => platform switch
108113
{
114+
RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsEditor => "Windows",
115+
RuntimePlatform.OSXPlayer or RuntimePlatform.OSXEditor => "macOS",
116+
RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxEditor => "Linux",
109117
RuntimePlatform.IPhonePlayer => "iOS",
118+
RuntimePlatform.Android => "Android",
110119
_ => platform.ToString(),
111120
};
112121

122+
private static string OsFamilyName(OperatingSystemFamily family) => family switch
123+
{
124+
OperatingSystemFamily.MacOSX => "macOS",
125+
_ => family.ToString(),
126+
};
127+
113128
private static string Truncate(string s, int max)
114129
{
115130
if (string.IsNullOrEmpty(s) || s.Length <= max) return s;

src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields()
11871187
{
11881188
ImmutableAudience.LaunchContextProvider = () => new Dictionary<string, object>
11891189
{
1190-
["platform"] = "WindowsPlayer",
1190+
["platform"] = "Windows",
11911191
["version"] = "1.2.3",
11921192
["buildGuid"] = "a1b2c3d4e5f6",
11931193
["unityVersion"] = "2022.3.20f1",
@@ -1201,7 +1201,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields()
12011201
.Select(File.ReadAllText)
12021202
.FirstOrDefault(c => c.Contains("\"game_launch\""));
12031203
Assert.IsNotNull(launchFile, "game_launch should have been enqueued");
1204-
StringAssert.Contains("\"platform\":\"WindowsPlayer\"", launchFile);
1204+
StringAssert.Contains("\"platform\":\"Windows\"", launchFile);
12051205
StringAssert.Contains("\"version\":\"1.2.3\"", launchFile);
12061206
StringAssert.Contains("\"buildGuid\":\"a1b2c3d4e5f6\"", launchFile);
12071207
StringAssert.Contains("\"unityVersion\":\"2022.3.20f1\"", launchFile);

src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void CollectGameLaunchProperties_AlwaysContainsCrossPlatformFields()
5252
{
5353
var props = DeviceCollector.CollectGameLaunchProperties();
5454
foreach (var key in new[] {
55-
"platform", "version", "buildGuid", "unityVersion",
55+
"platform", "isEditor", "version", "buildGuid", "unityVersion",
5656
"osFamily", "deviceModel", "gpu", "gpuVendor",
5757
"cpu", "cpuCores", "ramMb" })
5858
{
@@ -134,11 +134,67 @@ public void CollectGameLaunchProperties_NonIOS_DoesNotContainIdfv()
134134
}
135135

136136
[Test]
137-
public void CollectGameLaunchProperties_iOS_ContainsPlatformIPhonePlayer()
137+
public void CollectGameLaunchProperties_iOS_PlatformIsIOS()
138138
{
139139
IDFVBridge.Impl = () => null;
140140
var props = DeviceCollector.CollectGameLaunchProperties(RuntimePlatform.IPhonePlayer);
141141
Assert.AreEqual("iOS", props["platform"]);
142142
}
143+
144+
// -----------------------------------------------------------------
145+
// PlatformName mapping: collapse Player/Editor variants to OS name
146+
// -----------------------------------------------------------------
147+
148+
[TestCase(RuntimePlatform.WindowsPlayer, "Windows")]
149+
[TestCase(RuntimePlatform.WindowsEditor, "Windows")]
150+
[TestCase(RuntimePlatform.OSXPlayer, "macOS")]
151+
[TestCase(RuntimePlatform.OSXEditor, "macOS")]
152+
[TestCase(RuntimePlatform.LinuxPlayer, "Linux")]
153+
[TestCase(RuntimePlatform.LinuxEditor, "Linux")]
154+
[TestCase(RuntimePlatform.IPhonePlayer, "iOS")]
155+
[TestCase(RuntimePlatform.Android, "Android")]
156+
public void CollectGameLaunchProperties_Platform_MapsToLaymanName(
157+
RuntimePlatform input, string expected)
158+
{
159+
var props = DeviceCollector.CollectGameLaunchProperties(input);
160+
Assert.AreEqual(expected, props["platform"]);
161+
}
162+
163+
[Test]
164+
public void CollectGameLaunchProperties_Platform_UnmappedFallsBackToEnumName()
165+
{
166+
// Console / unsupported targets must not be silently dropped.
167+
var props = DeviceCollector.CollectGameLaunchProperties(RuntimePlatform.WebGLPlayer);
168+
Assert.AreEqual("WebGLPlayer", props["platform"]);
169+
}
170+
171+
// -----------------------------------------------------------------
172+
// OsFamily mapping: rewrite Unity's MacOSX to Apple's macOS
173+
// -----------------------------------------------------------------
174+
175+
[TestCase(OperatingSystemFamily.Windows, "Windows")]
176+
[TestCase(OperatingSystemFamily.MacOSX, "macOS")]
177+
[TestCase(OperatingSystemFamily.Linux, "Linux")]
178+
[TestCase(OperatingSystemFamily.Other, "Other")]
179+
public void CollectGameLaunchProperties_OsFamily_MapsToLaymanName(
180+
OperatingSystemFamily input, string expected)
181+
{
182+
var props = DeviceCollector.CollectGameLaunchProperties(
183+
osFamilyOverride: input);
184+
Assert.AreEqual(expected, props["osFamily"]);
185+
}
186+
187+
// -----------------------------------------------------------------
188+
// isEditor: distinguishes dev runs from production player traffic
189+
// -----------------------------------------------------------------
190+
191+
[TestCase(true)]
192+
[TestCase(false)]
193+
public void CollectGameLaunchProperties_IsEditor_ReflectsOverride(bool isEditor)
194+
{
195+
var props = DeviceCollector.CollectGameLaunchProperties(
196+
isEditorOverride: isEditor);
197+
Assert.AreEqual(isEditor, props["isEditor"]);
198+
}
143199
}
144200
}

0 commit comments

Comments
 (0)