Skip to content

Commit 58ebbe1

Browse files
committed
fix: Initial Unreal 5 support
1 parent b5e4b65 commit 58ebbe1

38 files changed

+1461
-30
lines changed

Amplitude.uplugin

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
"Name": "Amplitude",
2525
"Type": "Runtime",
2626
"LoadingPhase": "PreDefault",
27-
"WhitelistPlatforms": [
27+
"SupportedTargetPlatforms": [
2828
"IOS",
29-
"Mac"
29+
"Mac",
30+
"TVOS"
3031
]
3132
}
3233
]

Source/Amplitude/Amplitude.Build.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
using UnrealBuildTool;
22
using System.IO;
33
using System;
4-
using Tools.DotNETCommon;
54

65
public class Amplitude : ModuleRules
76
{
87
public Amplitude(ReadOnlyTargetRules Target) : base(Target)
98
{
9+
// UE5 compatibility settings
1010
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
11+
// CppStandard = CppStandardVersion.Cpp20;
12+
1113
string ThirdPartyPath = Path.GetFullPath(Path.Combine(ModuleDirectory, "../ThirdParty"));
1214
PublicDefinitions.Add("WITH_AMPLITUDE=1");
15+
1316
if (Target.Platform == UnrealTargetPlatform.Mac)
1417
{
1518
PrivateDependencyModuleNames.Add("AmplitudeMacOS");
@@ -34,8 +37,7 @@ public Amplitude(ReadOnlyTargetRules Target) : base(Target)
3437
"CoreUObject",
3538
"Engine",
3639
}
37-
);
38-
40+
);
3941

4042
PrivateDependencyModuleNames.AddRange(
4143
new string[]

Source/Amplitude/Private/AmplitudeProvider.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "Containers/UnrealString.h"
3+
#include "CoreMinimal.h"
44
#include "Interfaces/IAnalyticsProvider.h"
55
#include <string>
66

@@ -50,4 +50,13 @@ class FAmplitudeProvider : public IAnalyticsProvider
5050
void SetLocation(const FString &InLocation) override;
5151
void SetGender(const FString &InGender) override;
5252
void SetAge(const int32 InAge) override;
53-
};
53+
54+
virtual void SetDefaultEventAttributes(TArray<FAnalyticsEventAttribute>&& Attributes) override;
55+
virtual TArray<FAnalyticsEventAttribute> GetDefaultEventAttributesSafe() const override;
56+
virtual int32 GetDefaultEventAttributeCount() const override;
57+
virtual FAnalyticsEventAttribute GetDefaultEventAttribute(int AttributeIndex) const override;
58+
59+
private:
60+
/** Array of default event attributes */
61+
TArray<FAnalyticsEventAttribute> DefaultEventAttributes;
62+
};

