Skip to content

Commit 7be50a2

Browse files
refactor(audience-sample): centralise custom demo event names in SampleAppCustomEvents
The sample-app demo catalogue (sign_up, sign_in, email_acquired, wishlist_add, wishlist_remove, game_page_viewed, link_clicked, screen_viewed) had its event-name strings inline at every call site. A rename touches the catalogue, the screen_viewed Track call, and each Unity live-fire test that drives the catalogue UI. Move the eight names into a new internal SampleAppCustomEvents class under the sample-app Scripts assembly. Update AudienceSample.Events.cs, AudienceSample.cs (screen_viewed Track), and SampleAppLiveFireTests.cs (button and field lookups by event name) to reference the constants. 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 6959489 commit 7be50a2

5 files changed

Lines changed: 45 additions & 19 deletions

File tree

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

Lines changed: 7 additions & 7 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("sign_up", new[] { EventField.Text("method", optional: true) }),
59-
new EventSpec("sign_in", new[] { EventField.Text("method", optional: true) }),
60-
new EventSpec("email_acquired", new[] { EventField.Text("source", optional: true) }),
61-
new EventSpec("wishlist_add", new[] {
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) }),
61+
new EventSpec(SampleAppCustomEvents.WishlistAdd, new[] {
6262
EventField.Text("gameId"),
6363
EventField.Text("source", optional: true),
6464
EventField.Text("platform", optional: true),
6565
}),
66-
new EventSpec("wishlist_remove", new[] { EventField.Text("gameId") }),
66+
new EventSpec(SampleAppCustomEvents.WishlistRemove, new[] { EventField.Text("gameId") }),
6767
new EventSpec(EventNames.Purchase, new[] {
6868
EventField.Text(EventPropertyKeys.Currency),
6969
EventField.Number(EventPropertyKeys.Value),
@@ -91,12 +91,12 @@ internal readonly struct EventSpec
9191
EventField.Text(EventPropertyKeys.ItemId, optional: true),
9292
}),
9393
new EventSpec(EventNames.MilestoneReached, new[] { EventField.Text(EventPropertyKeys.Name) }),
94-
new EventSpec("game_page_viewed", new[] {
94+
new EventSpec(SampleAppCustomEvents.GamePageViewed, new[] {
9595
EventField.Text("gameId"),
9696
EventField.Text("gameName", optional: true),
9797
EventField.Text("slug", optional: true),
9898
}),
99-
new EventSpec("link_clicked", new[] {
99+
new EventSpec(SampleAppCustomEvents.LinkClicked, new[] {
100100
EventField.Text("url"),
101101
EventField.Text("label", optional: true),
102102
EventField.Text("source", optional: true),

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Immutable.Audience.Samples.SampleApp
2+
{
3+
// Sample-only event names that demonstrate the custom Track pattern.
4+
internal static class SampleAppCustomEvents
5+
{
6+
internal const string SignUp = "sign_up";
7+
internal const string SignIn = "sign_in";
8+
internal const string EmailAcquired = "email_acquired";
9+
internal const string WishlistAdd = "wishlist_add";
10+
internal const string WishlistRemove = "wishlist_remove";
11+
internal const string GamePageViewed = "game_page_viewed";
12+
internal const string LinkClicked = "link_clicked";
13+
internal const string ScreenViewed = "screen_viewed";
14+
}
15+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,54 +403,54 @@ public IEnumerator IdentifyTraits_AfterIdentify_FlushReportsOk()
403403
[UnityTest]
404404
public IEnumerator TypedEvent_SignUp_FlushReportsOk()
405405
{
406-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("sign_up"));
406+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.SignUp));
407407
}
408408

409409
[UnityTest]
410410
public IEnumerator TypedEvent_SignIn_FlushReportsOk()
411411
{
412-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("sign_in"));
412+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.SignIn));
413413
}
414414

415415
[UnityTest]
416416
public IEnumerator TypedEvent_EmailAcquired_FlushReportsOk()
417417
{
418-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("email_acquired"));
418+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.EmailAcquired));
419419
}
420420

421421
[UnityTest]
422422
public IEnumerator TypedEvent_WishlistAdd_FlushReportsOk()
423423
{
424-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("wishlist_add"), root =>
424+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.WishlistAdd), root =>
425425
{
426-
root.Q<TextField>(SampleAppUi.TypedEventField("wishlist_add", "gameId")).value = "il2cpp_game_1";
426+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.WishlistAdd, "gameId")).value = "il2cpp_game_1";
427427
});
428428
}
429429

430430
[UnityTest]
431431
public IEnumerator TypedEvent_WishlistRemove_FlushReportsOk()
432432
{
433-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("wishlist_remove"), root =>
433+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.WishlistRemove), root =>
434434
{
435-
root.Q<TextField>(SampleAppUi.TypedEventField("wishlist_remove", "gameId")).value = "il2cpp_game_1";
435+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.WishlistRemove, "gameId")).value = "il2cpp_game_1";
436436
});
437437
}
438438

439439
[UnityTest]
440440
public IEnumerator TypedEvent_GamePageViewed_FlushReportsOk()
441441
{
442-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("game_page_viewed"), root =>
442+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.GamePageViewed), root =>
443443
{
444-
root.Q<TextField>(SampleAppUi.TypedEventField("game_page_viewed", "gameId")).value = "il2cpp_game_1";
444+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.GamePageViewed, "gameId")).value = "il2cpp_game_1";
445445
});
446446
}
447447

448448
[UnityTest]
449449
public IEnumerator TypedEvent_LinkClicked_FlushReportsOk()
450450
{
451-
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent("link_clicked"), root =>
451+
yield return DriveTypedEventAndFlush(SampleAppUi.Buttons.TypedEvent(SampleAppCustomEvents.LinkClicked), root =>
452452
{
453-
root.Q<TextField>(SampleAppUi.TypedEventField("link_clicked", "url")).value = "https://example.com/il2cpp";
453+
root.Q<TextField>(SampleAppUi.TypedEventField(SampleAppCustomEvents.LinkClicked, "url")).value = "https://example.com/il2cpp";
454454
});
455455
}
456456

0 commit comments

Comments
 (0)