Skip to content

Commit f8a76b6

Browse files
nattb8claude
andcommitted
feat(audience): rename event property keys to snake_case
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b460ee6 commit f8a76b6

10 files changed

Lines changed: 117 additions & 117 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal void Start()
9797

9898
SafeTrack("session_start", new Dictionary<string, object>
9999
{
100-
["sessionId"] = sessionId
100+
["session_id"] = sessionId
101101
});
102102
}
103103

@@ -173,8 +173,8 @@ internal void End()
173173
// wall-clock; dashboards should not assume parity.
174174
SafeTrack("session_end", new Dictionary<string, object>
175175
{
176-
["sessionId"] = sessionId,
177-
["durationSec"] = duration
176+
["session_id"] = sessionId,
177+
["duration_sec"] = duration
178178
});
179179
}
180180

@@ -198,8 +198,8 @@ internal void EmitEndAndSeal()
198198

199199
SafeTrack("session_end", new Dictionary<string, object>
200200
{
201-
["sessionId"] = sessionId,
202-
["durationSec"] = duration
201+
["session_id"] = sessionId,
202+
["duration_sec"] = duration
203203
});
204204
}
205205

@@ -240,8 +240,8 @@ internal void OnHeartbeat()
240240
// Build outside _lock so track doesn't re-enter.
241241
var properties = new Dictionary<string, object>
242242
{
243-
["sessionId"] = sessionId,
244-
["durationSec"] = duration
243+
["session_id"] = sessionId,
244+
["duration_sec"] = duration
245245
};
246246

247247
SafeTrack("session_heartbeat", properties);

src/Packages/Audience/Runtime/Events/TypedEvents.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public Dictionary<string, object> ToProperties()
9595
if (Level != null) props["level"] = Level;
9696
if (Stage != null) props["stage"] = Stage;
9797
if (Score.HasValue) props["score"] = Score.Value;
98-
if (DurationSec.HasValue) props["durationSec"] = DurationSec.Value;
98+
if (DurationSec.HasValue) props["duration_sec"] = DurationSec.Value;
9999

100100
return props;
101101
}
@@ -182,8 +182,8 @@ public Dictionary<string, object> ToProperties()
182182
["amount"] = Amount.Value
183183
};
184184

185-
if (ItemType != null) props["itemType"] = ItemType;
186-
if (ItemId != null) props["itemId"] = ItemId;
185+
if (ItemType != null) props["item_type"] = ItemType;
186+
if (ItemId != null) props["item_id"] = ItemId;
187187

188188
return props;
189189
}
@@ -256,10 +256,10 @@ public Dictionary<string, object> ToProperties()
256256
["value"] = Value.Value
257257
};
258258

259-
if (ItemId != null) props["itemId"] = ItemId;
260-
if (ItemName != null) props["itemName"] = ItemName;
259+
if (ItemId != null) props["item_id"] = ItemId;
260+
if (ItemName != null) props["item_name"] = ItemName;
261261
if (Quantity.HasValue) props["quantity"] = Quantity.Value;
262-
if (TransactionId != null) props["transactionId"] = TransactionId;
262+
if (TransactionId != null) props["transaction_id"] = TransactionId;
263263

264264
return props;
265265
}

