Skip to content

Commit 71e295f

Browse files
refactor(audience-sdk): introduce EventPropertyKeys
Names the per-event property dictionary keys used by Session, TypedEvents, and the sample-app catalogue. - Constants.cs: adds EventPropertyKeys grouped by owning event (shared keys, Progression, Resource, Purchase, MilestoneReached). - Session.cs: SessionStart / SessionEnd / SessionHeartbeat property dictionaries read keys from EventPropertyKeys. - TypedEvents.cs: Progression / Resource / Purchase / MilestoneReached ToProperties dictionaries read keys from EventPropertyKeys. - AudienceSample.Events.cs: typed event-spec EventField names read from EventPropertyKeys.
1 parent 5e7a52c commit 71e295f

4 files changed

Lines changed: 75 additions & 43 deletions

File tree

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,32 @@ internal readonly struct EventSpec
5252
}),
5353
new EventSpec("wishlist_remove", new[] { EventField.Text("gameId") }),
5454
new EventSpec(EventNames.Purchase, new[] {
55-
EventField.Text("currency"),
56-
EventField.Number("value"),
57-
EventField.Text("itemId", optional: true),
58-
EventField.Text("itemName", optional: true),
59-
EventField.Number("quantity", optional: true),
60-
EventField.Text("transactionId", optional: true),
55+
EventField.Text(EventPropertyKeys.Currency),
56+
EventField.Number(EventPropertyKeys.Value),
57+
EventField.Text(EventPropertyKeys.ItemId, optional: true),
58+
EventField.Text(EventPropertyKeys.ItemName, optional: true),
59+
EventField.Number(EventPropertyKeys.Quantity, optional: true),
60+
EventField.Text(EventPropertyKeys.TransactionId, optional: true),
6161
}),
6262
// game_launch is deliberately absent. The Event Reference v1 defines
6363
// it as auto-tracked on Init with no public typed class; firing it
6464
// from the Send button would double-emit.
6565
new EventSpec(EventNames.Progression, new[] {
66-
EventField.Enum("status", new[] { "start", "complete", "fail" }),
67-
EventField.Text("world", optional: true),
68-
EventField.Text("level", optional: true),
69-
EventField.Text("stage", optional: true),
70-
EventField.Number("score", optional: true),
71-
EventField.Number("durationSec", optional: true),
66+
EventField.Enum(EventPropertyKeys.Status, new[] { "start", "complete", "fail" }),
67+
EventField.Text(EventPropertyKeys.World, optional: true),
68+
EventField.Text(EventPropertyKeys.Level, optional: true),
69+
EventField.Text(EventPropertyKeys.Stage, optional: true),
70+
EventField.Number(EventPropertyKeys.Score, optional: true),
71+
EventField.Number(EventPropertyKeys.DurationSec, optional: true),
7272
}),
7373
new EventSpec(EventNames.Resource, new[] {
74-
EventField.Enum("flow", new[] { "sink", "source" }),
75-
EventField.Text("currency"),
76-
EventField.Number("amount"),
77-
EventField.Text("itemType", optional: true),
78-
EventField.Text("itemId", optional: true),
74+
EventField.Enum(EventPropertyKeys.Flow, new[] { "sink", "source" }),
75+
EventField.Text(EventPropertyKeys.Currency),
76+
EventField.Number(EventPropertyKeys.Amount),
77+
EventField.Text(EventPropertyKeys.ItemType, optional: true),
78+
EventField.Text(EventPropertyKeys.ItemId, optional: true),
7979
}),
80-
new EventSpec(EventNames.MilestoneReached, new[] { EventField.Text("name") }),
80+
new EventSpec(EventNames.MilestoneReached, new[] { EventField.Text(EventPropertyKeys.Name) }),
8181
new EventSpec("game_page_viewed", new[] {
8282
EventField.Text("gameId"),
8383
EventField.Text("gameName", optional: true),

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,38 @@ internal static class ResponseFields
7676
internal const string Rejected = "rejected";
7777
}
7878

79+
// Keys inside each event's "properties" dict.
80+
internal static class EventPropertyKeys
81+
{
82+
// Shared across multiple events (Session + Progression for DurationSec,
83+
// Resource + Purchase for Currency / ItemId).
84+
internal const string SessionId = "sessionId";
85+
internal const string DurationSec = "durationSec";
86+
internal const string Currency = "currency";
87+
internal const string ItemId = "itemId";
88+
89+
// Progression-specific
90+
internal const string Status = "status";
91+
internal const string World = "world";
92+
internal const string Level = "level";
93+
internal const string Stage = "stage";
94+
internal const string Score = "score";
95+
96+
// Resource-specific
97+
internal const string Flow = "flow";
98+
internal const string Amount = "amount";
99+
internal const string ItemType = "itemType";
100+
101+
// Purchase-specific
102+
internal const string Value = "value";
103+
internal const string ItemName = "itemName";
104+
internal const string Quantity = "quantity";
105+
internal const string TransactionId = "transactionId";
106+
107+
// MilestoneReached-specific
108+
internal const string Name = "name";
109+
}
110+
79111
// Event names we send on Track.
80112
internal static class EventNames
81113
{

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

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

104104
SafeTrack(EventNames.SessionStart, new Dictionary<string, object>
105105
{
106-
["sessionId"] = sessionId
106+
[EventPropertyKeys.SessionId] = sessionId
107107
});
108108
}
109109

@@ -179,8 +179,8 @@ internal void End()
179179
// wall-clock; dashboards should not assume parity.
180180
SafeTrack(EventNames.SessionEnd, new Dictionary<string, object>
181181
{
182-
["sessionId"] = sessionId,
183-
["durationSec"] = duration
182+
[EventPropertyKeys.SessionId] = sessionId,
183+
[EventPropertyKeys.DurationSec] = duration
184184
});
185185
}
186186

