Skip to content

Commit 34d4050

Browse files
refactor(audience-sdk): introduce ContextKeys and GameLaunchPropertyKeys
Names the per-event context dictionary keys and the auto-fired game_launch property keys, and routes DeviceCollector's twelve truncation sites through Constants.MaxFieldLength so the 256-char cap reads as a contract. - Constants.cs: adds ContextKeys (UserAgent, Timezone, Locale, Screen) and GameLaunchPropertyKeys (Platform, Version, BuildGuid, UnityVersion, OsFamily, DeviceModel, Gpu, GpuVendor, Cpu, CpuCores, RamMb, ScreenDpi, DistributionPlatform). - DeviceCollector.cs: CollectContext writes ContextKeys; CollectGameLaunchProperties writes GameLaunchPropertyKeys; truncation calls use Constants.MaxFieldLength. - ImmutableAudience.cs: distribution-platform overlay on game_launch reads GameLaunchPropertyKeys.DistributionPlatform.
1 parent 71e295f commit 34d4050

3 files changed

Lines changed: 44 additions & 17 deletions

File tree

src/Packages/Audience/Runtime/Core/Constants.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@ internal static class MessageTypes
6262
internal const string Alias = "alias";
6363
}
6464

65+
// Property keys for the auto-fired game_launch event.
66+
internal static class GameLaunchPropertyKeys
67+
{
68+
internal const string Platform = "platform";
69+
internal const string Version = "version";
70+
internal const string BuildGuid = "buildGuid";
71+
internal const string UnityVersion = "unityVersion";
72+
internal const string OsFamily = "osFamily";
73+
internal const string DeviceModel = "deviceModel";
74+
internal const string Gpu = "gpu";
75+
internal const string GpuVendor = "gpuVendor";
76+
internal const string Cpu = "cpu";
77+
internal const string CpuCores = "cpuCores";
78+
internal const string RamMb = "ramMb";
79+
internal const string ScreenDpi = "screenDpi";
80+
internal const string DistributionPlatform = "distributionPlatform";
81+
}
82+
83+
// Keys merged into every event's context dictionary.
84+
internal static class ContextKeys
85+
{
86+
internal const string UserAgent = "userAgent";
87+
internal const string Timezone = "timezone";
88+
internal const string Locale = "locale";
89+
internal const string Screen = "screen";
90+
}
91+
6592
// JSON keys for the consent-sync PUT body.
6693
internal static class ConsentBodyFields
6794
{

src/Packages/Audience/Runtime/ImmutableAudience.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ private static void FireGameLaunch(AudienceConfig config, ConsentLevel consentAt
10161016

10171017
// Config-supplied distributionPlatform overrides the provider value.
10181018
if (config.DistributionPlatform != null)
1019-
properties["distributionPlatform"] = config.DistributionPlatform;
1019+
properties[GameLaunchPropertyKeys.DistributionPlatform] = config.DistributionPlatform;
10201020

10211021
// No sessionId on game_launch per Event Reference. Pipeline correlates
10221022
// via eventTimestamp with the session_start that fires just before.

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ internal static Dictionary<string, object> CollectContext()
1414
// 256-char cap mirrors Web SDK's identifier truncation.
1515
var ctx = new Dictionary<string, object>
1616
{
17-
["userAgent"] = Truncate(SystemInfo.operatingSystem, 256),
17+
[ContextKeys.UserAgent] = Truncate(SystemInfo.operatingSystem, Constants.MaxFieldLength),
1818
};
1919

2020
var timezone = SafeTimezone();
21-
if (timezone != null) ctx["timezone"] = Truncate(timezone, 256);
21+
if (timezone != null) ctx[ContextKeys.Timezone] = Truncate(timezone, Constants.MaxFieldLength);
2222

2323
var locale = LocaleString();
24-
if (locale != null) ctx["locale"] = Truncate(locale, 256);
24+
if (locale != null) ctx[ContextKeys.Locale] = Truncate(locale, Constants.MaxFieldLength);
2525

2626
var screen = TryResolveScreenString();
27-
if (screen != null) ctx["screen"] = Truncate(screen, 256);
27+
if (screen != null) ctx[ContextKeys.Screen] = Truncate(screen, Constants.MaxFieldLength);
2828

2929
return ctx;
3030
}
@@ -49,22 +49,22 @@ internal static Dictionary<string, object> CollectGameLaunchProperties()
4949
{
5050
var props = new Dictionary<string, object>
5151
{
52-
["platform"] = Application.platform.ToString(),
53-
["version"] = Truncate(Application.version, 256),
54-
["buildGuid"] = Truncate(Application.buildGUID, 256),
55-
["unityVersion"] = Truncate(Application.unityVersion, 256),
56-
["osFamily"] = SystemInfo.operatingSystemFamily.ToString(),
57-
["deviceModel"] = Truncate(SystemInfo.deviceModel, 256),
58-
["gpu"] = Truncate(SystemInfo.graphicsDeviceName, 256),
59-
["gpuVendor"] = Truncate(SystemInfo.graphicsDeviceVendor, 256),
60-
["cpu"] = Truncate(SystemInfo.processorType, 256),
61-
["cpuCores"] = SystemInfo.processorCount,
62-
["ramMb"] = SystemInfo.systemMemorySize,
52+
[GameLaunchPropertyKeys.Platform] = Application.platform.ToString(),
53+
[GameLaunchPropertyKeys.Version] = Truncate(Application.version, Constants.MaxFieldLength),
54+
[GameLaunchPropertyKeys.BuildGuid] = Truncate(Application.buildGUID, Constants.MaxFieldLength),
55+
[GameLaunchPropertyKeys.UnityVersion] = Truncate(Application.unityVersion, Constants.MaxFieldLength),
56+
[GameLaunchPropertyKeys.OsFamily] = SystemInfo.operatingSystemFamily.ToString(),
57+
[GameLaunchPropertyKeys.DeviceModel] = Truncate(SystemInfo.deviceModel, Constants.MaxFieldLength),
58+
[GameLaunchPropertyKeys.Gpu] = Truncate(SystemInfo.graphicsDeviceName, Constants.MaxFieldLength),
59+
[GameLaunchPropertyKeys.GpuVendor] = Truncate(SystemInfo.graphicsDeviceVendor, Constants.MaxFieldLength),
60+
[GameLaunchPropertyKeys.Cpu] = Truncate(SystemInfo.processorType, Constants.MaxFieldLength),
61+
[GameLaunchPropertyKeys.CpuCores] = SystemInfo.processorCount,
62+
[GameLaunchPropertyKeys.RamMb] = SystemInfo.systemMemorySize,
6363
};
6464

6565
// Screen.dpi can be 0 on some Linux WMs.
6666
var dpi = (int)Screen.dpi;
67-
if (dpi > 0) props["screenDpi"] = dpi;
67+
if (dpi > 0) props[GameLaunchPropertyKeys.ScreenDpi] = dpi;
6868

6969
return props;
7070
}

0 commit comments

Comments
 (0)