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

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

Copy
Copied
TreasureDataPlugin.enableCustomEvent();

To disable custom events:

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

Copy
Copied
TreasureDataPlugin.enableAppLifecycleEvent();

To disable automatic tracking of app lifecycle events:

Copy
Copied
TreasureDataPlugin.disableAppLifecycleEvent();

To check if automatic tracking of app lifecycle events is enabled:

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

Copy
Copied
TreasureDataPlugin.enableInAppPurchaseEvent();

To disable the automatic tracking of in app purchase events:

Copy
Copied
TreasureDataPlugin.disableInAppPurchaseEvent();

To check if automatic tracking of in app purchase events is enabled:

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

Copy
Copied
TreasureDataPlugin.enableAutoAppendUniqId();

To disable adding the UUID of the device to each event automatically:

Copy
Copied
TreasureDataPlugin.disableAutoAppendUniqId();

To reset UUID of device:

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

Copy
Copied
TreasureDataPlugin.enableAutoAppendRecordUUID();

To disable adding record UUID to each event automatically:

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

Copy
Copied
TreasureDataPlugin.enableAutoAppendAdvertisingIdentifier();
// Or specify custom column
TreasureDataPlugin.enableAutoAppendAdvertisingIdentifier('custom_aaid_column');

To disable adding Advertising ID:

Copy
Copied
TreasureDataPlugin.disableAutoAppendAdvertisingIdentifier();

Adding Device Model Information to Each Event Automatically

To add device model information to each event automatically:

Copy
Copied
TreasureDataPlugin.enableAutoAppendModelInformation();

To disable:

Copy
Copied
TreasureDataPlugin.disableAutoAppendModelInformation();

Adding Application Package Version Information to Each Event Automatically

To add application version information to each event automatically:

Copy
Copied
TreasureDataPlugin.enableAutoAppendAppInformation();

To disable:

Copy
Copied
TreasureDataPlugin.disableAutoAppendAppInformation();

Adding Locale Configuration Information to Each Event Automatically

To add locale configuration information to each event automatically:

Copy
Copied
TreasureDataPlugin.enableAutoAppendLocaleInformation();

To disable:

Copy
Copied
TreasureDataPlugin.disableAutoAppendLocaleInformation();

Start/End Session

Call startSession to start tracking a session

Copy
Copied
TreasureDataPlugin.startSession(sessionTable, sessionDatabase);

Call endSession to end tracking current session

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

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

  1. Default value targeting all tables and databases will be applied first.
  2. Default value targeting all tables in a database will then be applied.
  3. Default value targeting the table to which the event is added will then be applied.
  4. Default value targeting the table and database to which the event is added will then be applied.
  5. Finally, if the event has a value for the key, that value will override all default values.

To set default value:

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

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

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

Copy
Copied
TreasureDataPlugin.enableLogging();

To disable debug log:

Copy
Copied
TreasureDataPlugin.disableLogging();

Enable/Disable Retry Uploading

To enable retry uploading:

Copy
Copied
TreasureDataPlugin.enableRetryUploading();

To disable:

Copy
Copied
TreasureDataPlugin.disableRetryUploading();

Device and OS Support

See the native SDK repositories for more information about supported devices and operating systems.