Treasure Data Android and iOS SDKs Cordova Plugin

The td-cordova-sdk module uses the native iOS and Android SDKs to provide Treasure Data Mobile SDK features to Cordova apps.

Getting Started

Install the TD Cordova SDK by running the following command:

Copy
Copied
$ cordova plugin add td-cordova-sdk

Usage

After installing the plugin, you can access the methods through cordova.plugins.TreasureDataPlugin namespace.

Configuration

Copy
Copied
TreasureDataPlugin.setup({
  apiEndpoint: 'https://us01.records.in.treasuredata.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
})

Add an Event to Local Buffer

You can add custom events to a specific database and table. If a database parameter is not specified, the defaultDatabase configuration in TreasureDataPlugin.setup({...}) will be used instead.

Specify the database and table where you want to import events. The total length of the database and table names must be shorter than 129 characters.

Copy
Copied
const customEvent = {event: 'Custom event', data: new Date().getSeconds()};
TreasureDataPlugin.addEvent(customEvent, 'table', 'database');
// or
TreasureDataPlugin.addEvent(customEvent, 'table');

If you need to know whether addEvent was successful or failed, use addEventWithCallback. You can pass null or undefined as database parameters and defaultDatabase configuration in TreasureDataPlugin.setup({...}) will be used instead.

Copy
Copied
const customEvent = {event: 'Custom event', data: new Date().getSeconds()};
TreasureDataPlugin.addEventWithCallback(customEvent, 'table', 'database', () => {
  console.log('Add Event Successfully');
}, (errorCode, errorMessage) => {
  console.log('Add Event Failed', errorCode, errorMessage);
});

Upload Buffered Events to TreasureData

You can upload all buffered events to Treasure Data at anytime using the uploadEvent function

Copy
Copied
TreasureDataPlugin.uploadEvents();

If you need to know whether uploadEvents was successful or failed, use uploadEventsWithCallback instead.

Copy
Copied
TreasureDataPlugin.uploadEventsWithCallback(() => {
  console.log('Upload events successfully')
}, (errorCode, errorMessage) => {
  console.log('Failed to upload events', errorCode, errorMessage);
});

Further Reading

Here are additional resources that may be helpful. If you prefer to look at the source code, select the GitHub links below.