@@ -132,6 +132,15 @@ class Analytics {
132132 * The path must pre-exist and the app has read and write access to it.
133133 */
134134 std::optional<std::string> app_data_directory;
135+ /* *
136+ * @brief The duration of inactivity in seconds after which a session
137+ * terminates.
138+ *
139+ * If a user interacts with the app after this timeout period, a new session
140+ * is initiated. If this field is not set or a negative value is
141+ * provided, the SDK's default timeout duration is used.
142+ */
143+ std::optional<int64_t > session_timeout_duration_seconds;
135144 };
136145
137146 /* *
@@ -169,6 +178,8 @@ class Analytics {
169178 options.app_data_directory .value_or (" " ).empty ()
170179 ? nullptr
171180 : options.app_data_directory .value ().c_str ();
181+ google_analytics_options->session_timeout_duration_seconds =
182+ options.session_timeout_duration_seconds .value_or (-1 );
172183 return GoogleAnalytics_Initialize (google_analytics_options);
173184 }
174185
@@ -373,35 +384,49 @@ class Analytics {
373384 return ;
374385 }
375386
376- GoogleAnalytics_SetLogCallback (
377- [](GoogleAnalytics_LogLevel log_level, const char * message) {
378- LogLevel cpp_log_level;
379- switch (log_level) {
380- case GoogleAnalytics_LogLevel_kDebug:
381- cpp_log_level = LogLevel::kDebug ;
382- break ;
383- case GoogleAnalytics_LogLevel_kInfo:
384- cpp_log_level = LogLevel::kInfo ;
385- break ;
386- case GoogleAnalytics_LogLevel_kWarning:
387- cpp_log_level = LogLevel::kWarning ;
388- break ;
389- case GoogleAnalytics_LogLevel_kError:
390- cpp_log_level = LogLevel::kError ;
391- break ;
392- default :
393- cpp_log_level = LogLevel::kInfo ;
394- }
395- LogCallback local_callback;
396- Analytics& self = Analytics::GetInstance ();
397- {
398- std::lock_guard<std::mutex> lock (self.mutex_ );
399- local_callback = self.current_callback_ ;
400- }
401- if (local_callback) {
402- local_callback (cpp_log_level, std::string (message));
403- }
404- });
387+ GoogleAnalytics_SetLogCallback ([](int32_t log_level, const char * message) {
388+ LogLevel cpp_log_level;
389+ switch (log_level) {
390+ case GoogleAnalytics_LogLevel_kDebug:
391+ cpp_log_level = LogLevel::kDebug ;
392+ break ;
393+ case GoogleAnalytics_LogLevel_kInfo:
394+ cpp_log_level = LogLevel::kInfo ;
395+ break ;
396+ case GoogleAnalytics_LogLevel_kWarning:
397+ cpp_log_level = LogLevel::kWarning ;
398+ break ;
399+ case GoogleAnalytics_LogLevel_kError:
400+ cpp_log_level = LogLevel::kError ;
401+ break ;
402+ default :
403+ cpp_log_level = LogLevel::kInfo ;
404+ }
405+ LogCallback local_callback;
406+ Analytics& self = Analytics::GetInstance ();
407+ {
408+ std::lock_guard<std::mutex> lock (self.mutex_ );
409+ local_callback = self.current_callback_ ;
410+ }
411+ if (local_callback) {
412+ local_callback (cpp_log_level, std::string (message));
413+ }
414+ });
415+ }
416+
417+ /* *
418+ * @brief Sets the duration of inactivity in seconds after which a session
419+ * terminates.
420+ *
421+ * If a user interacts with the app after this timeout period, a new session
422+ * is initiated. If set to a negative value, the value is ignored. The default
423+ * value is 1800 seconds (30 minutes).
424+ *
425+ * @param[in] session_timeout_duration_seconds The session timeout duration in
426+ * seconds.
427+ */
428+ void SetSessionTimeoutInterval (int64_t session_timeout_duration_seconds) {
429+ GoogleAnalytics_SetSessionTimeoutInterval (session_timeout_duration_seconds);
405430 }
406431
407432 /* *
0 commit comments