Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new session id #10

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Aptabase.uplugin
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Binary file modified Docs/event-with-attributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 13 additions & 23 deletions Source/Aptabase/Private/AptabaseAnalyticsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,17 @@ void FAptabaseAnalyticsProvider::RecordExtendedEvent(const FString& EventName, c

bool FAptabaseAnalyticsProvider::StartSession(const TArray<FAnalyticsEventAttribute>& 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;
}

Expand All @@ -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()
Expand Down Expand Up @@ -93,6 +77,12 @@ void FAptabaseAnalyticsProvider::RecordEvent(const FString& EventName, const TAr

void FAptabaseAnalyticsProvider::RecordEventInternal(const FString& EventName, const TArray<FExtendedAnalyticsEventAttribute>& Attributes)
{
if (!bHasActiveSession)
{
UE_LOG(LogAptabase, Log, TEXT("No session is currently active. Discarding event."));
return;
}

const UAptabaseSettings* Settings = GetDefault<UAptabaseSettings>();
const TSharedPtr<IPlugin> AptabasePlugin = IPluginManager::Get().FindPlugin("Aptabase");

Expand Down Expand Up @@ -163,4 +153,4 @@ void FAptabaseAnalyticsProvider::OnEventRecoded(FHttpRequestPtr Request, FHttpRe
}

UE_LOG(LogAptabase, Verbose, TEXT("Event recorded successfully."));
}
}
Loading