@@ -539,6 +539,11 @@ namespace gameanalytics
539539 return " " ;
540540 }
541541
542+ int64_t GAState::getLastSessionLength () const
543+ {
544+ return _lastSessionTime;
545+ }
546+
542547 int64_t GAState::getTotalSessionLength () const
543548 {
544549 return _totalElapsedSessionTime + calculateSessionLength<std::chrono::seconds>();
@@ -590,10 +595,11 @@ namespace gameanalytics
590595
591596 try
592597 {
593- std::string cachedSessionTime = utilities::getOptionalValue<std::string>(state_dict, " total_session_time" , " 0" );
598+ std::string cachedLastSessionTime = utilities::getOptionalValue<std::string>(state_dict, " last_session_time" , " 0" );
599+ std::string cachedTotalSessionTime = utilities::getOptionalValue<std::string>(state_dict, " total_session_time" , " 0" );
594600
595- _totalElapsedSessionTime = std::stoull (cachedSessionTime );
596-
601+ _lastSessionTime = std::stoull (cachedTotalSessionTime );
602+ _totalElapsedSessionTime = std::stoull (cachedTotalSessionTime);
597603 }
598604 catch (const std::exception& e)
599605 {
@@ -1094,7 +1100,10 @@ namespace gameanalytics
10941100
10951101 void GAState::updateTotalSessionTime ()
10961102 {
1097- _totalElapsedSessionTime = getTotalSessionLength ();
1103+ _lastSessionTime = calculateSessionLength ();
1104+ _totalElapsedSessionTime += _lastSessionTime;
1105+
1106+ _gaStore.setState (" last_session_time" , std::to_string (_lastSessionTime));
10981107 _gaStore.setState (" total_session_time" , std::to_string (_totalElapsedSessionTime));
10991108 }
11001109
0 commit comments