Skip to content

Commit 595ebe8

Browse files
refactor(audience-sample): centralise custom demo property keys in SampleAppCustomEventPropertyKeys
The sample-app demo catalogue, screen_viewed Track call, and the typed-event live-fire tests had property keys (method, source, gameId, platform, gameName, slug, url, label, path) inline at every call site. Each key duplicates between the catalogue's EventField definition and the live-fire test's UI lookup. Add SampleAppCustomEventPropertyKeys alongside SampleAppCustomEvents (mirrors the SDK's EventPropertyKeys naming) and reference the constants from AudienceSample.Events.cs, AudienceSample.cs (the screen_viewed props dictionary), and SampleAppLiveFireTests.cs (the TypedEventField field-name lookups). Includes gameName and slug beyond the user's listed seven keys: same inline-property-key category, same migration treatment. Per the user's "everything random goes in a constant" stance, applied against the previous session's recommendation that the demo content read better inline. Recording the override on the user's explicit request. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent e5cdd45 commit 595ebe8

4 files changed

Lines changed: 33 additions & 19 deletions

File tree

examples/audience/Assets/SampleApp/Scripts/AudienceSample.Events.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ internal readonly struct EventSpec
5555

5656
internal static readonly EventSpec[] Catalogue =
5757
{
58-
new EventSpec(SampleAppCustomEvents.SignUp, new[] { EventField.Text("method", optional: true) }),
59-
new EventSpec(SampleAppCustomEvents.SignIn, new[] { EventField.Text("method", optional: true) }),
60-
new EventSpec(SampleAppCustomEvents.EmailAcquired, new[] { EventField.Text("source", optional: true) }),
58+
new EventSpec(SampleAppCustomEvents.SignUp, new[] { EventField.Text(SampleAppCustomEventPropertyKeys.Method, optional: true) }),
59+
new EventSpec(SampleAppCustomEvents.SignIn, new[] { EventField.Text(SampleAppCustomEventPropertyKeys.Method, optional: true) }),
60+
new EventSpec(SampleAppCustomEvents.EmailAcquired, new[] { EventField.Text(SampleAppCustomEventPropertyKeys.Source, optional: true) }),
6161
new EventSpec(SampleAppCustomEvents.WishlistAdd, new[] {
62-
EventField.Text("gameId"),
63-
EventField.Text("source", optional: true),
64-
EventField.Text("platform", optional: true),
62+
EventField.Text(SampleAppCustomEventPropertyKeys.GameId),
63+
EventField.Text(SampleAppCustomEventPropertyKeys.Source, optional: true),
64+
EventField.Text(SampleAppCustomEventPropertyKeys.Platform, optional: true),
6565
}),
66-
new EventSpec(SampleAppCustomEvents.WishlistRemove, new[] { EventField.Text("gameId") }),
66+
new EventSpec(SampleAppCustomEvents.WishlistRemove, new[] { EventField.Text(SampleAppCustomEventPropertyKeys.GameId) }),
6767
new EventSpec(EventNames.Purchase, new[] {
6868
EventField.Text(EventPropertyKeys.Currency),
6969
EventField.Number(EventPropertyKeys.Value),
@@ -92,15 +92,15 @@ internal readonly struct EventSpec
9292
}),
9393
new EventSpec(EventNames.MilestoneReached, new[] { EventField.Text(EventPropertyKeys.Name) }),
9494
new EventSpec(SampleAppCustomEvents.GamePageViewed, new[] {
95-
EventField.Text("gameId"),
96-
EventField.Text("gameName", optional: true),
97-
EventField.Text("slug", optional: true),
95+
EventField.Text(SampleAppCustomEventPropertyKeys.GameId),
96+
EventField.Text(SampleAppCustomEventPropertyKeys.GameName, optional: true),
97+
EventField.Text(SampleAppCustomEventPropertyKeys.Slug, optional: true),
9898
}),
9999
new EventSpec(SampleAppCustomEvents.LinkClicked, new[] {
100-
EventField.Text("url"),
101-
EventField.Text("label", optional: true),
102-
EventField.Text("source", optional: true),
103-
EventField.Text("gameId", optional: true),
100+
EventField.Text(SampleAppCustomEventPropertyKeys.Url),
101+
EventField.Text(SampleAppCustomEventPropertyKeys.Label, optional: true),
102+
EventField.Text(SampleAppCustomEventPropertyKeys.Source, optional: true),
103+
EventField.Text(SampleAppCustomEventPropertyKeys.GameId, optional: true),
104104
}),
105105
};
106106

examples/audience/Assets/SampleApp/Scripts/AudienceSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void OnPage() => RunAndLog(SampleAppUi.LogLabels.Page, () =>
110110
{
111111
GuardConsentForTrack();
112112
var screen = SceneManager.GetActiveScene().name;
113-
var props = new Dictionary<string, object> { ["path"] = screen };
113+
var props = new Dictionary<string, object> { [SampleAppCustomEventPropertyKeys.Path] = screen };
114114
ImmutableAudience.Track(SampleAppCustomEvents.ScreenViewed, props);
115115
return Json.Serialize(props, 2);
116116
});

examples/audience/Assets/SampleApp/Scripts/SampleAppCustomEvents.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ internal static class SampleAppCustomEvents
1212
internal const string LinkClicked = "link_clicked";
1313
internal const string ScreenViewed = "screen_viewed";
1414
}
15+
16+
// Property keys for the sample-app demo events.
17+
internal static class SampleAppCustomEventPropertyKeys
18+
{
19+
internal const string Method = "method";
20+
internal const string Source = "source";
21+
internal const string GameId = "gameId";
22+
internal const string Platform = "platform";
23+
internal const string GameName = "gameName";
24+
internal const string Slug = "slug";
25+
internal const string Url = "url";
26+
internal const string Label = "label";
27+
internal const string Path = "path";
28+
}
1529
}

examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppLiveFireTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public IEnumerator TypedEvent_WishlistAdd_FlushReportsOk()
423423
{
424424
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.WishlistAdd), root =>
425425
{
426-
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.WishlistAdd, "gameId")).value = "il2cpp_game_1";
426+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.WishlistAdd, SampleAppCustomEventPropertyKeys.GameId)).value = "il2cpp_game_1";
427427
});
428428
}
429429

@@ -432,7 +432,7 @@ public IEnumerator TypedEvent_WishlistRemove_FlushReportsOk()
432432
{
433433
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.WishlistRemove), root =>
434434
{
435-
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.WishlistRemove, "gameId")).value = "il2cpp_game_1";
435+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.WishlistRemove, SampleAppCustomEventPropertyKeys.GameId)).value = "il2cpp_game_1";
436436
});
437437
}
438438

@@ -441,7 +441,7 @@ public IEnumerator TypedEvent_GamePageViewed_FlushReportsOk()
441441
{
442442
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.GamePageViewed), root =>
443443
{
444-
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.GamePageViewed, "gameId")).value = "il2cpp_game_1";
444+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.GamePageViewed, SampleAppCustomEventPropertyKeys.GameId)).value = "il2cpp_game_1";
445445
});
446446
}
447447

@@ -450,7 +450,7 @@ public IEnumerator TypedEvent_LinkClicked_FlushReportsOk()
450450
{
451451
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.LinkClicked), root =>
452452
{
453-
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.LinkClicked, "url")).value = "https://example.com/il2cpp";
453+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.LinkClicked, SampleAppCustomEventPropertyKeys.Url)).value = "https://example.com/il2cpp";
454454
});
455455
}
456456

0 commit comments

Comments
 (0)