Skip to content

Commit 7bc130e

Browse files
committed
PR Chagnes
1 parent e547f68 commit 7bc130e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

examples/example_integration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ int main() {
9393
}
9494
}
9595

96-
ct.updateSession();
97-
ct.stop();
96+
//ct.updateSession();
97+
ct.endSession();
9898

9999
return 0;
100100
}

src/countly.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ bool Countly::beginSession() {
415415
}
416416

417417
bool Countly::updateSession() {
418-
log(Countly::LogLevel::INFO, "[Countly][updateSession]");
419-
420418
mutex.lock();
421419
if (!began_session) {
422420
mutex.unlock();
@@ -484,7 +482,23 @@ bool Countly::updateSession() {
484482
auto duration = std::chrono::duration_cast<std::chrono::seconds>(getSessionDuration());
485483
mutex.lock();
486484

485+
if (duration.count() * 1000 >= COUNTLY_KEEPALIVE_INTERVAL) {
486+
log(Countly::LogLevel::DEBUG, "[Countly][updateSession] sending session update.");
487+
std::map<std::string, std::string> data = {
488+
{"app_key", session_params["app_key"].get<std::string>()},
489+
{"device_id", session_params["device_id"].get<std::string>()},
490+
{"session_duration", std::to_string(duration.count())}
491+
};
492+
if (!sendHTTP("/i", Countly::serializeForm(data)).success) {
493+
mutex.unlock();
494+
return false;
495+
}
496+
497+
last_sent_session_request += duration;
498+
}
499+
487500
if (!no_events) {
501+
log(Countly::LogLevel::DEBUG, "[Countly][updateSession] sending event.");
488502
std::map<std::string, std::string> data = {
489503
{"app_key", session_params["app_key"].get<std::string>()},
490504
{"device_id", session_params["device_id"].get<std::string>()},
@@ -497,18 +511,6 @@ bool Countly::updateSession() {
497511
}
498512
}
499513

500-
std::map<std::string, std::string> data = {
501-
{"app_key", session_params["app_key"].get<std::string>()},
502-
{"device_id", session_params["device_id"].get<std::string>()},
503-
{"session_duration", std::to_string(duration.count())}
504-
};
505-
if (!sendHTTP("/i", Countly::serializeForm(data)).success) {
506-
mutex.unlock();
507-
return false;
508-
}
509-
510-
last_sent_session_request += duration;
511-
512514
#ifndef COUNTLY_USE_SQLITE
513515
event_queue.clear();
514516
#else

0 commit comments

Comments
 (0)