Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Packages/Audience/Runtime/Unity/DeviceCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ internal static Dictionary<string, object> CollectContext()
}

internal static Dictionary<string, object> CollectGameLaunchProperties(
RuntimePlatform? platformOverride = null)
RuntimePlatform? platformOverride = null,
bool? isEditorOverride = null)
{
var platform = platformOverride ?? Application.platform;
var isEditor = isEditorOverride ?? Application.isEditor;
var props = new Dictionary<string, object>
{
["platform"] = PlatformName(platform),
["isEditor"] = isEditor,
Comment thread
ImmutableJeffrey marked this conversation as resolved.
["version"] = Truncate(Application.version, 256),
["buildGuid"] = Truncate(Application.buildGUID, 256),
["unityVersion"] = Truncate(Application.unityVersion, 256),
Expand Down Expand Up @@ -106,7 +109,11 @@ internal static Dictionary<string, object> 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(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
{
ImmutableAudience.LaunchContextProvider = () => new Dictionary<string, object>
{
["platform"] = "WindowsPlayer",
["platform"] = "Windows",
["version"] = "1.2.3",
["buildGuid"] = "a1b2c3d4e5f6",
["unityVersion"] = "2022.3.20f1",
Expand All @@ -1203,7 +1203,7 @@
.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);
Expand Down Expand Up @@ -1652,8 +1652,8 @@
// First launch: bridge fetch in flight, provider returns null.
// Second launch: cache populated, provider returns the referrer.
// Event must fire on the second Init even though it missed the first.
string? firstCallReturn = null;

Check warning on line 1655 in src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests (.NET)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 1655 in src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests (.NET)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
string? secondCallReturn = "utm_source=second_launch";

Check warning on line 1656 in src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests (.NET)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 1656 in src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests (.NET)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
var callCount = 0;
ImmutableAudience.MobileInstallReferrerProvider = () =>
++callCount == 1 ? firstCallReturn : secondCallReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
{
Expand Down Expand Up @@ -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"]);
}
}
}
Loading