Integrate Legal Documents into Game Client using SDK
Overview
This guide explains how to integrate legal documents in AccelByte Gaming Services (AGS) by utilizing the AccelByte Legal Agreement API through the functions in AccelByte::Api::Agreement
within your game client.
Check player eligibilities
To check if players from a specific namespace has agreed to a legal agreement, use this function:
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->QueryLegalEligibilities(
// Specified namespace
,
THandler < TArray < FAccelByteModelsRetrieveUserEligibilitiesResponse >> ::
CreateLambda(
[](TArray < FAccelByteModelsRetrieveUserElegibilitiesResponse > Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().QueryLegalEligibilities(eligibilitiesResult =>
{
if (eligibilitiesResult.IsError)
{
// Do something if Query Legal Eligibilities has an error
Debug.Log($"Query Legal Eligibility failed : {eligibilitiesResult.Error.Code} Description : {eligibilitiesResult.Error.Message}");
return;
}
bool isEligible = true;
foreach(var eligibility in eligibilitiesResult.Value)
{
if (!eligibility.isAccepted)
{
isEligible = false;
break;
}
}
if (isEligible)
{
Debug.Log($"Query Legal Eligibility Success");
}
else
{
Debug.Log($"Contains player who don't accept legal eligibility");
}
});
Retrieve legal document content
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->GetLegalDocument(
// Specified URL
,
THandler < FString > ::CreateLambda([](FString Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
Result <string> docResult = null;
String localizedPolicyUrl = policyVersion.localizedPolicyVersions[0].attachmentLocation; // From GetLegalPolicies Result
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().GetLegalDocument(localizedPolicyUrl, docResult =>
{
if (docResult.IsError)
{
// Do something if failed
Debug.Log($"Get Legal Document failed : {docResult.Error.Code} Description : {docResult.Error.Message}");
return;
}
// Do something when successful
});
Retrieve legal document policies
This section outlines all the available functions for retrieving document policies based on specific criteria.
Retrieve all latest active policies
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->GetLegalPolicies(
// Specified policy type
,
// Default on empty flag
,
THandler < TArray < FAccelByteModelsPublicPolicy >> ::
CreateLambda([](TArray < FAccelByteModelsPublicPolicy > Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().GetLegalPolicies(AgreementPolicyType.EMPTY, false, publicPoliciesResult =>
{
if (publicPoliciesResult.IsError)
{
// Do something if failed
Debug.Log($"Get Legal Policies failed : {publicPoliciesResult.Error.Code} Description : {publicPoliciesResult.Error.Message}");
return;
}
// Do something when successful
});
Retrieve list of policies by namespace
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->GetLegalPolicies(
// Specified namespace
,
// Specified policy type
,
// Default on empty flag
,
THandler < TArray < FAccelByteModelsPublicPolicy >> ::
CreateLambda([](TArray < FAccelByteModelsPublicPolicy > Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
// Namespace is already stored on Config file
string[] tags = new string[] {
"game",
"NDA"
};
bool defaultOnEmpty = true; // Will get default country when no localized policy is set for your country
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().GetLegalPolicies(AgreementPolicyType.EMPTY, tags, defaultOnEmpty, publicPoliciesResult =>
{
if (publicPoliciesResult.IsError)
{
// Do something if failed
Debug.Log($"Get Legal Policies failed : {publicPoliciesResult.Error.Code} Description : {publicPoliciesResult.Error.Message}");
return;
}
// Do something when successful
foreach(var publicPolicy in publicPoliciesResult.Value)
{
Debug.Log("PolicyName: " + publicPolicy.policyName + " | Description: " + publicPolicy.description);
foreach(var policyVersion in publicPolicy.policyVersions)
{
Debug.Log("PolicyVersion: " + policyVersion.displayVersion + " | LocalizedPolicyUrl: " + policyVersion.localizedPolicyVersions[0].attachmentLocation);
}
}
});
Retrieve list of policies by tag
Retrieve all latest active policies that have specified tags based on the namespace from game configuration and country code from the user's profile.
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->GetLegalPolicies(
// Specified policy type
,
// List of tags
,
// Default on empty flag
,
THandler < TArray < FAccelByteModelsPublicPolicy >> ::
CreateLambda([](TArray < FAccelByteModelsPublicPolicy > Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
string[] tags = new string[2] {
"beta",
"newsletter"
};
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().GetLegalPolicies(AgreementPolicyType.EMPTY, tags, false, publicPoliciesResult =>
{
if (publicPoliciesResult.IsError)
{
// Do something if failed
Debug.Log($"Get Legal Policies failed : {publicPoliciesResult.Error.Code} Description : {publicPoliciesResult.Error.Message}");
return;
}
// Do something when successful
});
Retrieve list of policies by country
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->GetLegalPolicies(
// Specified country code
,
// Specified policy type
,
// Default on empty flag
,
THandler < TArray < FAccelByteModelsPublicPolicy >> ::
CreateLambda([](TArray < FAccelByteModelsPublicPolicy > Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
string countryCode = "US"; // You can get the country code from eligibilities return
string[] tags = new string[] {
"game",
"NDA"
};
bool defaultOnEmpty = true; // Will get default country when no localized policy for your country
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().GetLegalPoliciesByCountry(countryCode, AgreementPolicyType.EMPTY, tags, defaultOnEmpty, publicPoliciesResult =>
{
if (publicPoliciesResult.IsError)
{
// Do something if failed
Debug.Log($"Get Legal Policies failed : {publicPoliciesResult.Error.Code} Description : {publicPoliciesResult.Error.Message}");
return;
}
// Do something when successful
foreach(var publicPolicy in publicPoliciesResult.Value)
{
Debug.Log("PolicyName: " + publicPolicy.policyName + " | Description: " + publicPolicy.description);
foreach(var policyVersion in publicPolicy.policyVersions)
{
Debug.Log("PolicyVersion: " + policyVersion.displayVersion + " | LocalizedPolicyUrl: " + policyVersion.localizedPolicyVersions[0].attachmentLocation);
}
}
});
Retrieve list of policies by country and tag
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->GetLegalPolicies(
// Specified country code
,
// Specified policy type
,
// List of tags
,
// Default on empty flag
,
THandler < TArray < FAccelByteModelsPublicPolicy >> ::
CreateLambda([](TArray < FAccelByteModelsPublicPolicy > Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
string countryCode = "US";
string[] tags = new string[2] {
"beta",
"newsletter"
};
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().GetLegalPoliciesByCountry(countryCode, AgreementPolicyType.EMPTY, tags, false, publicPoliciesResult =>
{
if (publicPoliciesResult.IsError)
{
// Do something if failed
Debug.Log($"Get Legal Policies failed : {publicPoliciesResult.Error.Code} Description : {publicPoliciesResult.Error.Message}");
return;
}
// Do something when successful
});
Accept policies
Policies can be accepted one at a time or in bulk.
Accept a single policy
To accept a localized policy document using it localized version ID, use this function:
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->AcceptPolicyVersion(
// Specified localized policy version ID
,
FVoidHandler::CreateLambda([]() {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
string localizedPolicyVersionId = policyVersion.localizedPolicyVersions[0].id; // From GetLegalPolicies Result
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().AcceptPolicyVersion(localizedPolicyVersionId, acceptPolicyVersionResult =>
{
if (acceptPolicyVersionResult.IsError)
{
// Do something if failed
Debug.Log($"Accept Policy Version failed : {acceptPolicyVersionResult.Error.Code} Description : {acceptPolicyVersionResult.Error.Message}");
return;
}
// Do something when successful
});
Accept policies in bulk
To accept multiple localized policies at once, use this function:
- Unreal Engine
- Unity
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
auto AgreementApi = ApiClient->GetAgreementApi().Pin();
AgreementApi->BulkAcceptPolicyVersions(
// list of localized policy versions
,
THandler < FAccelByteModelsAcceptAgreementResponse > ::
CreateLambda([](FAccelByteModelsAcceptAgreementResponse Result) {
// Do something when successful
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage) {
// Do something if failed
})
);
//policy
AcceptAgreementRequest[] acceptAgreementRequests = new AcceptAgreementRequest[]
{
new AcceptAgreementRequest
{
isAccepted = true,
policyId = policy.policyId,
policyVersionId = policyVersion.id,
localizedPolicyVersionId = policyVersion.localizedPolicyVersions[0].id
}
};
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().BulkAcceptPolicyVersions(acceptAgreementRequests, acceptAgreementResponseResult =>
{
if (acceptAgreementResponseResult.IsError)
{
// Do something if failed
Debug.Log($"Accept Policy Version failed : {acceptAgreementResponseResult.Error.Code} Description : {acceptAgreementResponseResult.Error.Message}");
return;
}
// Do something when successful
});
Update existing policies
The following shows you how to make changes to existing policies.
Update marketing preference consent
The code below only accepts the "marketing preference" policy type. Refer to Policy types for information on the different types. Refer to Retrieve policies to get your latest policy details.
To update the player's current marketing preference consent, use the code in the following snippet:
- Unity
// Retrieve list of policies.
Result<PublicPolicy[]> publicPoliciesResult;
// Assume that the from the retrieved policy list, only the first policy will be accepted
AcceptAgreementRequest[] acceptAgreementRequests = new AcceptAgreementRequest[]
{
new AcceptAgreementRequest
{
isAccepted = true,
policyId = publicPoliciesResult.Value[0].id,
policyVersionId = publicPoliciesResult.Value[0].policyVersions[0].id,
localizedPolicyVersionId = publicPoliciesResult.Value[0].policyVersions[0].localizedPolicyVersions[0].id
}
};
AccelByteSDK.GetClientRegistry().GetApi().GetAgreement().BulkAcceptPolicyVersions(acceptAgreementRequests, acceptAgreementResponseResult =>
{
if (acceptAgreementResponseResult.IsError)
{
// Do something if failed
Debug.Log($"Accept Policy Version failed : {acceptAgreementResponseResult.Error.Code} Description : {acceptAgreementResponseResult.Error.Message}");
return;
}
// Do something when successful
});