Skip to content

Install and initialize the module

To use terms features, you must install the terms module in the Hive Axyl SDK and initialize it. If you have not installed the Hive Axyl SDK yet, first install the Hive Axyl SDK.

1. Install the terms module

1.1. Select common modules

The common module provides the minimum features for using Hive Axyl, so you must select it.

  • com.com2usplatform.hiveaxyl.core: SDK initialization and the basic features that other modules share

1.2. Select modules for terms features

Terms features additionally require the following modules.

  • com.com2usplatform.hiveaxyl.terms: Features for retrieving terms, retrieving the consent status, saving and deleting consent, and retrieving consent history
  • com.com2usplatform.hiveaxyl.auth: Features needed to prepare the login session when you obtain consent with the Player ID after login

If you obtain terms consent only before login, you can install just the terms module without the authentication module. For consent subjects, see Consent subject.

1.3. Install modules

Install the modules the same way as in SDK installation. Keep the Hive Axyl Scoped Registry you registered when you installed the SDK as it is, and add only the modules that terms features need to dependencies in Packages/manifest.json. If you already installed some modules, do not remove the existing entries; add only the modules that are not there yet.

{
  "scopedRegistries": [
    {
      "name": "Hive Axyl",
      "url": "https://package.openupm.com",
      "scopes": [
        "com.com2usplatform.hiveaxyl"
      ]
    }
  ],
  "dependencies": {
    "com.com2usplatform.hiveaxyl.core": "2.0.0",
    "com.com2usplatform.hiveaxyl.auth": "2.0.0",
    "com.com2usplatform.hiveaxyl.terms": "2.0.0"
  }
}

1.4. Verify the installation

Use the following code to check that the namespaces of the installed modules are recognized correctly.

using Hive.Axyl.Core;
using Hive.Axyl.Auth;
using Hive.Axyl.Terms;

The installation step is complete when the installed modules appear in the Installed state in Unity Package Manager.

2. Initialize the SDK

Method

Initialize

When the app starts, call the initialization method and register the terms module.

  1. Check the App ID you created in Create app information. The part before the first . of the App ID is the company code. Pass this value as CompanyCode when you call terms methods.
  2. Run CoreConfig.CreateBuilder with the App ID to create a CoreConfig object. If you register AddToken(), you must also set the Client ID with SetOAuthClientId. Check the Client ID in Get the security key.
  3. Initialize with HiveBootstrap.Initialize and register AddTerms() in builder. If you obtain consent after login, also register AddAuth() and AddToken().

Call the initialization method only once while the app runs. If you already wrote initialization code in Step 4. Initialize the SDK or for another feature, do not call it again; just add AddTerms() to the builder of the existing Initialize call.

Call parameters

Field name Type Required Description
config CoreConfig Required A CoreConfig object that holds the App ID. Create it with CoreConfig.CreateBuilder. If you register AddToken(), it must also hold the Client ID.
assemble Action<IHiveBuilder> Required A builder callback that registers the feature modules to use. To use terms features, include builder.AddTerms().

Call example

using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity;
using Hive.Axyl.Auth;
using Hive.Axyl.Terms;

// Call once when the app starts (for example, in Start of the first scene's MonoBehaviour).
// This setup also takes consent from logged-in users. If you take consent only before login, register only AddTerms()
// without the auth module, and leave out using Hive.Axyl.Auth, SetOAuthClientId, AddAuth() and AddToken().
CoreConfig config = CoreConfig.CreateBuilder("{appId}")
    .SetOAuthClientId("{clientId}")   // OAuth client ID sent when the token is refreshed automatically
    .Build();

HiveBootstrap.Initialize(config, builder =>
{
    builder.AddAuth();    // Account and authentication (IAuthService)
    builder.AddToken();   // Token issuance and automatic refresh (ITokenService)
    builder.AddTerms();   // Terms (ITermsService)
});

Get the registered terms module with HiveCore.Resolve<ITermsService>() and use it.

ITermsService terms = HiveCore.Resolve<ITermsService>();

Response status

If HiveCore.Resolve<ITermsService>() returns an instance without an exception, initialization and module registration are complete. For the exception that occurs when you get a module that is not registered and the common principles of error handling, see Common error handling.

In the following cases, an exception occurs during initialization.

  • ArgumentNullException: null was passed for config
  • InvalidOperationException: The initialization method was called again after initialization was already complete
  • InvalidOperationException: AddToken() was registered but the Client ID was not set with SetOAuthClientId, or was set to an empty value
  • DllNotFoundException: The native plugin that the SDK uses could not be loaded on Windows. For the cause and how to respond, see Windows prerequisites

3. Prepare the terms

The terms module retrieves only terms deployed in the Hive Console. Before calling terms methods, the operator prepares the terms in the following order.

  1. In Terms > Terms Registration, enter a service code and register the terms items.
  2. Deploy the terms in Terms > Terms Deployment.

When you call terms methods, pass the service code you entered here as ServiceCode. A service code is a string of 2 to 30 characters that starts with an uppercase English letter and uses only uppercase English letters, digits, and _.

Pass the company code of the same company as the App ID as CompanyCode. If the companies differ, every terms method returns ServiceNotFound.

Next steps