@@ -204,8 +204,8 @@ internal void EmitEndAndSeal()
204204

205205
SafeTrack(EventNames.SessionEnd, new Dictionary<string, object>
206206
{
207-
["sessionId"] = sessionId,
208-
["durationSec"] = duration
207+
[EventPropertyKeys.SessionId] = sessionId,
208+
[EventPropertyKeys.DurationSec] = duration
209209
});
210210
}
211211

@@ -246,8 +246,8 @@ internal void OnHeartbeat()
246246
// Build outside _lock so track doesn't re-enter.
247247
var properties = new Dictionary<string, object>
248248
{
249-
["sessionId"] = sessionId,
250-
["durationSec"] = duration
249+
[EventPropertyKeys.SessionId] = sessionId,
250+
[EventPropertyKeys.DurationSec] = duration
251251
};
252252

253253
SafeTrack(EventNames.SessionHeartbeat, properties);

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ public Dictionary<string, object> ToProperties()
8888

8989
var props = new Dictionary<string, object>
9090
{
91-
["status"] = Status.Value.ToLowercaseString()
91+
[EventPropertyKeys.Status] = Status.Value.ToLowercaseString()
9292
};
9393

94-
if (World != null) props["world"] = World;
95-
if (Level != null) props["level"] = Level;
96-
if (Stage != null) props["stage"] = Stage;
97-
if (Score.HasValue) props["score"] = Score.Value;
98-
if (DurationSec.HasValue) props["durationSec"] = DurationSec.Value;
94+
if (World != null) props[EventPropertyKeys.World] = World;
95+
if (Level != null) props[EventPropertyKeys.Level] = Level;
96+
if (Stage != null) props[EventPropertyKeys.Stage] = Stage;
97+
if (Score.HasValue) props[EventPropertyKeys.Score] = Score.Value;
98+
if (DurationSec.HasValue) props[EventPropertyKeys.DurationSec] = DurationSec.Value;
9999

100100
return props;
101101
}
@@ -177,13 +177,13 @@ public Dictionary<string, object> ToProperties()
177177

178178
var props = new Dictionary<string, object>
179179
{
180-
["flow"] = Flow.Value.ToLowercaseString(),
181-
["currency"] = Currency,
182-
["amount"] = Amount.Value
180+
[EventPropertyKeys.Flow] = Flow.Value.ToLowercaseString(),
181+
[EventPropertyKeys.Currency] = Currency,
182+
[EventPropertyKeys.Amount] = Amount.Value
183183
};
184184

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

188188
return props;
189189
}
@@ -252,14 +252,14 @@ public Dictionary<string, object> ToProperties()
252252

253253
var props = new Dictionary<string, object>
254254
{
255-
["currency"] = Currency,
256-
["value"] = Value.Value
255+
[EventPropertyKeys.Currency] = Currency,
256+
[EventPropertyKeys.Value] = Value.Value
257257
};
258258

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

264264
return props;
265265
}
@@ -288,7 +288,7 @@ public Dictionary<string, object> ToProperties()
288288

289289
return new Dictionary<string, object>
290290
{
291-
["name"] = Name
291+
[EventPropertyKeys.Name] = Name
292292
};
293293
}
294294
}

0 commit comments

Comments
 (0)