@@ -83,6 +83,7 @@ class Analytics {
8383 kError ,
8484 };
8585
86+
8687 /* *
8788 * @brief The callback type for logging messages from the SDK.
8889 *
@@ -132,6 +133,15 @@ class Analytics {
132133 * The path must pre-exist and the app has read and write access to it.
133134 */
134135 std::optional<std::string> app_data_directory;
136+ /* *
137+ * @brief The duration of inactivity in seconds after which a session
138+ * terminates.
139+ *
140+ * If a user interacts with the app after this timeout period, a new session
141+ * is initiated. If this field is not set or a negative value is
142+ * provided, the SDK's default timeout duration is used.
143+ */
144+ std::optional<int64_t > session_timeout_duration_seconds;
135145 };
136146
137147 /* *
@@ -169,6 +179,8 @@ class Analytics {
169179 options.app_data_directory .value_or (" " ).empty ()
170180 ? nullptr
171181 : options.app_data_directory .value ().c_str ();
182+ google_analytics_options->session_timeout_duration_seconds =
183+ options.session_timeout_duration_seconds .value_or (-1 );
172184 return GoogleAnalytics_Initialize (google_analytics_options);
173185 }
174186
@@ -373,35 +385,49 @@ class Analytics {
373385 return ;
374386 }
375387
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- });
388+ GoogleAnalytics_SetLogCallback ([](int32_t log_level, const char * message) {
389+ LogLevel cpp_log_level;
390+ switch (log_level) {
391+ case GoogleAnalytics_LogLevel_kDebug:
392+ cpp_log_level = LogLevel::kDebug ;
393+ break ;
394+ case GoogleAnalytics_LogLevel_kInfo:
395+ cpp_log_level = LogLevel::kInfo ;
396+ break ;
397+ case GoogleAnalytics_LogLevel_kWarning:
398+ cpp_log_level = LogLevel::kWarning ;
399+ break ;
400+ case GoogleAnalytics_LogLevel_kError:
401+ cpp_log_level = LogLevel::kError ;
402+ break ;
403+ default :
404+ cpp_log_level = LogLevel::kInfo ;
405+ }
406+ LogCallback local_callback;
407+ Analytics& self = Analytics::GetInstance ();
408+ {
409+ std::lock_guard<std::mutex> lock (self.mutex_ );
410+ local_callback = self.current_callback_ ;
411+ }
412+ if (local_callback) {
413+ local_callback (cpp_log_level, std::string (message));
414+ }
415+ });
416+ }
417+
418+ /* *
419+ * @brief Sets the duration of inactivity in seconds after which a session
420+ * terminates.
421+ *
422+ * If a user interacts with the app after this timeout period, a new session
423+ * is initiated. If set to a negative value, the value is ignored. The default
424+ * value is 1800 seconds (30 minutes).
425+ *
426+ * @param[in] session_timeout_duration_seconds The session timeout duration in
427+ * seconds.
428+ */
429+ void SetSessionTimeoutInterval (int64_t session_timeout_duration_seconds) {
430+ GoogleAnalytics_SetSessionTimeoutInterval (session_timeout_duration_seconds);
405431 }
406432
407433 /* *
@@ -444,9 +470,11 @@ class Analytics {
444470 GoogleAnalytics_NotifyAppLifecycleChange (c_state);
445471 }
446472
473+
447474 private:
448475 Analytics () = default ;
449476
477+
450478 std::mutex mutex_;
451479 LogCallback current_callback_;
452480};
0 commit comments