Session Management

General functions for handling session recording

Unreal Settings

SettingDescription

API Key

The API key from your project settings on the Metalitix website.

Use Debug Mode

If true, logs all messages to console (server callbacks, errors, etc.).

Hosted Locally

If true, specifies the origin as http://localhost (if you run application locally this field is required).

Inactivity Interval

Amount of user inactivity time, in seconds, after which the session will be automatically closed. By default, the session will close after 2 minutes.

Poll Interval

The time, in seconds, between samples of data from the user.

Unreal Functions

FunctionDescription

logger.Initialize(trackingEntity = null)

Initialization method for the TrackingEntity, which is typically the user’s camera.

logger.SetTrackingEntity(trackingEntity)

Manually change the TrackingEntity at runtime.

logger.PauseSession()

Stop sending data, but do not close the session.

logger.ResumeSession()

Start sending data again with the existing, open session.

logger.EndSession()

Stop sending data and close the session.

logger.EndSession(true)

Stop send data, close the session, and clear any custom field metrics.

logger.IsRunning()

Returns true if the session has started and is actively sending data. Returns false otherwise, such as if the session is ended or paused.

Example Unreal Scripts

The example script can be found in the Sample/ExampleMetalitix folder. It can be transfered into the level and tested using the Debugger.

Header File
*.h
#pragma once

#include "CoreMinimal.h"
#include "Core/Base/MetalitixLogger.h"
#include "GameFramework/Actor.h"
#include "ExampleMetalitix.generated.h"

UCLASS()
class METALITIX_API AExampleMetalitix : public AActor
{
    GENERATED_BODY()
    
public:    
    AExampleMetalitix();
    virtual void Tick(float DeltaTime) override;

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void Init();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void AfkHandle();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void StartSession();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void EndSession();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void PauseSession();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void ResumeSession();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void UpdateSession();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void AddCustomField();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void RemoveCustomField();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void SetPollInterval();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void ShowSurvey();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void OnEnterPressed();

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void SendCustomEventString(FString MetricName,FString FieldKey,FString Value);

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void SendCustomEventBool(FString MetricName,FString FieldKey,bool Value);

    UFUNCTION(BlueprintCallable,Category="Metalitix")
    void SendCustomEventNumber(FString MetricName,FString FieldKey,float Value);

    UPROPERTY(EditAnywhere,Category="Metalitix")
    AMetalitixLogger* MetalitixLogger;

protected:
    virtual void BeginPlay() override;
};
Source File
*.cpp
#include "Sample/ExampleMetalitix.h"
#include "Extensions/MetalitixDebug.h"

AExampleMetalitix::AExampleMetalitix()
{
    PrimaryActorTick.bCanEverTick = true;
}

void AExampleMetalitix::BeginPlay()
{
    Super::BeginPlay();
    MetalitixLogger->OnAwayFromKeyboard.AddLambda([&]{AfkHandle();});
}

void AExampleMetalitix::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
}

void AExampleMetalitix::Init()
{
    MetalitixLogger->Initialize(nullptr);
}

void AExampleMetalitix::AfkHandle()
{
    FMetalitixDebug::Log(this, "User is afk");
}
void AExampleMetalitix::StartSession()
{
    MetalitixLogger->StartSession();
}
        

 void AExampleMetalitix::EndSession()
{
    MetalitixLogger->EndSession();
}
        

 void AExampleMetalitix::PauseSession()
{
    MetalitixLogger->PauseSession();
}
        

void AExampleMetalitix::ResumeSession()
{
    MetalitixLogger->ResumeSession();
}
        

void AExampleMetalitix::UpdateSession()
{
    MetalitixLogger->UpdateSession();
}
        

void AExampleMetalitix::AddCustomField()
{
    MetalitixLogger->SetCustomField("custom", 10000);
}


void AExampleMetalitix::RemoveCustomField()
{
    MetalitixLogger->RemoveCustomField("custom");
}


void AExampleMetalitix::SetPollInterval()
{
    MetalitixLogger->SetPollInterval(0.1f);
}
        

void AExampleMetalitix::ShowSurvey()
{
    MetalitixLogger->ShowSurveyPopUp();
}

void AExampleMetalitix::OnEnterPressed()
{
    FJsonObject CustomField;
    CustomField.SetBoolField("BoolTest", true);
    auto Handler = MetalitixLogger->GetEventHandler();
    if(Handler == nullptr)
    {
        FMetalitixDebug::Log(this, "Event sending failed, session did not start!",true);
        return;
    }
    Handler->LogCustomEvent("ReturnDown", CustomField);
}

void AExampleMetalitix::SendCustomEventString(FString MetricName, FString FieldKey, FString Value)
{
    FJsonObject CustomField;
    CustomField.SetStringField(FieldKey, Value);
    auto Handler = MetalitixLogger->GetEventHandler();
    if(Handler == nullptr)
    {
        FMetalitixDebug::Log(this, "Event sending failed, session did not start!",true);
        return;
    }
    Handler->LogCustomEvent(MetricName, CustomField);
}

void AExampleMetalitix::SendCustomEventBool(FString MetricName, FString FieldKey, bool Value)
{
    FJsonObject CustomField;
    CustomField.SetBoolField(FieldKey, Value);
    auto Handler = MetalitixLogger->GetEventHandler();
    if(Handler == nullptr)
    {
        FMetalitixDebug::Log(this, "Event sending failed, session did not start!",true);
        return;
    }
        Handler->LogCustomEvent(MetricName, CustomField);
}
};

Last updated