Treasure Data Unity SDK API Reference

Overview

Copy
Copied
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

Copy
Copied
static ITreasureData Instance;

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


property DefaultDatabase

Copy
Copied
string DefaultDatabase;

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


property DefaultTable

Copy
Copied
string DefaultTable;

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


Public Functions

InitializeApiKey

Copy
Copied
static inline void InitializeApiKey(
    string apiKey
)

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

Param Description
apiKey TD Write-only API Key

EnableLogging

Copy
Copied
static inline void EnableLogging()

Enable the debug log.


DisableLogging

Copy
Copied
static inline void DisableLogging()

Disable the debug log.


InitializeApiEndpoint

Copy
Copied
static inline void InitializeApiEndpoint(
    string apiEndpoint
)

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

Example

Copy
Copied
TreasureData.InitializeApiEndpoint("https://us01.records.in.treasuredata.com");
Param Description
apiEndpoint API Endpoint to send data to.

InitializeEncryptionKey

Copy
Copied
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

Copy
Copied
TreasureData.InitializeEncryptionKey("hello world");
    :
TreasureData.Instance.AddEvent("testdb", "unitytbl", ev);
Param Description
encryptionKey string with the encryption key to use for local device encryption.

InitializeDefaultApiKey

Copy
Copied
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.

Param Description
apiKey TD write-only api key

InitializeDefaultDatabase

Copy
Copied
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

Copy
Copied
TreasureData.InitializeDefaultDatabase("testdb");
    :
TreasureData.Instance.AddEvent("unitytbl", ev);
Param Description
database Name of the database

StartGlobalSession

Copy
Copied
static inline void StartGlobalSession()

Start tracking a global session.


EndGlobalSession

Copy
Copied
static inline void EndGlobalSession()

End tracking a global session.


GetGlobalSessionId

Copy
Copied
static inline string GetGlobalSessionId()

Get the current global session ID.


EnableCustomEvent

Copy
Copied
inline void EnableCustomEvent()

Enable custom event tracking.


DisableCustomEvent

Copy
Copied
inline void DisableCustomEvent()

Disable custom event tracking.


IsCustomEventEnabled

Copy
Copied
inline bool IsCustomEventEnabled()

Whether or not the custom event tracking is enabled.

Return: true: enabled, false: disabled


EnableAppLifecycleEvent

Copy
Copied
inline void EnableAppLifecycleEvent()

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


DisableAppLifecycleEvent

Copy
Copied
inline void DisableAppLifecycleEvent()

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


IsAppLifecycleEventEnabled

Copy
Copied
inline bool IsAppLifecycleEventEnabled()

Determine whether or not application lifecycle tracking is enabled.

Return: true : enabled, false : disabled


EnableInAppPurchaseEvent

Copy
Copied
inline void EnableInAppPurchaseEvent(
    bool flag =true
)

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

Param Description
flag Boolean true / false

DisableInAppPurchaseEvent

Copy
Copied
inline void DisableInAppPurchaseEvent()

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


IsInAppPurchaseEventEnabled

Copy
Copied
inline bool IsInAppPurchaseEventEnabled()

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

Return: true: enabled, false: disabled


ResetUniqId

Copy
Copied
inline void ResetUniqId()

Reset UUID and send forget_device_uuid event with old UUID.


AddEvent

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

Add an event to local buffer.

Param Description
table the event's destination table
key key of the event object
val value of the event object

Return: bool success / failure boolean


AddEvent

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

Add an event to local buffer with callback.

Param Description
table the event's destination table
key key of the event object
val value of the event object
onSuccess callback function for successful execution
onError callback function for failure

Return: bool success / failure boolean


AddEvent

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

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

Param Description
table the event's destination table
obj the event object

Return: bool success / failure boolean


AddEvent

Copy
Copied
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.

Param Description
table the event's destination table
obj the event object
onSuccess callback function for successful execution
onError callback function for failure

Return: bool success / failure boolean


AddEvent

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

Add an event to local buffer.

Param Description
database the event's destination database
table the event's destination table
key key of the event object
val value of the event object

Return: bool success / failure boolean


AddEvent

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

Add an event to local buffer with callback.

Param Description
database the event's destination database
table the event's destination table
key key of the event object
val value of the event object
onSuccess callback function for successful execution
onError callback function for failure

Return: bool success / failure boolean


AddEvent

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

Add events to local buffer.

Param Description
database the event's destination database
table the event's destination table
events event data

Return: bool success / failure boolean


AddEvent

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

Add events to local buffer with callback.

Param Description
database the event's destination database
table the event's destination table
events event data
onSuccess callback function for successful execution
onError callback function for failure

Return: bool success / failure boolean


UploadEvents

Copy
Copied
inline void UploadEvents()

Upload events from local buffer to Treasure Data.


UploadEvents

Copy
Copied
inline void UploadEvents(
    OnSuccess onSuccess,
    OnError onError
)

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

Param Description
onSuccess Callback function to trigger on successful upload.
onError Callback function to trigger on failure to upload.

DisableAutoAppendUniqId

Copy
Copied
inline void DisableAutoAppendUniqId()

Disable the automatically appended td_uuid column.


EnableAutoAppendUniqId

Copy
Copied
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

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

DisableAutoAppendModelInformation

Copy
Copied
inline void DisableAutoAppendModelInformation()

Disable automatic tracking of model information.


EnableAutoAppendModelInformation

Copy
Copied
inline void EnableAutoAppendModelInformation()

Enable automatic tracking of device model information.

Example

Copy
Copied
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

Copy
Copied
inline void DisableAutoAppendAppInformation()

Disable automatic tracking of application information.


EnableAutoAppendAppInformation

Copy
Copied
inline void EnableAutoAppendAppInformation()

Application package version information will be added to each event automatically

Example

Copy
Copied
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

Copy
Copied
inline void DisableAutoAppendLocaleInformation()

Disable automatic tracking of locale information.


EnableAutoAppendLocaleInformation

Copy
Copied
inline void EnableAutoAppendLocaleInformation()

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

Example

Copy
Copied
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

Copy
Copied
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.

Copy
Copied
td.EnableServerSideUploadTimestamp();

EnableServerSideUploadTimestamp

Copy
Copied
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

Copy
Copied
td.EnableServerSideUploadTimestamp("server_upload_time");
Param Description
columnName Set the column to write the uploaded time value

DisableServerSideUploadTimestamp

Copy
Copied
inline void DisableServerSideUploadTimestamp()

Disable the uploading time column.


EnableAutoAppendRecordUUID

Copy
Copied
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

Copy
Copied
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

Copy
Copied
inline void EnableAutoAppendRecordUUID(
    string v
)

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

Param Description
columnName The column to write the ID

DisableAutoAppendRecordUUID

Copy
Copied
inline void DisableAutoAppendRecordUUID()

Disable appending ID for each event.


DisableRetryUploading

Copy
Copied
inline void DisableRetryUploading()

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


EnableRetryUploading

Copy
Copied
inline void EnableRetryUploading()

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


ClearFirstRun

Copy
Copied
inline void ClearFirstRun()

Clear first run flag.


GetSessionId

Copy
Copied
inline string GetSessionId()

Get current session ID.

Return: string Session ID