diff --git a/Aptabase.uplugin b/Aptabase.uplugin index 67b22e1..40f635a 100644 --- a/Aptabase.uplugin +++ b/Aptabase.uplugin @@ -1,6 +1,6 @@ { "FileVersion": 3, - "VersionName": "0.1.0", + "VersionName": "0.1.1", "EngineVersion": "5.2", "FriendlyName": "Aptabase", "Description": "Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", diff --git a/Docs/event-with-attributes.png b/Docs/event-with-attributes.png index 1276d68..eeec227 100644 Binary files a/Docs/event-with-attributes.png and b/Docs/event-with-attributes.png differ diff --git a/Source/Aptabase/Private/AptabaseAnalyticsProvider.cpp b/Source/Aptabase/Private/AptabaseAnalyticsProvider.cpp index 7c6465b..cfcb6ad 100644 --- a/Source/Aptabase/Private/AptabaseAnalyticsProvider.cpp +++ b/Source/Aptabase/Private/AptabaseAnalyticsProvider.cpp @@ -20,27 +20,17 @@ void FAptabaseAnalyticsProvider::RecordExtendedEvent(const FString& EventName, c bool FAptabaseAnalyticsProvider::StartSession(const TArray& Attributes) { - if (bHasActiveSession) - { - UE_LOG(LogAptabase, Warning, TEXT("Session start requested while a session was running. Please manually end the session before starting a new one.")); - EndSession(); - } + int64 EpochInSeconds = FDateTime::UtcNow().ToUnixTimestamp(); + int Random = FMath::RandRange(0, 99999999); + FString RandomString = FString::Printf(TEXT("%08d"), Random); + SessionId = FString::Printf(TEXT("%lld%s"), EpochInSeconds, *RandomString); bHasActiveSession = true; - RecordEvent(TEXT("SessionStart"), Attributes); return true; } void FAptabaseAnalyticsProvider::EndSession() { - if (!bHasActiveSession) - { - UE_LOG(LogAptabase, Log, TEXT("No session is currently active. Discarding session end request.")); - return; - } - - RecordEvent(TEXT("SessionEnd"), {}); - bHasActiveSession = false; } @@ -51,14 +41,8 @@ FString FAptabaseAnalyticsProvider::GetSessionID() const bool FAptabaseAnalyticsProvider::SetSessionID(const FString& InSessionID) { - if (bHasActiveSession) - { - UE_LOG(LogAptabase, Warning, TEXT("Cannot change the Session Id while session is running. Discarding session id set request.")); - return false; - } - - SessionId = InSessionID; - return true; + UE_LOG(LogAptabase, Log, TEXT("Aptabase automatically generates and manage sessions. Discarding session id set request.")); + return false; } void FAptabaseAnalyticsProvider::FlushEvents() @@ -93,6 +77,12 @@ void FAptabaseAnalyticsProvider::RecordEvent(const FString& EventName, const TAr void FAptabaseAnalyticsProvider::RecordEventInternal(const FString& EventName, const TArray& Attributes) { + if (!bHasActiveSession) + { + UE_LOG(LogAptabase, Log, TEXT("No session is currently active. Discarding event.")); + return; + } + const UAptabaseSettings* Settings = GetDefault(); const TSharedPtr AptabasePlugin = IPluginManager::Get().FindPlugin("Aptabase"); @@ -163,4 +153,4 @@ void FAptabaseAnalyticsProvider::OnEventRecoded(FHttpRequestPtr Request, FHttpRe } UE_LOG(LogAptabase, Verbose, TEXT("Event recorded successfully.")); -} \ No newline at end of file +}