Skip to content

Commit 573b647

Browse files
I've added SetDefaultEventParameters and ClearDefaultEventParameters to Analytics for you.
This change introduces two new C++ Analytics SDK functions: - `SetDefaultEventParameters(const std::map<std::string, Variant>& params)`: This allows you to set default parameters (string, int64, double, bool, null) that will be included in all subsequent `LogEvent` calls. If a `Variant::Null()` is provided for a key, that specific default parameter will be cleared. Aggregate types (maps, vectors) are not supported and will be skipped with an error logged. - `ClearDefaultEventParameters()`: This clears all currently set default event parameters. Here's how it's implemented on different platforms: - iOS: Uses `[FIRAnalytics setDefaultEventParameters:]`. `Variant::Null()` maps to `[NSNull null]`. Unsupported types are skipped. Passing an empty dictionary (if all input params are invalid) is a no-op. - Android: Uses `FirebaseAnalytics.setDefaultEventParameters(Bundle)`. `Variant::Null()` results in `Bundle.putString(key, null)`. Unsupported types are skipped. `AddVariantToBundle` is used for efficiency with scalar types. - Stub: Implemented as no-ops. I've also reviewed and updated the unit tests and integration tests to cover these functionalities and type constraints. Namespace usage for `Variant` has been refined: - Public API (`analytics.h`) uses unqualified `Variant` as it's within the `firebase` namespace. - SDK implementation file signatures match `analytics.h` (unqualified `Variant`). - Internal SDK code uses unqualified `Variant`. - Integration tests use `firebase::Variant` as they are outside the `firebase` namespace. I've applied code formatting using the project's script and updated and shortened the release notes in `release_build_files/readme.md`.
1 parent 8ddab84 commit 573b647

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

analytics/src/analytics_ios.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void SetSessionTimeoutDuration(int64_t milliseconds) {
373373
setSessionTimeoutInterval:static_cast<NSTimeInterval>(milliseconds) / kMillisecondsPerSecond];
374374
}
375375

376-
void SetDefaultEventParameters(const std::map<std::string, firebase::Variant>& default_parameters) {
376+
void SetDefaultEventParameters(const std::map<std::string, Variant>& default_parameters) {
377377
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
378378
NSMutableDictionary* ns_default_parameters =
379379
[[NSMutableDictionary alloc] initWithCapacity:default_parameters.size()];

analytics/src/analytics_stub.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void SetSessionTimeoutDuration(int64_t /*milliseconds*/) {
143143
}
144144

145145
void SetDefaultEventParameters(
146-
const std::map<std::string, firebase::Variant>& /*default_parameters*/) {
146+
const std::map<std::string, Variant>& /*default_parameters*/) {
147147
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
148148
// This is a stub implementation. No operation needed.
149149
}

analytics/src/include/firebase/analytics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct Parameter {
142142
/// @param parameter_name Name of the parameter (see Parameter::name).
143143
/// @param parameter_value Value for the parameter. Variants can
144144
/// hold numbers and strings.
145-
Parameter(const char* parameter_name, firebase::Variant parameter_value)
145+
Parameter(const char* parameter_name, Variant parameter_value)
146146
: name(parameter_name) {
147147
value = parameter_value;
148148
}
@@ -245,7 +245,7 @@ struct Parameter {
245245
///
246246
/// See firebase::Variant for usage information.
247247
/// @note String values can be up to 100 characters long.
248-
firebase::Variant value;
248+
Variant value;
249249
#endif // SWIG
250250
};
251251

@@ -570,7 +570,7 @@ void ResetAnalyticsData();
570570
///
571571
/// @param[in] default_parameters A map of parameter names to Variant values.
572572
void SetDefaultEventParameters(
573-
const std::map<std::string, firebase::Variant>& default_parameters);
573+
const std::map<std::string, Variant>& default_parameters);
574574

575575
/// @brief Clears all default event parameters.
576576
void ClearDefaultEventParameters();

0 commit comments

Comments
 (0)