TD Cordova SDK API Reference
Here is the API Reference for the Treasure Data Cordova SDK. To get started, navigate to the Quickstart.
setup
Configure the Treasure Data object.
setup(apiEndpoint, apiKey, defaultDatabase, defaultTable, [cdpEndpoint], [encryptionKey])
Param | Type | Description |
---|---|---|
apiEndpoint | string |
Valid API endpoint for ingesting data. For a full list of baseURLs that can be used for apiEndpoint see the Treasure Data API baseURLs. |
apiKey | string |
Write only TD API Key |
defaultDatabase | string |
Database name in TD account |
defaultTable | string |
Table name in TD database |
[cdpEndpoint] | string |
Valid CDP endpoint for ingesting data. For a full list of baseURLs that can be used for cdpEndpoint see the Treasure Data API baseURLs. |
[encryptionKey] | string |
Encryption key used to locally encrypt events when saved to device storage. This key will be used to generate an aes128 encryption key. Any string will work. |
Example
TreasureDataPlugin.setup({
apiEndpoint: 'https://in.treasure-data.com', // Or other supported endpoints
encryptionKey: 'xxxxx',
apiKey: 'xxxxx', /// You should use write only api key
defaultDatabase: 'default_database',
defaultTable: 'default_table_name',
cdpEndpoint: 'https://cdp.in.treasuredata.com' // Or other cdp endpoints
})
Custom Events
Add and upload custom events are enabled by default. However you can disable and enable this feature at any time using:
To enable custom events:
TreasureDataPlugin.enableCustomEvent();
To disable custom events:
TreasureDataPlugin.disableCustomEvent();
Track App Lifecycle Events Automatically (Android only)
App lifecycle event tracking is optional and not enable by default.
To enable automatic tracking of app lifecycle events:
TreasureDataPlugin.enableAppLifecycleEvent();
To disable automatic tracking of app lifecycle events:
TreasureDataPlugin.disableAppLifecycleEvent();
To check if automatic tracking of app lifecycle events is enabled:
TreasureDataPlugin.isAppLifecycleEventEnabled((enabled) => {
console.log('Tracking app lifecycle event is enabled?', enabled ? 'yes' : 'no');
})
Track In App Purchase Events Automatically
Enables tracking in app purchases. In app purchase event tracking is optional and is not enabled by default. You don't need to check for platform when calling this feature's APIs; they will simply be NOP (no-op).
To enable the automatic tracking of in app purchase events:
TreasureDataPlugin.enableInAppPurchaseEvent();
To disable the automatic tracking of in app purchase events:
TreasureDataPlugin.disableInAppPurchaseEvent();
To check if automatic tracking of in app purchase events is enabled:
TreasureDataPlugin.isInAppPurchaseEventEnabled((enabled) => {
console.log('Tracking in app purchase event is enabled?', enabled ? 'yes' : 'no');
})
Adding UUID of the Device to Each Event Automatically
UUID of the device will be added to each event automatically if you call TreasureDataPlugin.enableAutoAppendUniqId()
. This value won't change until the application is uninstalled.
To enable adding the UUID of the device to each event automatically:
TreasureDataPlugin.enableAutoAppendUniqId();
To disable adding the UUID of the device to each event automatically:
TreasureDataPlugin.disableAutoAppendUniqId();
To reset UUID of device:
TreasureDataPlugin.resetUniqId();
Adding a UUID to Each Event Record Automatically
A UUID will be added to each event record automatically if you call enableAutoAppendRecordUUID
. Each event has different UUID.
To enable adding record UUID to each event automatically:
TreasureDataPlugin.enableAutoAppendRecordUUID();
To disable adding record UUID to each event automatically:
TreasureDataPlugin.disableAutoAppendRecordUUID();
Adding Advertising ID to Each Event Record Automatically
Advertising ID will be added to each event record automatically if you call enableAutoAppendAdvertisingIdentifier
.
In Android, you must install Google Play Service Ads (Gradle com.google.android.gms:play-services-ads
) as a dependency for this feature to work.
In iOS, you must link Ad Support framework in Link Binary With Libraries build phase for this feature to work.
Users should also not turn on Limit Ad Tracking feature in their device. If they do, Treasure Data will not attach Advertising ID to the record. Due to asynchronous nature of getting Advertising ID, after enableAutoAppendAdvertisingIdentifier
method is called, it may take some time for Advertising ID to be available to be added to the record. However, Treasure Data does cache the Advertising ID in order to add to the next event without having to wait for the fetch Advertising ID task to complete.
To enable adding Advertising ID:
TreasureDataPlugin.enableAutoAppendAdvertisingIdentifier();
// Or specify custom column
TreasureDataPlugin.enableAutoAppendAdvertisingIdentifier('custom_aaid_column');
To disable adding Advertising ID:
TreasureDataPlugin.disableAutoAppendAdvertisingIdentifier();
Adding Device Model Information to Each Event Automatically
To add device model information to each event automatically:
TreasureDataPlugin.enableAutoAppendModelInformation();
To disable:
TreasureDataPlugin.disableAutoAppendModelInformation();
Adding Application Package Version Information to Each Event Automatically
To add application version information to each event automatically:
TreasureDataPlugin.enableAutoAppendAppInformation();
To disable:
TreasureDataPlugin.disableAutoAppendAppInformation();
Adding Locale Configuration Information to Each Event Automatically
To add locale configuration information to each event automatically:
TreasureDataPlugin.enableAutoAppendLocaleInformation();
To disable:
TreasureDataPlugin.disableAutoAppendLocaleInformation();
Start/End Session
Call startSession
to start tracking a session
TreasureDataPlugin.startSession(sessionTable, sessionDatabase);
Call endSession
to end tracking current session
TreasureDataPlugin.endSession(sessionTable, sessionDatabase);
Profile API
This feature is not enabled on accounts by default, please contact support for more information.
Important
You must set cdpEndpoint
property of TreasureData's sharedInstance
.
var plugin = cordova.plugins.TreasureDataPlugin;
function success(response) {
/* response format => [
{
"segments": ["segment_id"],
"attributes": {
"age": ##,
"td_client_id": "xxxxxxxxxxxxx"
},
"audienceId": "audience_id",
"key": { "name": "user_id", "value": "xxxxxxx" }
},
{
"segments": ["segment_id", "segment_id"],
"attributes": {
"im_segments": "xxxxxxxxxxxx",
"work_style_per_family": "xxxxxxxx"
},
"audienceId": "audience_id",
"key": {
"name": "td_client_id",
"value": "xxxxxxxxxxxxx"
}
}
] */
// yay
}
function error() {
// nay
}
plugin.fetchUserSegments(
["audience_id","audience_id"],
{
user_id: "xxxxx",
td_client_id: "xxxxx"
},
success,
error
);
Default Values
Set a default value if you want an event added to a table, a database, or any table or database to automatically set value for a key. If you have multiple default values set to the same key, newly added event will have the default value applied and override in following order:
- Default value targeting all tables and databases will be applied first.
- Default value targeting all tables in a database will then be applied.
- Default value targeting the table to which the event is added will then be applied.
- Default value targeting the table and database to which the event is added will then be applied.
- Finally, if the event has a value for the key, that value will override all default values.
To set default value:
TreasureDataPlugin.setDefaultValue("value", "key"); // Targeting all databases and tables
TreasureDataPlugin.setDefaultValue("value", "key", "database_name"); // Targeting all tables of database "database_name"
TreasureDataPlugin.setDefaultValue("value", "key", null, "table_name"); // Targeting all tables with "table_name" of any database
TreasureDataPlugin.setDefaultValue("value", "key", "database_name", "table_name"); // Targeting table "table_name" of database "database_name"
To get default value:
// Get default value for key targeting database "database_name" and table "table_name".
TreasureDataPlugin.defaultValue("key", "database_name", "table_name", (defaultValue) => {
console.log('Default Value', defaultValue);
});
To remove default value:
// Only remove default values targeting database "database_name" and table "table_name".
TreasureDataPlugin.removeDefaultValue("key", "database_name", "table_name");
Enable/Disable Debug Log
To enable debug log:
TreasureDataPlugin.enableLogging();
To disable debug log:
TreasureDataPlugin.disableLogging();
Enable/Disable Retry Uploading
To enable retry uploading:
TreasureDataPlugin.enableRetryUploading();
To disable:
TreasureDataPlugin.disableRetryUploading();
Device and OS Support
See the native SDK repositories for more information about supported devices and operating systems.