Source/Amplitude/Private/AmplitudeUnreal.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "AmplitudeUnreal.h"
22
#include "AmplitudeProvider.h"
33
#include "Analytics.h"
4-
#include <exception>
54
#if PLATFORM_APPLE
65
#include "AmplitudeiOSBridge.h"
76
#endif
@@ -63,11 +62,22 @@ void FAmplitudeProvider::RecordEvent(const FString &EventName, const TArray<FAna
6362
{
6463
std::string ConvertedEventName = std::string(TCHAR_TO_UTF8(*EventName));
6564
std::vector<std::pair<std::string, std::string>> propertyPairs;
66-
for (FAnalyticsEventAttribute Attribute : Attributes)
65+
66+
// Add default attributes first
67+
for (const FAnalyticsEventAttribute& DefaultAttribute : DefaultEventAttributes)
6768
{
6869
std::pair<std::string, std::string> propertyPair;
69-
propertyPair.first = std::string(TCHAR_TO_UTF8(*Attribute.AttrName));
70-
propertyPair.second = std::string(TCHAR_TO_UTF8(*Attribute.AttrValueString));
70+
propertyPair.first = std::string(TCHAR_TO_UTF8(*DefaultAttribute.GetName()));
71+
propertyPair.second = std::string(TCHAR_TO_UTF8(*DefaultAttribute.GetValue()));
72+
propertyPairs.push_back(propertyPair);
73+
}
74+
75+
// Add event-specific attributes
76+
for (const FAnalyticsEventAttribute& Attribute : Attributes)
77+
{
78+
std::pair<std::string, std::string> propertyPair;
79+
propertyPair.first = std::string(TCHAR_TO_UTF8(*Attribute.GetName()));
80+
propertyPair.second = std::string(TCHAR_TO_UTF8(*Attribute.GetValue()));
7181
propertyPairs.push_back(propertyPair);
7282
}
7383

@@ -85,23 +95,25 @@ FString FAmplitudeProvider::GetSessionID() const
8595
FString SessionId = FString::SanitizeFloat(Bridge.getSessionId());
8696
return SessionId;
8797
#endif
98+
return TEXT("-1");
8899
}
89100

90101
bool FAmplitudeProvider::SetSessionID(const FString &InSessionID)
91102
{
92-
try
103+
// Use Unreal's string conversion instead of std::stoi to avoid exceptions
104+
if (InSessionID.IsNumeric())
93105
{
94106
#if PLATFORM_APPLE
95107
ios_bridge::AmplitudeiOSBridge Bridge;
96-
long ConvertedSessionId = std::stoi(std::string(TCHAR_TO_UTF8(*InSessionID)));
108+
long ConvertedSessionId = FCString::Atoi64(*InSessionID);
97109
Bridge.setSessionId(ConvertedSessionId);
98110
#endif
99111
return true;
100112
}
101-
catch (std::exception &e)
102-
{
103-
return false;
104-
}
113+
114+
// Log error and return false if the session ID is not numeric
115+
UE_LOG(LogAnalytics, Warning, TEXT("SetSessionID failed: Invalid session ID format: %s"), *InSessionID);
116+
return false;
105117
}
106118

107119
void FAmplitudeProvider::FlushEvents()
@@ -156,3 +168,23 @@ void FAmplitudeProvider::SetAge(const int32 InAge)
156168
{
157169
SetUserProperty(TEXT("Age"), FString::FromInt(InAge));
158170
}
171+
172+
void FAmplitudeProvider::SetDefaultEventAttributes(TArray<FAnalyticsEventAttribute>&& Attributes)
173+
{
174+
DefaultEventAttributes = MoveTemp(Attributes);
175+
}
176+
177+
TArray<FAnalyticsEventAttribute> FAmplitudeProvider::GetDefaultEventAttributesSafe() const
178+
{
179+
return DefaultEventAttributes;
180+
}
181+
182+
int32 FAmplitudeProvider::GetDefaultEventAttributeCount() const
183+
{
184+
return DefaultEventAttributes.Num();
185+
}
186+
187+
FAnalyticsEventAttribute FAmplitudeProvider::GetDefaultEventAttribute(int AttributeIndex) const
188+
{
189+
return DefaultEventAttributes[AttributeIndex];
190+
}

Source/AmplitudeEditor/AmplitudeEditor.Build.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
using UnrealBuildTool;
44
using System.IO;
55
using System;
6-
using Tools.DotNETCommon;
76

87
public class AmplitudeEditor : ModuleRules
98
{
109
public AmplitudeEditor(ReadOnlyTargetRules Target) : base(Target)
1110
{
12-
// PrivateIncludePaths.Add("AmplitudeEditor/Private");
11+
// UE5 compatibility settings
12+
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
13+
// CppStandard = CppStandardVersion.Cpp20;
14+
15+
// Include paths
1316
PrivateIncludePaths.Add(Path.GetFullPath(Path.Combine(ModuleDirectory, "Private")));
1417
PrivateIncludePaths.Add(Path.GetFullPath(Path.Combine(ModuleDirectory, "Public")));
1518
PublicIncludePaths.Add(Path.GetFullPath(Path.Combine(ModuleDirectory, "Public")));
@@ -21,9 +24,16 @@ public AmplitudeEditor(ReadOnlyTargetRules Target) : base(Target)
2124
"Analytics",
2225
"AnalyticsVisualEditing",
2326
"Engine",
24-
"Projects"
27+
"Projects",
28+
"Slate",
29+
"SlateCore",
30+
"EditorStyle",
31+
"EditorWidgets",
32+
"UnrealEd",
33+
"WorkspaceMenuStructure",
34+
"DeveloperSettings"
2535
}
26-
);
36+
);
2737

