Skip to content

Treasure Data Unity SDK API Reference

Overview

class TreasureData;

The ITreasureData interface wraps the native iOS and Android SDKs for use in Unity development. If you have any questions please reference the underlying SDK API Reference Documentation.

Public Property

property Instance

static ITreasureData Instance;

Treasure Data object instance. Make sure to call InitializeWithAPIKey before accessing.


property DefaultDatabase

string DefaultDatabase;

The default database to send events to. Treasure Data recommends setting this during initialization.


property DefaultTable

string DefaultTable;

The default Table to send events to. Treasure Data recommends setting this during initialization.


Public Functions

InitializeApiKey

static inline void InitializeApiKey(
    string apiKey
)

Set the write-only TD API key. Treasure Data recommends setting this during initialization.

ParamDescription
apiKeyTD Write-only API Key

EnableLogging

static inline void EnableLogging()

Enable the debug log.


DisableLogging

static inline void DisableLogging()

Disable the debug log.


InitializeApiEndpoint

static inline void InitializeApiEndpoint(
    string apiEndpoint
)

Set the TD API Endpoint to use. The default is records.in.treasuredata.com.

Example

TreasureData.InitializeApiEndpoint("https://us01.records.in.treasuredata.com");
ParamDescription
apiEndpointAPI Endpoint to send data to.

InitializeEncryptionKey

static inline void InitializeEncryptionKey(
    string encryptionKey
)

Initialize the AES 128 encryption. The string must be less than 128 characters. This will encrypt event data passed to AddEvent.

Example

TreasureData.InitializeEncryptionKey("hello world");
    :
TreasureData.Instance.AddEvent("testdb", "unitytbl", ev);
ParamDescription
encryptionKeystring with the encryption key to use for local device encryption.

InitializeDefaultApiKey

static inline void InitializeDefaultApiKey(
    string apiKey
)

Set the default API key to be used across all initialized TD objects automatically. Treasure Data recommends you use a write-only API key.

ParamDescription
apiKeyTD write-only api key

InitializeDefaultDatabase

static inline void InitializeDefaultDatabase(
    string database
)

Set the default database to use for all initialized TD objects automatically. Make sure that this database already exists in your Treasure Data account.

Example

TreasureData.InitializeDefaultDatabase("testdb");
    :
TreasureData.Instance.AddEvent("unitytbl", ev);
ParamDescription
databaseName of the database

StartGlobalSession

static inline void StartGlobalSession()

Start tracking a global session.


EndGlobalSession

static inline void EndGlobalSession()

End tracking a global session.


GetGlobalSessionId

static inline string GetGlobalSessionId()

Get the current global session ID.


EnableCustomEvent

inline void EnableCustomEvent()

Enable custom event tracking.


DisableCustomEvent

inline void DisableCustomEvent()

Disable custom event tracking.


IsCustomEventEnabled

inline bool IsCustomEventEnabled()

Whether or not the custom event tracking is enabled.

Return: true: enabled, false: disabled


EnableAppLifecycleEvent

inline void EnableAppLifecycleEvent()

Enable app lifecycle tracking. This setting has no effect on custom tracking.


DisableAppLifecycleEvent

inline void DisableAppLifecycleEvent()

Disable app lifecycle tracking. This setting has no effect on custom tracking


IsAppLifecycleEventEnabled

inline bool IsAppLifecycleEventEnabled()

Determine whether or not application lifecycle tracking is enabled.

Return: true : enabled, false : disabled


EnableInAppPurchaseEvent

inline void EnableInAppPurchaseEvent(
    bool flag =true
)

Enable tracking In App Purchase event automatically. This is disabled by default.

ParamDescription
flagBoolean true / false

DisableInAppPurchaseEvent

inline void DisableInAppPurchaseEvent()

Enable tracking In App Purchase event automatically. This is disabled by default.


IsInAppPurchaseEventEnabled

inline bool IsInAppPurchaseEventEnabled()

Determine whether or not the In App Purchase tracking is enabled.

Return: true: enabled, false: disabled


ResetUniqId

inline void ResetUniqId()

