Skip to content

Commit 9b377ac

Browse files
Here's the plan:
refactor: Address further review comments for Windows Analytics This commit incorporates additional specific feedback on the Windows Analytics C++ implementation (src/analytics_desktop.cc): 1. **Comment Cleanup:** - Removed a commented-out unused constant and its description. - Removed a non-functional comment next to a namespace declaration. - Clarified and shortened the comment in the `is_vector` handling block within `ConvertParametersToGAParams`. 2. **Use Common `AnalyticsFn` Enum:** - Included `analytics/src/common/analytics_common.h`. - Removed the local definition of `AnalyticsFn` enum, now relying on the common definition (assumed to be in `firebase::analytics::internal`). 3. **Corrected Map Parameter to `GoogleAnalytics_Item` Conversion:** - Critically, fixed the logic in `ConvertParametersToGAParams` for when a `Parameter::value` is a map. - Previously, each key-value pair from the input map was incorrectly creating a `GoogleAnalytics_Item` with fixed property names like "name" and "int_value". - The logic now correctly ensures that each key-value pair from your input map becomes a direct property in the `GoogleAnalytics_Item`, using the original map's key as the key for the property in the `GoogleAnalytics_Item`. For example, an entry `{"user_key": 123}` in the input map now results in a property `{"user_key": 123}` within the `GoogleAnalytics_Item`.
1 parent fa9363e commit 9b377ac

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

src/analytics_desktop.cc

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "analytics/src/windows/analytics_windows.h"
1616
#include "app/src/include/firebase/app.h"
1717
#include "analytics/src/include/firebase/analytics.h" // Path confirmed to remain as is
18+
#include "analytics/src/common/analytics_common.h"
1819
#include "common/src/include/firebase/variant.h"
1920
#include "app/src/include/firebase/future.h"
2021
#include "app/src/include/firebase/log.h"
@@ -24,20 +25,18 @@
2425
#include <string>
2526
#include <map>
2627

27-
// Error code for Analytics features not supported on this platform. (Will be removed)
28-
// const int kAnalyticsErrorNotSupportedOnPlatform = 1; // Or a more specific range
29-
3028
namespace firebase {
3129
namespace analytics {
3230

33-
namespace internal { // Or directly in firebase::analytics if that's the pattern
34-
// Functions that return a Future.
35-
enum AnalyticsFn {
36-
kAnalyticsFn_GetAnalyticsInstanceId = 0,
37-
kAnalyticsFn_GetSessionId,
38-
kAnalyticsFnCount // Must be the last enum value.
39-
};
40-
} // namespace internal
31+
// (Local AnalyticsFn enum removed, assuming it's now provided by analytics_common.h)
32+
// namespace internal {
33+
// // Functions that return a Future.
34+
// enum AnalyticsFn {
35+
// kAnalyticsFn_GetAnalyticsInstanceId = 0,
36+
// kAnalyticsFn_GetSessionId,
37+
// kAnalyticsFnCount // Must be the last enum value.
38+
// };
39+
// } // namespace internal
4140

4241
// Future data for analytics.
4342
// This is initialized in `Initialize()` and cleaned up in `Terminate()`.
@@ -103,12 +102,8 @@ static void ConvertParametersToGAParams(
103102
GoogleAnalytics_EventParameters_InsertString(
104103
c_event_params, param.name, param.value.string_value());
105104
} else if (param.value.is_vector()) {
106-
// Vector types for top-level event parameters are not directly supported for conversion
107-
// to GoogleAnalytics_EventParameters on Desktop.
108-
// The previous implementation attempted to interpret a vector of maps as an "Item Array",
109-
// but the standard way to log an array of Items is via a single parameter (e.g., "items")
110-
// whose value is a vector of firebase::analytics::Item objects (which are maps).
111-
// For direct parameters, vector is an unsupported type.
105+
// Vector types for top-level event parameters are not supported on Desktop.
106+
// Only specific complex types (like a map processed into an ItemVector) are handled.
112107
LogError("Analytics: Parameter '%s' has type Vector, which is unsupported for event parameters on Desktop. Skipping.", param.name);
113108
continue; // Skip this parameter
114109
} else if (param.value.is_map()) {
@@ -143,32 +138,28 @@ static void ConvertParametersToGAParams(
143138
continue; // Skip this key-value pair, try next one in map
144139
}
145140

146-
// Store the original map's key as the "name" of this item property
147-
GoogleAnalytics_Item_InsertString(c_item, "name", key_from_map.c_str());
141+
// Removed: GoogleAnalytics_Item_InsertString(c_item, "name", key_from_map.c_str());
148142

149-
bool value_property_set = false;
143+
bool item_had_valid_property = false;
150144
if (value_from_map.is_int64()) {
151-
GoogleAnalytics_Item_InsertInt(c_item, "int_value", value_from_map.int64_value());
152-
value_property_set = true;
145+
GoogleAnalytics_Item_InsertInt(c_item, key_from_map.c_str(), value_from_map.int64_value());
146+
item_had_valid_property = true;
153147
} else if (value_from_map.is_double()) {
154-
GoogleAnalytics_Item_InsertDouble(c_item, "double_value", value_from_map.double_value());
155-
value_property_set = true;
148+
GoogleAnalytics_Item_InsertDouble(c_item, key_from_map.c_str(), value_from_map.double_value());
149+
item_had_valid_property = true;
156150
} else if (value_from_map.is_string()) {
157-
GoogleAnalytics_Item_InsertString(c_item, "string_value", value_from_map.string_value());
158-
value_property_set = true;
151+
GoogleAnalytics_Item_InsertString(c_item, key_from_map.c_str(), value_from_map.string_value());
152+
item_had_valid_property = true;
159153
} else {
160154
LogWarning("Analytics: Value for key '%s' in map parameter '%s' has an unsupported Variant type. This key-value pair will be skipped.", key_from_map.c_str(), param.name);
161-
// As "name" was set, but no value, this item is incomplete.
162155
}
163156

164-
if (value_property_set) {
157+
if (item_had_valid_property) {
165158
GoogleAnalytics_ItemVector_InsertItem(c_item_vector, c_item);
166159
// c_item is now owned by c_item_vector
167160
item_vector_populated = true;
168161
} else {
169-
// If value wasn't set (e.g. unsupported type), or c_item creation failed.
170-
// (c_item creation failure is handled by 'continue' above, so this 'else'
171-
// is mainly for when value_property_set is false due to unsupported type)
162+
// If no valid property was set for this c_item (e.g., value type was unsupported)
172163
GoogleAnalytics_Item_Destroy(c_item);
173164
}
174165
}

0 commit comments

Comments
 (0)