@@ -426,6 +426,10 @@ namespace gameanalytics
426426 out[" session_num" ] = getInstance ()._sessionNum ;
427427 out[" connection_type" ] = device::GADevice::getConnectionType ();
428428
429+ // playtime metrics
430+ out[" current_session_length" ] = getInstance ().calculateSessionLength ();
431+ out[" lifetime_session_length" ] = getInstance ().getTotalSessionLength ();
432+
429433 // ---- OPTIONAL ---- //
430434
431435 // A/B testing
@@ -535,6 +539,11 @@ namespace gameanalytics
535539 return " " ;
536540 }
537541
542+ int64_t GAState::getLastSessionLength () const
543+ {
544+ return _lastSessionTime;
545+ }
546+
538547 int64_t GAState::getTotalSessionLength () const
539548 {
540549 return _totalElapsedSessionTime + calculateSessionLength<std::chrono::seconds>();
@@ -586,10 +595,11 @@ namespace gameanalytics
586595
587596 try
588597 {
589- 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" );
590600
591- _totalElapsedSessionTime = std::stoull (cachedSessionTime );
592-
601+ _lastSessionTime = std::stoull (cachedLastSessionTime );
602+ _totalElapsedSessionTime = std::stoull (cachedTotalSessionTime);
593603 }
594604 catch (const std::exception& e)
595605 {
@@ -1090,8 +1100,11 @@ namespace gameanalytics
10901100
10911101 void GAState::updateTotalSessionTime ()
10921102 {
1093- int64_t totalSessionTime = getTotalSessionLength ();
1094- _gaStore.setState (" total_session_time" , std::to_string (totalSessionTime));
1103+ _lastSessionTime = calculateSessionLength ();
1104+ _totalElapsedSessionTime += _lastSessionTime;
1105+
1106+ _gaStore.setState (" last_session_time" , std::to_string (_lastSessionTime));
1107+ _gaStore.setState (" total_session_time" , std::to_string (_totalElapsedSessionTime));
10951108 }
10961109
10971110 std::string GAState::getBuild ()
0 commit comments