2838
PrivateIncludePathModuleNames.AddRange(
2939
new string[] {

Source/AmplitudeIOS/AmplitudeIOS/AmplitudeIOS.Build.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,23 @@ public class AmplitudeIOS : ModuleRules
88
public AmplitudeIOS(ReadOnlyTargetRules Target) : base(Target)
99
{
1010
Type = ModuleType.External;
11-
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "include"));
12-
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "arm64", "Amplitude_iOS_Unreal.a"));
11+
12+
// UE5 compatibility settings
13+
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
14+
// CppStandard = CppStandardVersion.Cpp20;
15+
16+
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "include"));
17+
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "arm64", "Amplitude_iOS_Unreal.a"));
18+
PublicDefinitions.Add("AMPLITUDE_USE_PREFIXED_SERVERZONE=1");
19+
20+
// iOS specific framework dependencies
21+
if (Target.Platform == UnrealTargetPlatform.IOS)
22+
{
23+
PublicFrameworks.AddRange(new string[]
24+
{
25+
"Foundation",
26+
"SystemConfiguration"
27+
});
28+
}
1329
}
1430
}
-1.42 MB
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// AMPDefaultTrackingOptions.h
3+
// Copyright (c) 2023 Amplitude Inc. (https://amplitude.com/)
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
//
23+
24+
#import <Foundation/Foundation.h>
25+
26+
#ifndef AMPDefaultTrackingOptions_h
27+
#define AMPDefaultTrackingOptions_h
28+
29+
@interface AMPDefaultTrackingOptions : NSObject
30+
31+
/**
32+
Enables/disables session tracking. Default to disabled.
33+
*/
34+
@property (nonatomic, assign) BOOL sessions;
35+
36+
/**
37+
Enables/disables app lifecycle events tracking. Default to disabled.
38+
*/
39+
@property (nonatomic, assign) BOOL appLifecycles;
40+
41+
/**
42+
Enables/disables deep link events tracking. Default to disabled.
43+
*/
44+
@property (nonatomic, assign) BOOL deepLinks;
45+
46+
/**
47+
Enables/disables screen view events tracking. Default to disabled.
48+
*/
49+
@property (nonatomic, assign) BOOL screenViews;
50+
51+
- (instancetype)init;
52+
+ (instancetype)initWithSessions:(BOOL)sessions
53+
appLifecycles:(BOOL)appLifecycles
54+
deepLinks:(BOOL)deepLinks
55+
screenViews:(BOOL)screenViews;
56+
+ (instancetype)initWithAllEnabled;
57+
+ (instancetype)initWithNoneEnabled;
58+
59+
@end
60+
61+
#endif /* AMPDefaultTrackingOptions_h */

Source/AmplitudeIOS/AmplitudeIOS/include/AMPIdentify.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,45 @@
152152
*/
153153
- (AMPIdentify *)unset:(NSString *)property;
154154

155+
156+
/**
157+
Pre-insert the value of a given user property. If the value already exists, it will do no operation.
158+
159+
@param property The user property key
160+
161+
@param value A value or values to set.
162+
163+
@returns the same [AMPIdentify](#) object, allowing you to chain multiple method calls together.
164+
165+
@see [User Properties and User Property Operations](https://github.com/amplitude/amplitude-ios#user-properties-and-user-property-operations)
166+
*/
167+
- (AMPIdentify *)preInsert:(NSString *)property value:(NSObject *)value;
168+
169+
170+
/**
171+
Post-insert the value of a given user property. If the value already exists, it will do no operation.
172+
173+
@param property The user property key
174+
175+
@param value A value or values to set.
176+
177+
@returns the same [AMPIdentify](#) object, allowing you to chain multiple method calls together.
178+
179+
@see [User Properties and User Property Operations](https://github.com/amplitude/amplitude-ios#user-properties-and-user-property-operations)
180+
*/
181+
- (AMPIdentify *)postInsert:(NSString *)property value:(NSObject *)value;
182+
183+
184+
/**
185+
Remove the value of a given user property, if the value exists. If the value doesn't exsit, it will do no opearation.
186+
187+
@param property The user property key
188+
189+
@param value A value or values to set.
190+
191+
@returns the same [AMPIdentify](#) object, allowing you to chain multiple method calls together.
192+
193+
@see [User Properties and User Property Operations](https://github.com/amplitude/amplitude-ios#user-properties-and-user-property-operations)
194+
*/
195+
- (AMPIdentify *)remove:(NSString *)property value:(NSObject *)value;
155196
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// AMPIngestionMetadata.h
3+
// Copyright (c) 2022 Amplitude Inc. (https://amplitude.com/)
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
//
23+
#import <Foundation/Foundation.h>
24+
25+
@interface AMPIngestionMetadata : NSObject
26+
27+
@property (nonatomic, strong, readonly) NSString *sourceName;
28+
29+
@property (nonatomic, strong, readonly) NSString *sourceVersion;
30+
31+
+ (instancetype)ingestionMetadata;
32+
33+
- (AMPIngestionMetadata *)setSourceName:(NSString *)sourceName;
34+
35+
- (AMPIngestionMetadata *)setSourceVersion:(NSString *)sourceVersion;
36+
37+
- (NSDictionary *)toNSDictionary;
38+
39+
@end

0 commit comments

Comments
 (0)