From c8fde34333a73aab1f83df6f9b3244ed8e99ec07 Mon Sep 17 00:00:00 2001 From: a-maurice Date: Mon, 21 Oct 2024 14:35:12 -0700 Subject: [PATCH] Add support for Analytics Parameters of Lists (#1126) --- analytics/src/Parameter.cs | 3 --- .../Firebase/Sample/Analytics/UIHandler.cs | 23 +++++++++++++++++++ .../Sample/Analytics/UIHandlerAutomated.cs | 8 +++++++ docs/readme.md | 3 +++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/analytics/src/Parameter.cs b/analytics/src/Parameter.cs index 5b14f008..ce809644 100644 --- a/analytics/src/Parameter.cs +++ b/analytics/src/Parameter.cs @@ -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 parameterValue) { Name = parameterName; Value = parameterValue; @@ -93,7 +91,6 @@ public Parameter(string parameterName, IEnumerable> 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.")] diff --git a/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandler.cs b/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandler.cs index 25cb7dfd..08564b79 100644 --- a/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandler.cs +++ b/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandler.cs @@ -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 { + { FirebaseAnalytics.ParameterItemID, "SKU_12345" }, + { FirebaseAnalytics.ParameterItemName, "Horse Armor DLC" }, + }, + new Dictionary { + { FirebaseAnalytics.ParameterItemID, "SKU_67890" }, + { FirebaseAnalytics.ParameterItemName, "Gold Horse Armor DLC" }, + } + }) + ); + } + // Reset analytics data for this app instance. public void ResetAnalyticsData() { DebugLog("Reset analytics data."); @@ -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(); } diff --git a/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandlerAutomated.cs b/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandlerAutomated.cs index b4356bce..e101771a 100644 --- a/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandlerAutomated.cs +++ b/analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandlerAutomated.cs @@ -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. @@ -94,6 +95,13 @@ Task TestAnalyticsLevelUpDoesNotThrow() { }); } + Task TestAnalyticsViewCartDoesNotThrow() { + return WrapWithTask(() => { + base.AnalyticsViewCart(); + return true; + }); + } + Task TestAnalyticsSetConsentDoesNotThrow() { return WrapWithTask(() => { base.AnalyticsSetConsent(); diff --git a/docs/readme.md b/docs/readme.md index f2d2c8d3..7758ea14 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -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.