Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions analytics/src/analytics_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ LogLevel ConvertAnalyticsLogLevelToFirebaseLogLevel(
}
}

void GoogleAnalyticsWrapperLogCallback(GoogleAnalytics_LogLevel log_level,
const char* message) {
void GoogleAnalyticsWrapperLogCallback(int32_t log_level, const char* message) {
LogCallback callback_to_call;

{
Expand All @@ -421,8 +420,8 @@ void GoogleAnalyticsWrapperLogCallback(GoogleAnalytics_LogLevel log_level,
}

if (callback_to_call) {
LogLevel firebase_log_level =
ConvertAnalyticsLogLevelToFirebaseLogLevel(log_level);
LogLevel firebase_log_level = ConvertAnalyticsLogLevelToFirebaseLogLevel(
static_cast<GoogleAnalytics_LogLevel>(log_level));
callback_to_call(firebase_log_level, message);
}
}
Expand Down
5 changes: 3 additions & 2 deletions analytics/src/analytics_desktop_dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ const char* FirebaseAnalytics_KnownWindowsDllHashes[] = {
"c1b9ff6e9119c30bbeb7472326dcde418f45682e6b822e25eed922fe6e3cc698",
"13ae5f9349b24186f1f3667b52832076e8d14ad9656c3546b1b7fca79ac8144b",
"3f1fb1bb21bce0061c4b89bb674d3b6c94eaea2c8de98802198a35ea94c97900",
"1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5"
"1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5",
"496a9f262836523a7e5db097b2b663f9875eab36e010343d9b967bfa9eef567d"
};

// Count of known Google Analytics Windows DLL SHA256 hashes.
const int FirebaseAnalytics_KnownWindowsDllHashCount = 4;
const int FirebaseAnalytics_KnownWindowsDllHashCount = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and prevent potential mismatches in the future, it's better to calculate the number of hashes dynamically rather than hardcoding it. This ensures that the count is always in sync with the number of elements in the FirebaseAnalytics_KnownWindowsDllHashes array.

Suggested change
const int FirebaseAnalytics_KnownWindowsDllHashCount = 5;
const int FirebaseAnalytics_KnownWindowsDllHashCount = sizeof(FirebaseAnalytics_KnownWindowsDllHashes) / sizeof(FirebaseAnalytics_KnownWindowsDllHashes[0]);

#endif // defined(_WIN32)

// --- Stub Function Definitions ---
Expand Down
2 changes: 1 addition & 1 deletion analytics/src/analytics_desktop_dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ typedef enum GoogleAnalytics_LogLevel {
*
* @param[in] message The log message string.
*/
typedef void (*GoogleAnalytics_LogCallback)(GoogleAnalytics_LogLevel log_level,
typedef void (*GoogleAnalytics_LogCallback)(int32_t log_level,
const char* message);

/**
Expand Down
Binary file modified analytics/windows/google_analytics.dll
Binary file not shown.
83 changes: 54 additions & 29 deletions analytics/windows/include/public/analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ class Analytics {
* The path must pre-exist and the app has read and write access to it.
*/
std::optional<std::string> app_data_directory;
/**
* @brief The duration of inactivity in seconds after which a session
* terminates.
*
* If a user interacts with the app after this timeout period, a new session
* is initiated. If this field is not set or a negative value is
* provided, the SDK's default timeout duration is used.
*/
std::optional<int64_t> session_timeout_duration_seconds;
};

/**
Expand Down Expand Up @@ -169,6 +178,8 @@ class Analytics {
options.app_data_directory.value_or("").empty()
? nullptr
: options.app_data_directory.value().c_str();
google_analytics_options->session_timeout_duration_seconds =
options.session_timeout_duration_seconds.value_or(-1);
return GoogleAnalytics_Initialize(google_analytics_options);
}

Expand Down Expand Up @@ -373,35 +384,49 @@ class Analytics {
return;
}

GoogleAnalytics_SetLogCallback(
[](GoogleAnalytics_LogLevel log_level, const char* message) {
LogLevel cpp_log_level;
switch (log_level) {
case GoogleAnalytics_LogLevel_kDebug:
cpp_log_level = LogLevel::kDebug;
break;
case GoogleAnalytics_LogLevel_kInfo:
cpp_log_level = LogLevel::kInfo;
break;
case GoogleAnalytics_LogLevel_kWarning:
cpp_log_level = LogLevel::kWarning;
break;
case GoogleAnalytics_LogLevel_kError:
cpp_log_level = LogLevel::kError;
break;
default:
cpp_log_level = LogLevel::kInfo;
}
LogCallback local_callback;
Analytics& self = Analytics::GetInstance();
{
std::lock_guard<std::mutex> lock(self.mutex_);
local_callback = self.current_callback_;
}
if (local_callback) {
local_callback(cpp_log_level, std::string(message));
}
});
GoogleAnalytics_SetLogCallback([](int32_t log_level, const char* message) {
LogLevel cpp_log_level;
switch (log_level) {
case GoogleAnalytics_LogLevel_kDebug:
cpp_log_level = LogLevel::kDebug;
break;
case GoogleAnalytics_LogLevel_kInfo:
cpp_log_level = LogLevel::kInfo;
break;
case GoogleAnalytics_LogLevel_kWarning:
cpp_log_level = LogLevel::kWarning;
break;
case GoogleAnalytics_LogLevel_kError:
cpp_log_level = LogLevel::kError;
break;
default:
cpp_log_level = LogLevel::kInfo;
}
LogCallback local_callback;
Analytics& self = Analytics::GetInstance();
{
std::lock_guard<std::mutex> lock(self.mutex_);
local_callback = self.current_callback_;
}
if (local_callback) {
local_callback(cpp_log_level, std::string(message));
}
});
}

/**
* @brief Sets the duration of inactivity in seconds after which a session
* terminates.
*
* If a user interacts with the app after this timeout period, a new session
* is initiated. If set to a negative value, the value is ignored. The default
* value is 1800 seconds (30 minutes).
*
* @param[in] session_timeout_duration_seconds The session timeout duration in
* seconds.
*/
void SetSessionTimeoutInterval(int64_t session_timeout_duration_seconds) {
GoogleAnalytics_SetSessionTimeoutInterval(session_timeout_duration_seconds);
}

/**
Expand Down
45 changes: 40 additions & 5 deletions analytics/windows/include/public/c/analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ typedef struct ANALYTICS_API GoogleAnalytics_Options {
*/
const char* app_data_directory;

/**
* @brief The duration of inactivity in seconds after which a session
* terminates.
*
* If a user interacts with the app after this timeout period,
* a new session is initiated. If set to a negative value, the SDK's
* default timeout duration is used.
*/
int64_t session_timeout_duration_seconds;

/**
* @brief Reserved for internal use by the SDK.
*/
Expand Down Expand Up @@ -137,9 +147,15 @@ typedef enum GoogleAnalytics_LogLevel {
/**
* @brief Function pointer type for a log callback.
*
* @param[in] message The log message string.
* @param[in] message The log message string. Pass a value from the
* #GoogleAnalytics_LogLevel enum.
*
* @note The parameters are defined as `int32_t` to ensure ABI stability across
* different compilers, but callers should use the enum constants directly.
*
* @see GoogleAnalytics_LogLevel
*/
typedef void (*GoogleAnalytics_LogCallback)(GoogleAnalytics_LogLevel log_level,
typedef void (*GoogleAnalytics_LogCallback)(int32_t log_level,
const char* message);

/**
Expand Down Expand Up @@ -525,6 +541,20 @@ ANALYTICS_API void GoogleAnalytics_SetAnalyticsCollectionEnabled(bool enabled);
ANALYTICS_API void GoogleAnalytics_SetLogCallback(
GoogleAnalytics_LogCallback callback);

/**
* @brief Sets the duration of inactivity in seconds after which a session
* terminates.
*
* If a user interacts with the app after this timeout period, a new session is
* initiated. If set to a negative value, the value is ignored. The default
* value is 1800 seconds (30 minutes).
*
* @param[in] session_timeout_duration_seconds The session timeout duration in
* seconds.
*/
ANALYTICS_API void GoogleAnalytics_SetSessionTimeoutInterval(
int64_t session_timeout_duration_seconds);

/**
* @brief Notifies the current state of the app's lifecycle.
*
Expand All @@ -537,10 +567,15 @@ ANALYTICS_API void GoogleAnalytics_SetLogCallback(
* data is uploaded or an error occurs. The caller must ensure the OS does not
* terminate background threads before the call returns.
*
* @param[in] state The current state of the app's lifecycle.
* @param[in] state The current state of the app's lifecycle. Pass a value from
* the #GoogleAnalytics_AppLifecycleState enum.
*
* @note The parameters are defined as `int32_t` to ensure ABI stability across
* different compilers, but callers should use the enum constants directly.
*
* @see GoogleAnalytics_AppLifecycleState
*/
ANALYTICS_API void GoogleAnalytics_NotifyAppLifecycleChange(
GoogleAnalytics_AppLifecycleState state);
ANALYTICS_API void GoogleAnalytics_NotifyAppLifecycleChange(int32_t state);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion analytics/windows/known_dll_hashes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
c1b9ff6e9119c30bbeb7472326dcde418f45682e6b822e25eed922fe6e3cc698
13ae5f9349b24186f1f3667b52832076e8d14ad9656c3546b1b7fca79ac8144b
3f1fb1bb21bce0061c4b89bb674d3b6c94eaea2c8de98802198a35ea94c97900
1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5
1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5
496a9f262836523a7e5db097b2b663f9875eab36e010343d9b967bfa9eef567d
Loading