Reset UUID and send forget_device_uuid event with old UUID.


AddEvent

inline bool AddEvent(
    string table,
    string key,
    object val
)

Add an event to local buffer.

ParamDescription
tablethe event's destination table
keykey of the event object
valvalue of the event object

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string table,
    string key,
    object val,
    OnSuccess onSuccess,
    OnError onError
)

Add an event to local buffer with callback.

ParamDescription
tablethe event's destination table
keykey of the event object
valvalue of the event object
onSuccesscallback function for successful execution
onErrorcallback function for failure

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string table,
    Dictionary< string, object > obj
)

Add an event to local buffer. Use DefaultDatabase as database.

ParamDescription
tablethe event's destination table
objthe event object

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string table,
    Dictionary< string, object > obj,
    OnSuccess onSuccess,
    OnError onError
)

Add an event to local buffer with callback. Use DefaultDatabase as database.

ParamDescription
tablethe event's destination table
objthe event object
onSuccesscallback function for successful execution
onErrorcallback function for failure

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string database,
    string table,
    string key,
    object val
)

Add an event to local buffer.

ParamDescription
databasethe event's destination database
tablethe event's destination table
keykey of the event object
valvalue of the event object

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string database,
    string table,
    string key,
    object val,
    OnSuccess onSuccess,
    OnError onError
)

Add an event to local buffer with callback.

ParamDescription
databasethe event's destination database
tablethe event's destination table
keykey of the event object
valvalue of the event object
onSuccesscallback function for successful execution
onErrorcallback function for failure

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string database,
    string table,
    Dictionary< string, object > events
)

Add events to local buffer.

ParamDescription
databasethe event's destination database
tablethe event's destination table
eventsevent data

Return: bool success / failure boolean


AddEvent

inline bool AddEvent(
    string database,
    string table,
    Dictionary< string, object > events,
    OnSuccess onSuccess,
    OnError onError
)

Add events to local buffer with callback.

ParamDescription
databasethe event's destination database
tablethe event's destination table
eventsevent data
onSuccesscallback function for successful execution
onErrorcallback function for failure

Return: bool success / failure boolean


UploadEvents

inline void UploadEvents()

Upload events from local buffer to Treasure Data.


UploadEvents

inline void UploadEvents(
    OnSuccess onSuccess,
    OnError onError
)

Upload events from local buffer to Treasure Data. Triggers onSuccess and onError callbacks on success or failure.

ParamDescription
onSuccessCallback function to trigger on successful upload.
onErrorCallback function to trigger on failure to upload.

DisableAutoAppendUniqId

inline void DisableAutoAppendUniqId()

Disable the automatically appended td_uuid column.


EnableAutoAppendUniqId

inline void EnableAutoAppendUniqId()

Automatically append td_uuid column for every event. The value is randomly generated and persists across application launches and events. Basically, it is used to represent a unique application installation instance. This is disabled by default. This value won't change until the application is uninstalled.

Example

TreasureData.Instance.EnableAutoAppendUniqId();
    :
TreasureData.Instance.AddEvent("unitytbl", "name", "foobar");
// Outputs =>>
//   {"td_uuid_id":"cad88260-67b4-0242-1329-2650772a66b1", "name":"foobar", ... }

DisableAutoAppendModelInformation

inline void DisableAutoAppendModelInformation()

Disable automatic tracking of model information.


EnableAutoAppendModelInformation

inline void EnableAutoAppendModelInformation()

Enable automatic tracking of device model information.

Example

TreasureData.Instance.EnableAutoAppendModelInformation();
    :
TreasureData.Instance.AddEvent("unitytbl", "name", "foobar");
// Outputs =>>
//   {"td_device":"iPod touch", "name":"foobar", ... }

It outputs the following column names and values:

  • iOS
    • td_device : UIDevice.model
      • td_model : UIDevice.model
      • td_os_ver : UIDevice.model.systemVersion
      • td_os_type : "iOS"
  • Android
    • td_board : android.os.Build::BOARD
    • td_brand : android.os.Build::BRAND
    • td_device : android.os.Build::DEVICE
    • td_display : android.os.Build::DISPLAY
    • td_model : android.os.Build::MODEL
    • td_os_ver : android.os.Build.VERSION::SDK_INT
    • td_os_type : "Android"

