Getting the Player's Age
Jurisdictional Requirements for Age Collection
To create a new Session
, the first step is to determine whether local regulations require the game to ask the player's date of birth. age-gate/get-requirements
returns whether an age gate is required in the shoudlDisplay
field, as well as other information like what kind of age gate can be shown in the current jurisdiction, the minimum age for the game, the civil age for the current location, and the age of digital consent for the current location.
void UKidWorkflow::GetUserAge(const FString& Location, TFunction<void(bool, bool,
const FString&)> Callback)
{
// uses /age-gate/get-requirements to determine what to do
// - whether to show an age gate
// - what type of age gate is allowed
// - get digitalConsentAge, civilAge and minimumAge
// - whether age assurance is required
// - show the age gate if necessary
// - invoke Callback() with an age, whether
// the age gate was shown and whether age assurance is required
FString Url = BaseUrl + TEXT("/age-gate/get-requirements?jurisdiction=") + Location;
HttpRequestHelper::GetRequestWithAuth(Url, AuthToken,
[this, Location, Callback](FHttpResponsePtr Response, bool bWasSuccessful)
{
if (bWasSuccessful && Response.IsValid())
{
TSharedPtr<FJsonObject> JsonResponse;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonResponse))
{
bool bShouldDisplay = JsonResponse->GetBoolField(TEXT("shouldDisplay"));
bool bAgeAssuranceRequired = JsonResponse->GetBoolField(TEXT("ageAssuranceRequired"));
// Extracting extra information about the jurisdiction.
// Can be used to further customize the age gate.
int32 DigitalConsentAge = JsonResponse->GetIntegerField(TEXT("digitalConsentAge"));
int32 CivilAge = JsonResponse->GetIntegerField(TEXT("civilAge"));
int32 MinimumAge = JsonResponse->GetIntegerField(TEXT("minimumAge"));
// Extracting methods array
const TArray<TSharedPtr<FJsonValue>>& ApprovedAgeCollectionMethods =
JsonResponse->GetArrayField(TEXT("approvedAgeCollectionMethods"));
TSet<FString> Methods;
for (const TSharedPtr<FJsonValue>& Value : ApprovedAgeCollectionMethods)
{
Methods.Add(Value->AsString());
}
if (bShouldDisplay)
{
ShowAgeGate(Methods, [this, DigitalConsentAge, Callback,
bAgeAssuranceRequired](const FString& DOB)
{
// Only verify ages higher than the digital consent age
int32 Age = CalculateAgeFromDOB(DOB);
Callback(true, bAgeAssuranceRequired && Age >= DigitalConsentAge, DOB);
});
}
else
{
Callback(false /* ageGateShown */, false /* ageAssuranceRequired */, TEXT(""));
}
}
}
});
}
If /age-gate/get-requirements
responded with shouldDisplay
= false
, then the no age gate should be shown and the player's date of birth is not defined. In this case, the game will still create a Session
by retrieving default permissions for the jurisdiction by calling /session/get-default-permissions
, which means that permissions do not vary based on age in this jurisdiction. Some features in a game may be prohibited for all age audiences based on jurisdiction, so the game should still consult the Session
permissions to check whether a feature can be enabled.
Showing an Age Gate
If an age gate is required (shouldDisplay
= true
), the age gate UI should be shown, and the user must enter a date of birth to continue.
Certain jurisdictions are specific on whether an age gate can contain a slider, or must request an explicit date of birth. The allowed methods for collecting age are specified in the /approvedAgeCollectionMethods
field.
Handling Age Assurance
If the player enters an age that would be considered an adult or teen, some jurisdictions may require age assurance. In these jurisdictions, the ageAssuranceRequired
field returned from the /age-gate/get-requirements
API will be true
. In this case, after the users enters a date of birth, the game should verify the given age if it is above the age of digital consent for the location. Age estimation can be done using facial scanning or document verification. If age estimation fails, or the age the player gave falls under the lowest value in the estimated age range, then they should be considered the minimum age of the range. The player will either require parental consent, or be blocked altogether depending on the minimum age configured for the game.