Install and initialize the module
To use Analytics features, you must install the Analytics 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.
Install the Analytics module
The Analytics module works with only the common module. Because event logs are sent even before login, you do not need the authentication module. If you also use login features, use the authentication module you installed in Build with Code together with it.
Select common modules
Select the following common module.
com.com2usplatform.hiveaxyl.core: Hive Axyl SDK initialization and the basic features that other modules share
Select modules for Analytics features
Analytics features additionally require the following module.
com.com2usplatform.hiveaxyl.analytics: The event log sending feature that turns events that occur in the app into log events and sends multiple log events together in a single request
Install modules
Install the Analytics module the same way as in SDK installation. Because the Hive Axyl SDK is installed only through a Scoped Registry, additionally declare the Analytics module in the Hive Axyl Scoped Registry you registered when you installed the SDK.
Add com.com2usplatform.hiveaxyl.core and the Analytics module com.com2usplatform.hiveaxyl.analytics to dependencies in Packages/manifest.json.
Verify the installation
Use the following using statements to check that the namespaces of the installed SDK and Analytics module are recognized correctly.
The installation is complete when the installed modules appear in the Installed state in Unity Package Manager.
Initialize the SDK
Initialize
To use Analytics features, you must initialize the Hive Axyl SDK once when the app starts. During initialization, the SDK prepares the runtime needed to send event logs.
- Check the App ID you created in Create app information.
- Run
CoreConfig.CreateBuilderwith the App ID to create aCoreConfigobject. - Run initialization with
HiveBootstrap.Initialize, and register the Analytics module withAddAnalytics()onbuilder. - After initialization, get the Analytics features with
HiveCore.Resolve<IAnalyticsService>()and use them.
Call initialization only once while the app is running. If you already wrote initialization code in Step 4. Initialize the SDK, do not call it again. Only add AddAnalytics() to the builder of your existing Initialize call.
Call parameters
| Field name | Type | Required | Description |
|---|---|---|---|
config | CoreConfig | Required | The CoreConfig object that holds the App ID. Create it with CoreConfig.CreateBuilder. |
assemble | Action<IHiveBuilder> | Required | The builder callback that registers the feature modules to use. To use Analytics features, include builder.AddAnalytics(). |
Call example
using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity; // HiveBootstrap
using Hive.Axyl.Analytics; // AddAnalytics extension
var config = CoreConfig.CreateBuilder("{appId}").Build();
HiveBootstrap.Initialize(config, builder =>
{
builder.AddAnalytics(); // Analytics (IAnalyticsService)
// If you also use other features such as login, register them in the same initialization call.
// builder.AddAuth();
// builder.AddToken();
});
After registration, get the registered module with HiveCore.Resolve<IAnalyticsService>() and use it.
Response data
No data is returned on success.
Response example
Response status
Check whether initialization and module registration succeeded with the result of the HiveCore.Resolve<IAnalyticsService>() call. If it returns an instance without an exception, both initialization and module registration are complete. For the common principles of error handling, including the exception that Resolve<T>() throws when module registration is missing, see Common error handling.
In the following cases, an exception is thrown during initialization. Unlike a Failure you receive as the result of a method call, this exception immediately fails the initial setup.
ArgumentNullException: When you passnulltoconfigInvalidOperationException: When you call the initialization method again after initialization is already completeDllNotFoundException: When a Windows build cannot load the OS-specific binaries that the SDK uses. For the causes and how to handle them, see Windows build prerequisites below
Windows build prerequisites
In Windows builds, the SDK also loads the OS-specific binaries (native plugins) that it calls from C# code. If these files cannot be loaded, a DllNotFoundException is thrown during initialization. There are two causes.
- When the native plugin files are not included in the build output
- When Microsoft Visual C++ 2015-2022 Redistributable (x64) is not installed on the PC that runs the app. This package is a set of Microsoft runtime libraries that the native plugins need to run. Windows does not include it by default, and Unity does not add it to the build output.
Therefore, when you release on Windows, include this redistributable package in your app installer, or guide users to install it on first launch. The download link is also included in the exception message.