-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extended attribute types to preserve types when sending data
fixed include path
- Loading branch information
Showing
8 changed files
with
153 additions
and
9 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
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
43 changes: 43 additions & 0 deletions
43
Source/Aptabase/Private/ExtendedAnalyticsBlueprintLibrary.cpp
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,43 @@ | ||
#include "ExtendedAnalyticsBlueprintLibrary.h" | ||
|
||
#include <Analytics.h> | ||
#include <Interfaces/IAnalyticsProvider.h> | ||
|
||
#include "AptabaseAnalyticsProvider.h" | ||
#include "AptabaseLog.h" | ||
#include "ExtendedAnalyticsEventAttribute.h" | ||
|
||
FExtendedAnalyticsEventAttribute UExtendedAnalyticsBlueprintLibrary::MakeExtendedAnalyticsEventStringAttribute(const FString& Name, const FString& Value) | ||
{ | ||
FExtendedAnalyticsEventAttribute Attribute; | ||
Attribute.Key = Name; | ||
Attribute.Value.Set<FString>(Value); | ||
return Attribute; | ||
} | ||
|
||
FExtendedAnalyticsEventAttribute UExtendedAnalyticsBlueprintLibrary::MakeExtendedAnalyticsEventNumberAttribute(const FString& Name, const double Value) | ||
{ | ||
FExtendedAnalyticsEventAttribute Attribute; | ||
Attribute.Key = Name; | ||
Attribute.Value.Set<double>(Value); | ||
return Attribute; | ||
} | ||
|
||
void UExtendedAnalyticsBlueprintLibrary::RecordEventWithAttributes(const FString& EventName, const TArray<FExtendedAnalyticsEventAttribute>& Attributes) | ||
{ | ||
const TSharedPtr<IAnalyticsProvider> Provider = FAnalytics::Get().GetDefaultConfiguredProvider(); | ||
if (!Provider.IsValid()) | ||
{ | ||
UE_LOG(LogAptabase, Warning, TEXT("RecordEventWithAttributes: Failed to get the default analytics provider. Double check your [Analytics] configuration in your INI")); | ||
return; | ||
} | ||
|
||
const TSharedPtr<FAptabaseAnalyticsProvider> AptabaseProvider = StaticCastSharedPtr<FAptabaseAnalyticsProvider>(Provider); | ||
if (!AptabaseProvider.IsValid()) | ||
{ | ||
UE_LOG(LogAptabase, Warning, TEXT("RecordEventWithAttributes: Attributes of type FExtendedAnalyticsEventAttribute only works with Aptabase analytics")); | ||
return; | ||
} | ||
|
||
AptabaseProvider->RecordExtendedEvent(EventName, Attributes); | ||
} |
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 @@ | ||
#include "ExtendedAnalyticsEventAttribute.h" |
32 changes: 32 additions & 0 deletions
32
Source/Aptabase/Public/ExtendedAnalyticsBlueprintLibrary.h
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,32 @@ | ||
#pragma once | ||
|
||
#include <CoreMinimal.h> | ||
#include <Kismet/BlueprintFunctionLibrary.h> | ||
|
||
#include "ExtendedAnalyticsBlueprintLibrary.generated.h" | ||
|
||
/** | ||
* A C++ and Blueprint accessible library of utility functions for extended analytics tracking | ||
*/ | ||
UCLASS() | ||
class APTABASE_API UExtendedAnalyticsBlueprintLibrary : public UBlueprintFunctionLibrary | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
/** | ||
* Creates and ExtendedAnalyticsEventAttribute with a name and a string value | ||
*/ | ||
UFUNCTION(BlueprintPure, Category = "Analytics") | ||
static FExtendedAnalyticsEventAttribute MakeExtendedAnalyticsEventStringAttribute(const FString& Name, const FString& Value); | ||
/** | ||
* Creates and ExtendedAnalyticsEventAttribute with a name and a number (double) value | ||
*/ | ||
UFUNCTION(BlueprintPure, Category = "Analytics") | ||
static FExtendedAnalyticsEventAttribute MakeExtendedAnalyticsEventNumberAttribute(const FString& Name, const double Value); | ||
/** | ||
* Records an event has happened by name with an array of ExtendedAttributes (preserve native type) | ||
*/ | ||
UFUNCTION(BlueprintCallable, Category = "Analytics") | ||
static void RecordEventWithAttributes(const FString& EventName, const TArray<FExtendedAnalyticsEventAttribute>& Attributes); | ||
}; |
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,27 @@ | ||
#pragma once | ||
|
||
#include <Misc/TVariant.h> | ||
|
||
#include "ExtendedAnalyticsEventAttribute.generated.h" | ||
|
||
/** | ||
* Struct to hold type specific data for analytics events. | ||
* @note similar to FAnalyticsEventAttribute::AttrTypeEnum leveraging the TVariant type | ||
* @note properties are not blueprint exposed because TVariant is not blueprint friendly | ||
*/ | ||
USTRUCT(BlueprintType) | ||
struct FExtendedAnalyticsEventAttribute | ||
{ | ||
GENERATED_BODY(); | ||
|
||
/** | ||
* Name of the Attribute | ||
*/ | ||
FString Key; | ||
|
||
/** | ||
* Value of the Attribute | ||
* @note we can support more types but they need to be converted to the correct JSON type before sending | ||
*/ | ||
TVariant<FString, double> Value; | ||
}; |