Consult with the Treasure team to develop a data dictionary / taxonomy prior to telemetry instrumentation

Our analytics tracking system allows you to track custom client-side events and properties to better understand your users’ behavior. Integration is simple and requires only a few lines of code.

Usage

To use analytics please let us know and in a private channel we’ll provide you the {DATA_PLATFORM_URL} and the X-API-Key header value to use.

1

Initialize an instance of the AnalyticsManager class

Use your {X-API-Key} and {DATA_PLATFORM_URL} along with an identifier for your app, the version of your app and the environment (dev/prod).

A cartridge_tag is assigned to your game by Treasure.

import { AnalyticsManager } from "@treasure-dev/tdk-core";

AnalyticsManager.instance.init(({
    apiUri: "{DATA_PLATFORM_URL}",
    apiKey: "{X-API-Key}",
    app: {
        // bundle/package name of ap e.g. lol.treasure.tdkjs
        app_identifier: "YOUR_APP_IDENTIFIER",
        // version of app e.g. 0.0.1,
        app_version: "YOUR_APP_VERSION",
        // 0 for dev, 1 for prod
        app_environment: 0,
    },
    cartridgeTag: "YOUR_CARTRIDGE_TAG",
});
2

Track a custom event

Track a custom event with the trackCustomEvent method.

The method accepts a TrackableEvent object with the following properties:

type PlayerIdPayload =
    | {
    smart_account: string; // Ethereum wallet address for player. Lowercase.
    user_id?: undefined; // Optional if smart_account is defined.
}
    | {
    user_id: string; // Required if smart_account is undefined. Can be player ID or email, etc.
    smart_account?: string; // Optional if user_id is defined.
};

export type TrackableEvent = PlayerIdPayload & {
    name: string;
    properties: { [key: string]: PropertyValue | PropertyValue[] };
};
  • A player ID: You must include one of or both smart_account and user_id. The smart_account is the Ethereum wallet address for the player. The user_id is some unique identifier for the player that you choose, such as an email address or a player ID.
  • name: The name of the event, which you define.
  • properties: An object containing the event properties. Property values can be strings, numbers, booleans, null, or arrays and objects of these types.
Please use snake_case for event and parameter names
// Track a custom event
const eventId: string = await AnalyticsManager.instance.trackCustomEvent({
    smart_account: "YOUR_SMART_ACCOUNT_ADDRESS", // And/or `user_id`
    name: "YOUR_EVENT_NAME",
    properties: {
        // Add any additional properties here
        // Please use `snake_case` for event and parameter names
    },
});

console.log(`Successfully tracked event with id: ${eventId}`);