Clickstream Unity SDK can help you easily collect and report events from Unity Games to AWS. This SDK is part of an AWS solution - Clickstream Analytics on AWS, which provisions data pipeline to ingest and process event data into AWS services such as S3, Redshift.
The SDK provide easy to use API for data collection. In addition, we've added features that automatically collect common user events and attributes (e.g., app start and scene load) to simplify data collection for users.
Visit our Documentation site to learn more about Clickstream Unity SDK.
We use Unity Package Manager to distribute our SDK
Window
and click Package Manager
in Unity Editor.+
button, then select Add package from git URL...
https://github.com/awslabs/clickstream-unity
, then click Add
to wait for completion.using ClickstreamAnalytics;
ClickstreamAnalytics.Init(new ClickstreamConfiguration
{
AppId = "your AppId",
Endpoint = "https://example.com/collect"
});
using ClickstreamAnalytics;
var attributes = new Dictionary<string, object>
{
{ "event_category", "shoes" },
{ "currency", "CNY" },
{ "value", 279.9 }
};
ClickstreamAnalytics.Record("button_click", attributes);
// record event with name
ClickstreamAnalytics.Record('button_click');
using ClickstreamAnalytics;
// when user login success.
ClickstreamAnalytics.SetUserId("UserId");
// when user logout
ClickstreamAnalytics.SetUserId(null);
using ClickstreamAnalytics;
var userAttrs = new Dictionary<string, object> {
{ "userName", "carl" },
{ "userAge", 22 }
};
ClickstreamAnalytics.SetUserAttributes(userAttrs);
When opening for the first time after integrating the SDK, you need to manually set the user attributes once, and current login user's attributes will be cached in PlayerPrefs, so the next time game start you don't need to set all user's attribute again, of course you can use the same api ClickstreamAnalytics.SetUserAttributes()
to update the current user's attribute when it changes.
Add global attributes when initializing the SDK
The following example code shows how to add global attributes when initializing the SDK.
using ClickstreamAnalytics;
ClickstreamAnalytics.Init(new ClickstreamConfiguration
{
AppId = "your AppId",
Endpoint = "https://example.com/collect",
GlobalAttributes = new Dictionary<string, object>
{
{ "_app_install_channel", "Amazon Store" }
}
});
Add global attributes after initializing the SDK
using ClickstreamAnalytics;
ClickstreamAnalytics.SetGlobalAttributes(new Dictionary<string, object>
{
{ "_traffic_source_source", "Search engine" }, { "level", 10 }
});
It is recommended to set global attributes when initializing the SDK, global attributes will be included in all events that occur after it is set, you also can remove a global attribute by setting its value to null
.
In addition to the required AppId
and Endpoint
, you can configure other information to get more customized usage:
using ClickstreamAnalytics;
ClickstreamAnalytics.Init(new ClickstreamConfiguration
{
AppId = "your AppId",
Endpoint = "https://example.com/collect",
SendEventsInterval = 10000,
IsCompressEvents = true,
IsLogEvents = false,
IsUseMemoryCache = false,
IsTrackAppStartEvents = true,
IsTrackAppEndEvents = true,
IsTrackSceneLoadEvents = true,
IsTrackSceneUnLoadEvents = true
});
Here is an explanation of each property:
10000
true
true
true
true
You can update the default configuration after initializing the SDK, below are the additional configuration options you can customize.
using ClickstreamAnalytics;
ClickstreamAnalytics.UpdateConfiguration(new Configuration
{
AppId = "your AppId",
Endpoint = "https://example.com/collect",
IsCompressEvents = false,
IsLogEvents = true,
IsTrackAppStartEvents = false,
IsTrackAppEndEvents = false,
IsTrackSceneLoadEvents = false,
IsTrackSceneUnLoadEvents = false
});
You can follow the steps below to view the event raw json and debug your events.
ClickstreamAnalytics.Init()
API and set the IsLogEvents
attribute to true in debug mode.[ClickstreamAnalytics]
in the filter, and you will see the json content of all events recorded by Clickstream Unity SDK.See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.