src/Packages/Audience/Runtime/ImmutableAudience.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,17 +1121,17 @@ private static void FireGameLaunch(
11211121

11221122
// Config-supplied distributionPlatform overrides the provider value.
11231123
if (config.DistributionPlatform != null)
1124-
properties["distributionPlatform"] = config.DistributionPlatform;
1124+
properties["distribution_platform"] = config.DistributionPlatform;
11251125

11261126
// Emitted only on the first launch where SKAN registration fires.
11271127
if (skanRegistered == true)
1128-
properties["skanRegistered"] = true;
1128+
properties["skan_registered"] = true;
11291129

11301130
// iOS ATT/IDFA snapshot, merged after Unity context so attribution
11311131
// keys are authoritative if both sources happen to set the same key.
11321132
// idfa and gaid are cross-app device identifiers, same privacy class
1133-
// as userId; gate them at Full-only. State-class keys (attStatus,
1134-
// gaidLimitAdTracking) are non-identifying and ship at Anon+Full.
1133+
// as userId; gate them at Full-only. State-class keys (att_status,
1134+
// gaid_limit_ad_tracking) are non-identifying and ship at Anon+Full.
11351135
if (attributionContext != null)
11361136
{
11371137
var canIdentify = consentAtInit.CanIdentify();
@@ -1160,7 +1160,7 @@ private static void FireInstallReferrerReceivedOnce(AudienceConfig config, strin
11601160

11611161
Track("install_referrer_received", new Dictionary<string, object>
11621162
{
1163-
["installReferrer"] = installReferrer,
1163+
["install_referrer"] = installReferrer,
11641164
});
11651165

11661166
try
@@ -1235,8 +1235,8 @@ private static void CheckAndFireAttStatusChanged(
12351235

12361236
var props = new Dictionary<string, object>
12371237
{
1238-
["previousStatus"] = AttStatusToString(previous.Value),
1239-
["newStatus"] = AttStatusToString(currentStatus),
1238+
["previous_status"] = AttStatusToString(previous.Value),
1239+
["new_status"] = AttStatusToString(currentStatus),
12401240
};
12411241

12421242
if (currentStatus == 3 && consent.CanIdentify())

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,33 @@ internal static Dictionary<string, object> CollectGameLaunchProperties(
5555
var props = new Dictionary<string, object>
5656
{
5757
["platform"] = PlatformName(platform),
58-
["isEditor"] = isEditor,
58+
["is_editor"] = isEditor,
5959
["version"] = Truncate(Application.version, 256),
60-
["buildGuid"] = Truncate(Application.buildGUID, 256),
61-
["unityVersion"] = Truncate(Application.unityVersion, 256),
62-
["osFamily"] = SystemInfo.operatingSystemFamily.ToString(),
63-
["deviceModel"] = Truncate(SystemInfo.deviceModel, 256),
60+
["build_guid"] = Truncate(Application.buildGUID, 256),
61+
["unity_version"] = Truncate(Application.unityVersion, 256),
62+
["os_family"] = SystemInfo.operatingSystemFamily.ToString(),
63+
["device_model"] = Truncate(SystemInfo.deviceModel, 256),
6464
["gpu"] = Truncate(SystemInfo.graphicsDeviceName, 256),
65-
["gpuVendor"] = Truncate(SystemInfo.graphicsDeviceVendor, 256),
65+
["gpu_vendor"] = Truncate(SystemInfo.graphicsDeviceVendor, 256),
6666
["cpu"] = Truncate(SystemInfo.processorType, 256),
67-
["cpuCores"] = SystemInfo.processorCount,
68-
["ramMb"] = SystemInfo.systemMemorySize,
67+
["cpu_cores"] = SystemInfo.processorCount,
68+
["ram_mb"] = SystemInfo.systemMemorySize,
6969
};
7070

7171
// Screen.dpi can be 0 on some Linux WMs.
7272
var dpi = (int)Screen.dpi;
73-
if (dpi > 0) props["screenDpi"] = dpi;
73+
if (dpi > 0) props["screen_dpi"] = dpi;
7474

7575
if (platform == RuntimePlatform.Android)
76-
props["androidId"] = Truncate(SystemInfo.deviceUniqueIdentifier, 256);
76+
props["android_id"] = Truncate(SystemInfo.deviceUniqueIdentifier, 256);
7777

7878
if (platform == RuntimePlatform.IPhonePlayer)
7979
{
8080
var idfv = IDFVBridge.GetIDFV();
8181
if (idfv != null) props["idfv"] = Truncate(idfv, 256);
8282

8383
// iOS baseline is 163 DPI (1×); 326 → 2×, 401-460 → 3×.
84-
if (dpi > 0) props["screenScale"] = (int)Math.Round(dpi / 163.0);
84+
if (dpi > 0) props["screen_scale"] = (int)Math.Round(dpi / 163.0);
8585
}
8686

8787
return props;

src/Packages/Audience/Runtime/Unity/Mobile/AttributionContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal static IReadOnlyDictionary<string, object> Capture(string? persistentDa
4646
// never ships there. Native ATTBridge calls are themselves gated
4747
// by #if UNITY_IOS, so non-iOS editor targets get the safe stubs.
4848
var status = ATTBridge.GetStatus();
49-
props["attStatus"] = AttStatusToString(status);
49+
props["att_status"] = AttStatusToString(status);
5050

5151
// Only ship IDFA when the user has authorized tracking. The native
5252
// bridge already returns null for the zero-UUID case, but gating
@@ -84,7 +84,7 @@ internal static void EmitGaidProps(GAIDInfo info, IDictionary<string, object> pr
8484
{
8585
if (!info.LimitAdTracking && !string.IsNullOrEmpty(info.Gaid))
8686
props["gaid"] = info.Gaid;
87-
props["gaidLimitAdTracking"] = info.LimitAdTracking;
87+
props["gaid_limit_ad_tracking"] = info.LimitAdTracking;
8888
}
8989
}
9090
}

src/Packages/Audience/Tests/Runtime/Core/SessionTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public void Start_FiresSessionStart_WithSessionId()
3535

3636
Assert.AreEqual(1, _events.Count);
3737
Assert.AreEqual("session_start", _events[0].name);
38-
Assert.IsTrue(_events[0].props.ContainsKey("sessionId"));
39-
Assert.IsNotEmpty((string)_events[0].props["sessionId"]);
38+
Assert.IsTrue(_events[0].props.ContainsKey("session_id"));
39+
Assert.IsNotEmpty((string)_events[0].props["session_id"]);
4040
}
4141

4242
[Test]
@@ -64,9 +64,9 @@ public void End_FiresSessionEnd_WithDuration()
6464

6565
var endEvent = _events.FirstOrDefault(e => e.name == "session_end");
6666
Assert.IsNotNull(endEvent.props);
67-
Assert.IsTrue(endEvent.props.ContainsKey("sessionId"));
68-
Assert.IsTrue(endEvent.props.ContainsKey("durationSec"));
69-
Assert.AreEqual(2L, (long)endEvent.props["durationSec"]);
67+
Assert.IsTrue(endEvent.props.ContainsKey("session_id"));
68+
Assert.IsTrue(endEvent.props.ContainsKey("duration_sec"));
69+
Assert.AreEqual(2L, (long)endEvent.props["duration_sec"]);
7070
}
7171

7272
[Test]
@@ -121,8 +121,8 @@ void Track(string name, Dictionary<string, object> props)
121121
{
122122
var beat = events.FirstOrDefault(e => e.name == "session_heartbeat");
123123
Assert.IsNotNull(beat.props, "heartbeat event should carry a properties dictionary");
124-
Assert.IsTrue(beat.props.ContainsKey("sessionId"));
125-
Assert.IsTrue(beat.props.ContainsKey("durationSec"));
124+
Assert.IsTrue(beat.props.ContainsKey("session_id"));
125+
Assert.IsTrue(beat.props.ContainsKey("duration_sec"));
126126
}
127127
}
128128

@@ -198,7 +198,7 @@ public void Pause_CalledTwice_SecondCallIsNoOp()
198198
session.End();
199199

200200
var sessionEnd = _events.Last(e => e.name == "session_end");
201-
var duration = (long)sessionEnd.props["durationSec"];
201+
var duration = (long)sessionEnd.props["duration_sec"];
202202
// Wall-clock Start→End = 13s, paused from T=5 to T=10 = 5s, engaged = 8s.
203203
Assert.AreEqual(8L, duration,
204204
"double Pause must preserve the first Pause timestamp so engagement arithmetic covers the full pause window");
@@ -246,7 +246,7 @@ public void Resume_NegativePauseDuration_ClampsAccumulatorToZero()
246246
session.End();
247247

248248
var sessionEnd = _events.Last(e => e.name == "session_end");
249-
var duration = (long)sessionEnd.props["durationSec"];
249+
var duration = (long)sessionEnd.props["duration_sec"];
250250
// Wall-clock from Start to End is 10 + (-5) + 2 = 7 s. The
251251
// pause duration was clamped to 0, so engaged seconds = 7 - 0 = 7.
252252
// Without the clamp, _accumulatedPause would be -5, the
@@ -277,7 +277,7 @@ public void End_ClockRewindsSinceStart_ClampsDurationToZero()
277277
session.End();
278278

279279
var sessionEnd = _events.Last(e => e.name == "session_end");
280-
var duration = (long)sessionEnd.props["durationSec"];
280+
var duration = (long)sessionEnd.props["duration_sec"];
281281
Assert.AreEqual(0L, duration,
282282
"negative engaged time from a wall-clock rewind must clamp to zero");
283283
}
@@ -306,7 +306,7 @@ public void End_ClockRewindsWhilePaused_DoesNotInflateDuration()
306306
session.End();
307307

308308
var sessionEnd = _events.Last(e => e.name == "session_end");
309-
var duration = (long)sessionEnd.props["durationSec"];
309+
var duration = (long)sessionEnd.props["duration_sec"];
310310
Assert.LessOrEqual(duration, 5L,
311311
"clock rewind while paused must not over-credit engagement past the wall-clock window");
312312
}
@@ -331,7 +331,7 @@ public void End_AfterShortPause_ReportsDurationMinusPause()
331331
session.End();
332332

