Skip to main content

Session

The Session object is responsible for maintaining persistent data around user sessions over the life-time of an application.

Constructor

Argument NameDescriptionRequired?Default
savePathThe path to save persistent data intoYesNull
foregroundTimeoutThe time until a session expires in focusNo600 (s)
backgroundTimeoutThe time until a session expires in backNo300 (s)
checkIntervalHow often to validate the session timeoutNo15 (s)
loggerThe logger to use within the applicationNoNull

A full ClientSession construction should look like the following:

ClientSession session = new ClientSession ("save_file_path.xml");

The timeout's refer to the length of time the session remains active after the last event is sent. As long as events are sent within this limit the session will not timeout.

NOTE: When using the Tracker within Xamarin you will need to fetch a correct path for internal storage. Some example code for fetching this path:

// Android
public string GetLocalFilePath(string filename)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return Path.Combine(path, filename);
}

// iOS
public string GetLocalFilePath(string filename)
{
string docFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string libFolder = Path.Combine(docFolder, "..", "Library", "Databases");

if (!Directory.Exists(libFolder))
{
Directory.CreateDirectory(libFolder);
}

return Path.Combine(libFolder, filename);
}

6.2 Functions

SetBackground(bool)

Will set whether or not the application is in the background. It is up to the developer to set this metric if they wish to have a different timeout for foreground and background.

NOTE: If a timeout occurs while the application has been backgrounded the SessionChecker will be stopped automatically. Session checking will resume on Foregrounding or on an event being tracked.

Was this page helpful?