AnalyticsET.UserAgentCommentsEnabled

AnalyticsET.UserAgentCommentsEnabled

#Overview

name: AnalyticsET.UserAgentCommentsEnabled

This variable is created as a Console Variable (cvar).

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of AnalyticsET.UserAgentCommentsEnabled is to control whether comments are supported in the analytics user agent string. This setting is primarily used in the analytics system of Unreal Engine 5.

Based on the callsites, this setting variable is mainly used in the Analytics module, specifically in the AnalyticsET (Analytics Event Tracker) subsystem. It’s also referenced in the HTTP module, suggesting that it affects how user agent strings are constructed for network requests.

The value of this variable is set through a console variable (CVarDefaultUserAgentCommentsEnabled) in the AnalyticsProviderETCvars namespace. It’s initialized with a default value of true, meaning comments are enabled by default.

This variable interacts closely with its associated variable CVarDefaultUserAgentCommentsEnabled. They share the same value and purpose, but are used in different contexts - one for analytics and one for general HTTP requests.

Developers should be aware that:

  1. This setting affects both analytics and general HTTP requests.
  2. When disabled, it prevents the inclusion of project-specific and platform-specific comments in user agent strings.
  3. It can be changed at runtime and will affect the behavior immediately.

Best practices when using this variable include:

  1. Consider the privacy implications of including or excluding comments in user agent strings.
  2. Be consistent in its usage across your project to avoid inconsistent behavior.
  3. If you need to include specific information in user agent strings, ensure this setting is enabled.

Regarding the associated variable CVarDefaultUserAgentCommentsEnabled:

The purpose of CVarDefaultUserAgentCommentsEnabled is to control whether comments are included in the default user agent string for HTTP requests.

This variable is used in the HTTP module of Unreal Engine 5, specifically in the GenericPlatformHttp implementation.

Its value is set similarly to AnalyticsET.UserAgentCommentsEnabled, through a console variable, with a default value of true.

It interacts with the FUserAgentImpl class, which builds the user agent string based on this setting.

Developers should be aware that:

  1. This setting affects all HTTP requests made through the engine’s HTTP module.
  2. When disabled, it strips all comments from the user agent string, potentially reducing the amount of information sent with each request.

Best practices include:

  1. Consider the balance between providing useful information in HTTP requests and maintaining user privacy.
  2. Be aware of any compliance requirements that may affect what information you can include in user agent strings.
  3. Coordinate the use of this variable with AnalyticsET.UserAgentCommentsEnabled to ensure consistent behavior across your application.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Analytics/AnalyticsET/Private/IAnalyticsProviderET.cpp:33

Scope (from outer to inner):

file
namespace    AnalyticsProviderETCvars

Source code excerpt:


	TAutoConsoleVariable<bool> CVarDefaultUserAgentCommentsEnabled(
		TEXT("AnalyticsET.UserAgentCommentsEnabled"),
		true,
		TEXT("Whether comments are supported in the analytics user agent string"),
		ECVF_SaveForNextBoot
	);
}

#Associated Variable and Callsites

This variable is associated with another variable named CVarDefaultUserAgentCommentsEnabled. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Analytics/AnalyticsET/Private/IAnalyticsProviderET.cpp:29

Scope (from outer to inner):

file
namespace    AnalyticsProviderETCvars

Source code excerpt:

		TEXT("AnalyticsET.PreventMultipleFlushesInOneFrame"),
		PreventMultipleFlushesInOneFrame,
		TEXT("When true, prevents more than one AnalyticsProviderET instance from flushing in the same frame, allowing the flush and HTTP cost to be amortized.")
	);

	TAutoConsoleVariable<bool> CVarDefaultUserAgentCommentsEnabled(
		TEXT("AnalyticsET.UserAgentCommentsEnabled"),
		true,
		TEXT("Whether comments are supported in the analytics user agent string"),
		ECVF_SaveForNextBoot
	);
}

// Want to avoid putting the project name into the User-Agent, because for some apps (like the editor), the project name is private info.
// The analytics User-Agent uses the default User-Agent, but with project name removed.
class FAnalyticsUserAgentCache
{

#Loc: <Workspace>/Engine/Source/Runtime/Analytics/AnalyticsET/Private/IAnalyticsProviderET.cpp:73

Scope (from outer to inner):

file
class        class FAnalyticsUserAgentCache
function     static TSet<FString> GetAllowedProjectComments

Source code excerpt:

	}

	static TSet<FString> GetAllowedProjectComments()
	{
		TArray<FString> AllowedProjectComments;
		if (AnalyticsProviderETCvars::CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
		{
			GConfig->GetArray(TEXT("Analytics"), TEXT("AllowedUserAgentProjectComments"), AllowedProjectComments, GEngineIni);
		}
		return TSet<FString>(MoveTemp(AllowedProjectComments));
	}

	static TSet<FString> GetAllowedPlatformComments()
	{
		TArray<FString> AllowedPlatformComments;
		if (AnalyticsProviderETCvars::CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
		{
			GConfig->GetArray(TEXT("Analytics"), TEXT("AllowedUserAgentPlatformComments"), AllowedPlatformComments, GEngineIni);
		}
		return TSet<FString>(MoveTemp(AllowedPlatformComments));
	}

	static TSet<FString> ParseCommentSet(const FString& CommentBlob)
	{
		TArray<FString> Comments;
		CommentBlob.ParseIntoArray(Comments, TEXT(";"));
		return TSet<FString>(MoveTemp(Comments));

#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:10

Scope: file

Source code excerpt:

#include "Misc/EngineVersion.h"
#include "Misc/App.h"
#include "Misc/ScopeRWLock.h"
#include "String/BytesToHex.h"

TAutoConsoleVariable<bool> CVarDefaultUserAgentCommentsEnabled(
	TEXT("http.DefaultUserAgentCommentsEnabled"),
	true,
	TEXT("Whether comments are supported in the defualt user agent string"),
	ECVF_SaveForNextBoot
);

namespace
{
	/**
	 * Utility to split stringviews based on a substring.  Returns everything before SplitString as 'Left' and everything after as
	 * 'Right'. If SplitString is not found, OutLeft and OutRight are not modified and the function will return false.

#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:231

Scope (from outer to inner):

file
class        class FUserAgentImpl final
function     FUserAgentImpl

Source code excerpt:

	FUserAgentImpl()
		: RWLock()
		, bCachedCommentsEnabled(false)
	{
		CachedUserAgent = BuildUserAgentString();
		CVarDefaultUserAgentCommentsEnabled->OnChangedDelegate().AddRaw(this, &FUserAgentImpl::OnCommentsEnabledChanged);
	}

	void AddProjectComment(const FString& Comment)
	{
		FRWScopeLock WriteLock(RWLock, SLT_Write);
		Builder.AddProjectComment(Comment);
		CachedUserAgent = BuildUserAgentString();
	}

	void AddPlatformComment(const FString& Comment)
	{

#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:268

Scope (from outer to inner):

file
class        class FUserAgentImpl final
function     FString BuildUserAgentString

Source code excerpt:

	}

private:
	FString BuildUserAgentString()
	{
		if (CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
		{
			return Builder.BuildUserAgentString();
		}
		else
		{
			// Build the user agent string without any comments.
			TSet<FString> AllowedCommentsFilter;
			return Builder.BuildUserAgentString(&AllowedCommentsFilter, &AllowedCommentsFilter);
		}
	}