333333
var sessionEnd = _events.Last(e => e.name == "session_end");
334-
var duration = (long)sessionEnd.props["durationSec"];
334+
var duration = (long)sessionEnd.props["duration_sec"];
335335
Assert.AreEqual(7L, duration,
336336
"session_end duration should exclude the 3s paused interval");
337337
}
@@ -353,7 +353,7 @@ public void End_WhilePaused_ExcludesInFlightPauseFromDuration()
353353
session.End(); // ends while paused
354354

355355
var sessionEnd = _events.Last(e => e.name == "session_end");
356-
var duration = (long)sessionEnd.props["durationSec"];
356+
var duration = (long)sessionEnd.props["duration_sec"];
357357
Assert.AreEqual(5L, duration,
358358
"session_end fired while paused should count only pre-pause engaged time");
359359
}
@@ -381,7 +381,7 @@ public void End_AfterExtendedPauseRollover_ReportsPrePauseDuration()
381381
session.Resume();
382382

383383
var sessionEnd = _events.First(e => e.name == "session_end");
384-
var duration = (long)sessionEnd.props["durationSec"];
384+
var duration = (long)sessionEnd.props["duration_sec"];
385385
Assert.AreEqual(10L, duration,
386386
"session_end on extended-pause rollover should report pre-pause engaged time, not wall-clock");
387387
}
@@ -406,7 +406,7 @@ public void Heartbeat_AfterShortPause_ReportsPauseAdjustedDuration()
406406
session.OnHeartbeat();
407407

