-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "ImmutableAnalytics.h" | ||
|
||
#include "JsonDomBuilder.h" | ||
|
||
#define EVENT_DATA_SUCCESS "succeeded" | ||
|
||
|
||
void UImmutableAnalytics::Track(EEventName EventName) | ||
{ | ||
check(JSConnector.IsValid()); | ||
|
||
FString FullData; | ||
|
||
FJsonObjectConverter::UStructToJsonObjectString<FEventData>({ "unrealSdk", GetEventName(EventName), "" }, FullData); | ||
|
||
JSConnector->CallJS(ImmutablePassportAction::TRACK, FullData, FImtblJSResponseDelegate::CreateUObject(this, &UImmutableAnalytics::OnTrackResponse)); | ||
} | ||
|
||
void UImmutableAnalytics::Track(EEventName EventName, bool Success) | ||
{ | ||
TMap<FString, FString> EventData = {{EVENT_DATA_SUCCESS, Success ? TEXT("true") : TEXT("false") } }; | ||
Track(EventName, EventData); | ||
} | ||
|
||
void UImmutableAnalytics::Track(EEventName EventName, TMap<FString, FString>& EventData) | ||
{ | ||
check(JSConnector.IsValid()); | ||
|
||
FJsonDomBuilder::FObject Object; | ||
|
||
for (auto data : EventData) | ||
{ | ||
Object.Set(data.Key, data.Value); | ||
} | ||
|
||
FString FullData; | ||
|
||
FJsonObjectConverter::UStructToJsonObjectString<FEventData>({ "unrealSdk", GetEventName(EventName), Object.ToString() }, FullData); | ||
|
||
JSConnector->CallJS(ImmutablePassportAction::TRACK, FullData, FImtblJSResponseDelegate::CreateUObject(this, &UImmutableAnalytics::OnTrackResponse)); | ||
} | ||
|
||
void UImmutableAnalytics::Setup(TWeakObjectPtr<UImtblJSConnector> Connector) | ||
{ | ||
IMTBL_LOG_FUNCSIG | ||
|
||
if (!Connector.IsValid()) | ||
{ | ||
IMTBL_ERR("Invalid JSConnector passed to UImmutableAnalytics::Setup.") | ||
return; | ||
} | ||
|
||
JSConnector = Connector.Get(); | ||
} | ||
|
||
void UImmutableAnalytics::OnTrackResponse(FImtblJSResponse Response) | ||
{ | ||
// Currently, we ignore tracking errors. Edit if it is required | ||
} | ||
|
||
FString UImmutableAnalytics::GetEventName(EEventName EventName) | ||
{ | ||
switch(EventName) | ||
{ | ||
#define CONVERT(EventName, EventNameString) case EEventName::EventName: return EventNameString; | ||
EVENT_NAME_LIST | ||
#undef CONVERT | ||
default: | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#pragma once | ||
|
||
#include "Immutable/ImmutablePassport.h" | ||
|
||
#include "ImmutableAnalytics.generated.h" | ||
|
||
USTRUCT(BlueprintType) | ||
struct FEventData | ||
{ | ||
GENERATED_BODY() | ||
|
||
UPROPERTY() | ||
FString moduleName; | ||
|
||
UPROPERTY() | ||
FString eventName; | ||
|
||
UPROPERTY() | ||
FString properties; | ||
}; | ||
|
||
/** | ||
* Immutable bridge sdk analytics utility | ||
*/ | ||
UCLASS() | ||
class IMMUTABLE_API UImmutableAnalytics : public UObject | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
|
||
/** | ||
* Event names to track | ||
*/ | ||
#define EVENT_NAME_LIST \ | ||
CONVERT(INIT_PASSPORT, "initialisedPassport") \ | ||
CONVERT(START_LOGIN, "startedLogin") \ | ||
CONVERT(COMPLETE_LOGIN, "performedLogin") \ | ||
CONVERT(START_LOGIN_PKCE, "startedLoginPkce") \ | ||
CONVERT(COMPLETE_LOGIN_PKCE, "performedLoginPkce") \ | ||
CONVERT(COMPLETE_RELOGIN, "performedRelogin") \ | ||
CONVERT(START_CONNECT_IMX, "startedConnectImx") \ | ||
CONVERT(COMPLETE_CONNECT_IMX, "performedConnectImx") \ | ||
CONVERT(START_CONNECT_IMX_PKCE, "startedConnectImxPkce") \ | ||
CONVERT(COMPLETE_CONNECT_IMX_PKCE, "performedConnectImxPkce") \ | ||
CONVERT(COMPLETE_RECONNECT, "performedReconnect") \ | ||
CONVERT(COMPLETE_LOGOUT, "performedLogout") \ | ||
CONVERT(COMPLETE_LOGOUT_PKCE, "performedLogoutPkce") | ||
|
||
enum class EEventName: uint8 | ||
{ | ||
#define CONVERT(name, nameString) name, | ||
EVENT_NAME_LIST | ||
#undef CONVERT | ||
}; | ||
|
||
public: | ||
void Setup(TWeakObjectPtr<class UImtblJSConnector> Connector); | ||
/** | ||
* Performs the call to game bridge track method | ||
* @param EventName Name that will be tracked | ||
* @param Success Single event data record that track "succeeded" field | ||
* @param EventData Map with customed data, converted to json object | ||
*/ | ||
void Track(EEventName EventName); | ||
void Track(EEventName EventName, bool Success); | ||
void Track(EEventName EventName, TMap<FString, FString>& EventData); | ||
|
||
private: | ||
// Convert enum to string | ||
FString GetEventName(EEventName EventName); | ||
// Callback method for Track from bridge | ||
void OnTrackResponse(FImtblJSResponse Response); | ||
|
||
private: | ||
TWeakObjectPtr<class UImtblJSConnector> JSConnector; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters