UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnalyticsEventAttribute.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7
9{
10};
11
13{
14 return TEXT("null");
15}
16
25
26inline const TCHAR* LexToString(const FJsonFragment& Fragment)
27{
28 if (Fragment.FragmentString.IsEmpty())
29 return LexToString(FJsonNull{});
30 return *Fragment.FragmentString;
31}
32
33inline FString LexToString(FJsonFragment&& Fragment)
34{
35 if (Fragment.FragmentString.IsEmpty())
36 return LexToString(FJsonNull{});
37 return MoveTemp(Fragment.FragmentString);
38}
39
40
41
48{
49 UE_DEPRECATED(4.26, "This property has been deprecated, use GetName() instead")
50 const FString AttrName;
51
52 UE_DEPRECATED(4.26, "This property has been deprecated, use GetValue() instead")
53 const FString AttrValueString;
54 UE_DEPRECATED(4.26, "This property has been deprecated, use GetValue() instead. You cannot recover the original non-string value anymore")
55 const double AttrValueNumber;
56 UE_DEPRECATED(4.26, "This property has been deprecated, use GetValue() instead. You cannot recover the original non-string value anymore")
57 const bool AttrValueBool;
58
60 {
61 String,
62 Number,
63 Boolean,
64 Null,
66 };
67 UE_DEPRECATED(4.26, "This property has been deprecated, use IsJsonFragment or GetValue instead")
69
70 template <typename ValueType>
71 FAnalyticsEventAttribute(FString InName, ValueType&& InValue);
72
73 const FString& GetName() const;
74 const FString& GetValue() const;
75 bool IsJsonFragment() const;
76
78 template<typename ValueType>
79 void SetValue(ValueType&& InValue);
80
84
87
90
93
96
99
102
104 UE_DEPRECATED(4.26, "This property has been deprecated, use GetValue() instead")
105 FString ToString() const;
106
108 UE_DEPRECATED(4.26, "This property is used to support the deprecated APIs, construct Json values using FJsonFragment instead")
110
111 static bool IsValidAttributeName(const FString& InName)
112 {
113 return !InName.IsEmpty() && InName != TEXT("EventName") && InName != TEXT("DateOffset");
114 }
115
116private:
117 FString& CheckName(FString& InName)
118 {
119 // These are reserved names in our environment. Enforce things don't use it.
121 return InName;
122 }
123};
124
125
126// The implementation of this class references deprecated members. Don't fire warnings for these.
127// For this reason we actually implement the entire class out-of-line, but still in the header files, so we can wrap
128// all the implementations in DISABLE macro easily.
130
132: AttrName()
133, AttrValueString()
134, AttrValueNumber(0)
135, AttrValueBool(false)
136, AttrType(AttrTypeEnum::String)
137{
138
139}
140
142
144
146, AttrValueString(MoveTemp(const_cast<FString&>(RHS.AttrValueString)))
147// no need to use MoveTemp on intrinsic types.
148, AttrValueNumber(RHS.AttrValueNumber)
149, AttrValueBool(RHS.AttrValueBool)
150, AttrType(RHS.AttrType)
151{
152
153}
154
155template <typename ValueType>
157: AttrName(MoveTemp(CheckName(InName)))
158, AttrValueString(AnalyticsConversionToString(Forward<ValueType>(InValue)))
159, AttrValueNumber(0)
160, AttrValueBool(false)
161, AttrType(TIsArithmetic<typename TDecay<ValueType>::Type>::Value || std::is_same_v<typename TDecay<ValueType>::Type, FJsonNull> || std::is_same_v<typename TDecay<ValueType>::Type, FJsonFragment> ? AttrTypeEnum::JsonFragment : AttrTypeEnum::String)
162{
163
164}
165
166
168{
169 if (&RHS == this)
170 {
171 return *this;
172 }
173
174 const_cast<FString&>(AttrName) = RHS.AttrName;
175 const_cast<FString&>(AttrValueString) = RHS.AttrValueString;
176 const_cast<double&>(AttrValueNumber) = RHS.AttrValueNumber;
177 const_cast<bool&>(AttrValueBool) = RHS.AttrValueBool;
178 const_cast<AttrTypeEnum&>(AttrType) = RHS.AttrType;
179 return *this;
180}
181
186
188{
189 if (&RHS == this)
190 {
191 return *this;
192 }
193
194 const_cast<double&>(AttrValueNumber) += RHS.AttrValueNumber;
195 return *this;
196}
197
199{
200 if (&RHS == this)
201 {
202 return *this;
203 }
204
205 const_cast<FString&>(AttrName) = MoveTemp(const_cast<FString&>(RHS.AttrName));
206 const_cast<FString&>(AttrValueString) = MoveTemp(const_cast<FString&>(RHS.AttrValueString));
207 // no need to use MoveTemp on intrinsic types.
208 const_cast<double&>(AttrValueNumber) = RHS.AttrValueNumber;
209 const_cast<bool&>(AttrValueBool) = RHS.AttrValueBool;
210 const_cast<AttrTypeEnum&>(AttrType) = RHS.AttrType;
211 return *this;
212}
213
215{
216 return GetValue();
217}
218
219inline const FString& FAnalyticsEventAttribute::GetName() const
220{
221 return AttrName;
222}
223
224inline const FString& FAnalyticsEventAttribute::GetValue() const
225{
226 return AttrValueString;
227}
228
233
234template<typename ValueType>
240
245
247
250{
251 // AddElement actually adds an element to the attributes array and is flagged no-inline so the array insert/value conversion
252 // code is generated once per type combination.
253 template <typename Allocator, typename KeyType, typename ValueType>
255 {
256 static_assert(std::is_convertible_v<KeyType, FString>, "Keys must be convertible to `FString`!");
257 Attrs.Emplace(FString{Key}, Value);
258 }
259
260 template <typename Allocator>
264
265 // MakeArray is just a helper whose only purpose is to generate a sequence of AddElement calls and is meant to be always inlined.
266 template <typename Allocator, typename KeyType, typename ValueType, typename... RemainingArgTypes>
268 {
269 static_assert(sizeof...(RemainingArgs) % 2 == 0, "Must pass an even number of arguments.");
270
271 // Decay here to decay string literals into const char*/const TCHAR* (losing the information about their length)
272 // to limit the number of unique instantiations of AddElement.
275 }
276}
277
279template <typename Allocator = FDefaultAllocator, typename...ArgTypes>
287
289template <typename Allocator = FDefaultAllocator, typename...ArgTypes>
decltype(auto) AnalyticsConversionToString(const T &Value)
Definition AnalyticsConversion.h:11
const TCHAR * LexToString(FJsonNull)
Definition AnalyticsEventAttribute.h:12
TArray< FAnalyticsEventAttribute, Allocator > MakeAnalyticsEventAttributeArray(ArgTypes &&...Args)
Definition AnalyticsEventAttribute.h:280
TArray< FAnalyticsEventAttribute, Allocator > & AppendAnalyticsEventAttributeArray(TArray< FAnalyticsEventAttribute, Allocator > &Attrs, ArgTypes &&...Args)
Definition AnalyticsEventAttribute.h:290
EGLSurface EGLint const EGLint EGLnsecsANDROID * values
Definition AndroidOpenGLFunctions.h:11
#define FORCENOINLINE
Definition AndroidPlatform.h:142
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
TSizedDefaultAllocator< 32 > FDefaultAllocator
Definition ContainerAllocationPolicies.h:831
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition UnrealType.h:3087
Definition Array.h:670
void Empty(SizeType Slack=0)
Definition Array.h:2273
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition AnalyticsEventAttribute.h:250
FORCEINLINE void MakeArray(TArray< FAnalyticsEventAttribute, Allocator > &Attrs)
Definition AnalyticsEventAttribute.h:261
@ false
Definition radaudio_common.h:23
Definition AnalyticsEventAttribute.h:48
FAnalyticsEventAttribute()
Definition AnalyticsEventAttribute.h:131
const FString AttrName
Definition AnalyticsEventAttribute.h:50
const FString & GetValue() const
Definition AnalyticsEventAttribute.h:224
FString ToString() const
Definition AnalyticsEventAttribute.h:214
FAnalyticsEventAttribute & operator=(const FAnalyticsEventAttribute &RHS)
Definition AnalyticsEventAttribute.h:167
FAnalyticsEventAttribute & operator+(const FAnalyticsEventAttribute &RHS)
Definition AnalyticsEventAttribute.h:187
AttrTypeEnum
Definition AnalyticsEventAttribute.h:60
void SetValue(ValueType &&InValue)
Definition AnalyticsEventAttribute.h:235
const AttrTypeEnum AttrType
Definition AnalyticsEventAttribute.h:68
const double AttrValueNumber
Definition AnalyticsEventAttribute.h:55
const bool AttrValueBool
Definition AnalyticsEventAttribute.h:57
const FString & GetName() const
Definition AnalyticsEventAttribute.h:219
static bool IsValidAttributeName(const FString &InName)
Definition AnalyticsEventAttribute.h:111
FAnalyticsEventAttribute & operator+=(const FAnalyticsEventAttribute &RHS)
Definition AnalyticsEventAttribute.h:182
bool IsJsonFragment() const
Definition AnalyticsEventAttribute.h:229
const FString AttrValueString
Definition AnalyticsEventAttribute.h:53
void SwitchToJsonFragment()
Definition AnalyticsEventAttribute.h:241
Definition AnalyticsEventAttribute.h:18
FString FragmentString
Definition AnalyticsEventAttribute.h:23
FJsonFragment(FString &&StringRef)
Definition AnalyticsEventAttribute.h:22
Definition AnalyticsEventAttribute.h:9
Definition Decay.h:44
UE::Core::Private::Decay::TDecayNonReference< typenameTRemoveReference< T >::Type >::Type Type
Definition Decay.h:45
Definition IsArithmetic.h:12