408408
var heartbeat = _events.Last(e => e.name == "session_heartbeat");
409-
var duration = (long)heartbeat.props["durationSec"];
409+
var duration = (long)heartbeat.props["duration_sec"];
410410
Assert.AreEqual(6L, duration,
411411
"heartbeat duration should exclude the 2s paused interval");
412412
}

src/Packages/Audience/Tests/Runtime/Events/TypedEventTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Progression_Complete_ProducesCorrectProperties()
3939
Assert.AreEqual("tutorial", props["world"]);
4040
Assert.AreEqual("1", props["level"]);
4141
Assert.AreEqual(1500, props["score"]);
42-
Assert.AreEqual(120.5f, props["durationSec"]);
42+
Assert.AreEqual(120.5f, props["duration_sec"]);
4343
}
4444

4545
[Test]
@@ -52,7 +52,7 @@ public void Progression_OptionalFieldsOmitted_WhenNull()
5252
Assert.IsFalse(props.ContainsKey("level"));
5353
Assert.IsFalse(props.ContainsKey("stage"));
5454
Assert.IsFalse(props.ContainsKey("score"));
55-
Assert.IsFalse(props.ContainsKey("durationSec"));
55+
Assert.IsFalse(props.ContainsKey("duration_sec"));
5656
}
5757

5858
[Test]
@@ -72,8 +72,8 @@ public void Resource_Source_ProducesCorrectProperties()
7272
Assert.AreEqual("source", props["flow"]);
7373
Assert.AreEqual("gold", props["currency"]);
7474
Assert.AreEqual(100m, props["amount"]);
75-
Assert.AreEqual("quest_reward", props["itemType"]);
76-
Assert.AreEqual("main_quest_01", props["itemId"]);
75+
Assert.AreEqual("quest_reward", props["item_type"]);
76+
Assert.AreEqual("main_quest_01", props["item_id"]);
7777
}
7878

7979
[Test]
@@ -126,10 +126,10 @@ public void Purchase_ProducesCorrectProperties()
126126

127127
Assert.AreEqual("USD", props["currency"]);
128128
Assert.AreEqual(9.99m, props["value"]);
129-
Assert.AreEqual("gem_pack_01", props["itemId"]);
130-
Assert.AreEqual("Starter Gem Pack", props["itemName"]);
129+
Assert.AreEqual("gem_pack_01", props["item_id"]);
130+
Assert.AreEqual("Starter Gem Pack", props["item_name"]);
131131
Assert.AreEqual(1, props["quantity"]);
132-
Assert.AreEqual("txn_abc123", props["transactionId"]);
132+
Assert.AreEqual("txn_abc123", props["transaction_id"]);
133133
}
134134

135135
[Test]
@@ -139,10 +139,10 @@ public void Purchase_OptionalFieldsOmitted_WhenNull()
139139

140140
Assert.IsTrue(props.ContainsKey("currency"));
141141
Assert.IsTrue(props.ContainsKey("value"));
142-
Assert.IsFalse(props.ContainsKey("itemId"));
143-
Assert.IsFalse(props.ContainsKey("itemName"));
142+
Assert.IsFalse(props.ContainsKey("item_id"));
143+
Assert.IsFalse(props.ContainsKey("item_name"));
144144
Assert.IsFalse(props.ContainsKey("quantity"));
145-
Assert.IsFalse(props.ContainsKey("transactionId"));
145+
Assert.IsFalse(props.ContainsKey("transaction_id"));
146146
}
147147

148148
[Test]

0 commit comments

Comments
 (0)