Skip to content

Commit

Permalink
Add support for Analytics Parameters of Lists (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-maurice authored Oct 21, 2024
1 parent 1fc6b99 commit c8fde34
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
3 changes: 0 additions & 3 deletions analytics/src/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public Parameter(string parameterName, double parameterValue) {
Value = parameterValue;
}

// TODO: Implement accepting maps and vectors in C++ Analytics before enabling these.
/*
public Parameter(string parameterName, IDictionary<string, object> parameterValue) {
Name = parameterName;
Value = parameterValue;
Expand All @@ -93,7 +91,6 @@ public Parameter(string parameterName, IEnumerable<IDictionary<string, object>>
Name = parameterName;
Value = parameterValue;
}
*/

/// @deprecated No longer needed, will be removed in the future.
[System.Obsolete("No longer needed, will be removed in the future.")]
Expand Down
23 changes: 23 additions & 0 deletions analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ public void AnalyticsLevelUp() {
new Parameter("hit_accuracy", 3.14f));
}

public void AnalyticsViewCart() {
// Log an event that includes a parameter with a list
DebugLog("Logging a view cart event.");
FirebaseAnalytics.LogEvent(
FirebaseAnalytics.EventViewCart,
new Parameter(FirebaseAnalytics.ParameterCurrency, "USD"),
new Parameter(FirebaseAnalytics.ParameterValue, 30.03),
new Parameter(FirebaseAnalytics.ParameterItems, new [] {
new Dictionary<string, object> {
{ FirebaseAnalytics.ParameterItemID, "SKU_12345" },
{ FirebaseAnalytics.ParameterItemName, "Horse Armor DLC" },
},
new Dictionary<string, object> {
{ FirebaseAnalytics.ParameterItemID, "SKU_67890" },
{ FirebaseAnalytics.ParameterItemName, "Gold Horse Armor DLC" },
}
})
);
}

// Reset analytics data for this app instance.
public void ResetAnalyticsData() {
DebugLog("Reset analytics data.");
Expand Down Expand Up @@ -222,6 +242,9 @@ void GUIDisplayControls() {
if (GUILayout.Button("Log Level Up")) {
AnalyticsLevelUp();
}
if (GUILayout.Button("Log View Cart")) {
AnalyticsViewCart();
}
if (GUILayout.Button("Reset Analytics Data")) {
ResetAnalyticsData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override void Start() {
TestAnalyticsScoreDoesNotThrow,
TestAnalyticsGroupJoinDoesNotThrow,
TestAnalyticsLevelUpDoesNotThrow,
TestAnalyticsViewCartDoesNotThrow,
// This test regularly fails on iOS simulator, and there isn't a great way
// to determine if this is on a device or simulator, so just disable on
// GHA iOS and tvOS for now.
Expand Down Expand Up @@ -94,6 +95,13 @@ Task TestAnalyticsLevelUpDoesNotThrow() {
});
}

Task TestAnalyticsViewCartDoesNotThrow() {
return WrapWithTask(() => {
base.AnalyticsViewCart();
return true;
});
}

Task TestAnalyticsSetConsentDoesNotThrow() {
return WrapWithTask(() => {
base.AnalyticsSetConsent();
Expand Down
3 changes: 3 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Release Notes
-------------
### Upcoming
- Changes
- Analytics: Add support for Parameters of Lists of Dictionaries, needed
by some events such as ViewCart.
([#1056](https://github.com/firebase/firebase-unity-sdk/issues/1056)).
- Analytics: Renamed ParameterGroupId to ParameterGroupID, to be
consistent with other similarly named variables. ParameterGroupId
is considered deprecated, and will be removed in the future.
Expand Down

0 comments on commit c8fde34

Please sign in to comment.