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.
static ITreasureData Instance;
Treasure Data object instance. Make sure to call InitializeWithAPIKey
before accessing.
string DefaultDatabase;
The default database to send events to. Treasure Data recommends setting this during initialization.
string DefaultTable;
The default Table to send events to. Treasure Data recommends setting this during initialization.
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 |
static inline void EnableLogging()
Enable the debug log.
static inline void DisableLogging()
Disable the debug log.
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");
Param | Description |
---|---|
apiEndpoint | API Endpoint to send data to. |
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);
Param | Description |
---|---|
encryptionKey | string with the encryption key to use for local device encryption. |
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 |
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);
Param | Description |
---|---|
database | Name of the database |
static inline void StartGlobalSession()
Start tracking a global session.
static inline void EndGlobalSession()
End tracking a global session.
static inline string GetGlobalSessionId()
Get the current global session ID.
inline void EnableCustomEvent()
Enable custom event tracking.
inline void DisableCustomEvent()
Disable custom event tracking.
inline bool IsCustomEventEnabled()
Whether or not the custom event tracking is enabled.
Return: true: enabled, false: disabled
inline void EnableAppLifecycleEvent()
Enable app lifecycle tracking. This setting has no effect on custom tracking.
inline void DisableAppLifecycleEvent()
Disable app lifecycle tracking. This setting has no effect on custom tracking
inline bool IsAppLifecycleEventEnabled()
Determine whether or not application lifecycle tracking is enabled.
Return: true : enabled, false : disabled
inline void EnableInAppPurchaseEvent(
bool flag =true
)
Enable tracking In App Purchase event automatically. This is disabled by default.
Param | Description |
---|---|
flag | Boolean true / false |
inline void DisableInAppPurchaseEvent()
Enable tracking In App Purchase event automatically. This is disabled by default.
inline bool IsInAppPurchaseEventEnabled()
Determine whether or not the In App Purchase tracking is enabled.
Return: true: enabled, false: disabled
inline void ResetUniqId()
Reset UUID and send forget_device_uuid
event with old UUID.
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
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
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
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
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
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
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
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
inline void UploadEvents()
Upload events from local buffer to Treasure Data.
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. |
inline void DisableAutoAppendUniqId()
Disable the automatically appended td_uuid
column.
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", ... }
inline void DisableAutoAppendModelInformation()
Disable automatic tracking of model information.
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.modeltd_model
: UIDevice.modeltd_os_ver
: UIDevice.model.systemVersiontd_os_type
: "iOS"
- Android
td_board
: android.os.Build::BOARDtd_brand
: android.os.Build::BRANDtd_device
: android.os.Build::DEVICEtd_display
: android.os.Build::DISPLAYtd_model
: android.os.Build::MODELtd_os_ver
: android.os.Build.VERSION::SDK_INTtd_os_type
: "Android"
inline void DisableAutoAppendAppInformation()
Disable automatic tracking of application information.
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 keyCFBundleShortVersionString
td_app_ver_num
: Core Foundation keyCFBundleVersion
- 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())
inline void DisableAutoAppendLocaleInformation()
Disable automatic tracking of locale information.
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)
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();
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");
Param | Description |
---|---|
columnName | Set the column to write the uploaded time value |
inline void DisableServerSideUploadTimestamp()
Disable the uploading time column.
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(...);
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 |
inline void DisableAutoAppendRecordUUID()
Disable appending ID for each event.
inline void DisableRetryUploading()
Disable automatic retry uploading. After it is disabled, the application only attempts to upload events once per upload event.
inline void EnableRetryUploading()
Enable automatic retry uploading. Once enabled, the application continues trying to upload events until all events are uploaded successfully.
inline void ClearFirstRun()
Clear first run flag.
inline string GetSessionId()
Get current session ID.
Return: string Session ID