DisableAutoAppendAppInformation

inline void DisableAutoAppendAppInformation()

Disable automatic tracking of application information.


EnableAutoAppendAppInformation

inline void EnableAutoAppendAppInformation()

Application package version information will be added to each event automatically

Example

TreasureData.Instance.EnableAutoAppendAppInformation();
    :
TreasureData.Instance.AddEvent("unitytbl", "name", "foobar");
// Outputs =>>
//   {"td_app_ver":"1.2.3", "name":"foobar", ... }

It outputs the following column names and values:

  • iOS
    • td_app_ver : Core Foundation key CFBundleShortVersionString
    • td_app_ver_num : Core Foundation key CFBundleVersion
  • Android
    • td_app_ver : android.content.pm.PackageInfo.versionName (from Context.getPackageManager().getPackageInfo())
    • td_app_ver_num : android.content.pm.PackageInfo.versionCode (from Context.getPackageManager().getPackageInfo())

DisableAutoAppendLocaleInformation

inline void DisableAutoAppendLocaleInformation()

Disable automatic tracking of locale information.


EnableAutoAppendLocaleInformation

inline void EnableAutoAppendLocaleInformation()

Enable automatic tracking of locale information by adding it to each event.

Example

TreasureData.Instance.EnableAutoAppendLocaleInformation();
    :
td.AddEvent("unitytbl", "name", "foobar");
// Outputs =>>
//   {"td_locale_lang":"en", "name":"foobar", ... }

It outputs the following column names and values:

  • iOS
    • td_locale_country : [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]
    • td_locale_lang : [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]
  • Android
    • td_locale_country : java.util.Locale.getCountry() (from Context.getResources().getConfiguration().locale)
    • td_locale_lang : java.util.Locale.getLanguage() (from Context.getResources().getConfiguration().locale)

EnableServerSideUploadTimestamp

inline void EnableServerSideUploadTimestamp()

Automatically append the server side upload time stamp when the event is received on server. This is disabled by default. The column name is set to time by default.

Example : Use the server side upload time as time column.

td.EnableServerSideUploadTimestamp();

EnableServerSideUploadTimestamp

inline void EnableServerSideUploadTimestamp(
    string v
)

Automatically append the server side upload time stamp when the event is received on server. Disabled by default.

Example : Add server side upload time as a customized column name

td.EnableServerSideUploadTimestamp("server_upload_time");
ParamDescription
columnNameSet the column to write the uploaded time value

DisableServerSideUploadTimestamp

inline void DisableServerSideUploadTimestamp()

Disable the uploading time column.


EnableAutoAppendRecordUUID

inline void EnableAutoAppendRecordUUID()

Automatically appends a random and unique ID for each event, using record_uuid as the default column name. Each event has a different UUID. This is disabled by default.

Example

TreasureData.Instance.EnableAutoAppendRecordUUID();
// If you want to customize the column name, pass it to the API
// TreasureData.Instance.EnableAutoAppendRecordUUID("my_record_uuid");
    :
TreasureData.Instance.AddEvent(...);

EnableAutoAppendRecordUUID

inline void EnableAutoAppendRecordUUID(
    string v
)

Automatically append a random and unique ID for each event. Disabled by default.

ParamDescription
columnNameThe column to write the ID

DisableAutoAppendRecordUUID

inline void DisableAutoAppendRecordUUID()

Disable appending ID for each event.


DisableRetryUploading

inline void DisableRetryUploading()

Disable automatic retry uploading. After it is disabled, the application only attempts to upload events once per upload event.


EnableRetryUploading

inline void EnableRetryUploading()

Enable automatic retry uploading. Once enabled, the application continues trying to upload events until all events are uploaded successfully.


ClearFirstRun

inline void ClearFirstRun()

Clear first run flag.


GetSessionId

inline string GetSessionId()

Get current session ID.

Return: string Session ID