TD React Native SDK API Reference

Here is the API Reference for the Treasure Data React Native module. To get started, navigate to the Quickstart.

setup

TreasureData.setup(configuration) — Initializes the Treasure Data object.

Param Type Description
configuration json Configuration options
configuration.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.
configuration.apiKey string Write only TD API Key
configuration.defaultDatabase string Database name in TD account
configuration.defaultTable string Table name in TD database
[configuration.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.
[configuration.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
import TreasureData from 'td-react-native-sdk';

TreasureData.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 Event

TreasureData.enableCustomEvent() — Add and upload custom events are enabled by default.

TreasureData.disableCustomEvent() — Disables custom events.

Track app lifecycle events automatically (Android only)

TreasureData.enableAppLifecycleEvent() — This feature is only available in Android. App lifecycle event tracking is optional and is not enabled by default.

TreasureData.disableAppLifecycleEvent() — Disables tracking app lifecycle events.

To check if tracking app lifecycle events is enabled:

Copy
Copied
TreasureData.isAppLifecycleEventEnabled((enabled) => {
  console.log('Tracking app lifecycle event is enabled?', enabled);
})

Track in app purchase events automatically

TreasureData.enableInAppPurchaseEvent() — 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).

TreasureData.disableInAppPurchaseEvent() — Disables tracking in app purchase events.

To check if tracking in app purchase events is enabled:

Copy
Copied
TreasureData.isInAppPurchaseEventEnabled((enabled) => {
  console.log('Tracking in app purchase event is enabled?', enabled);
})

Adding the UUID of the device to each event automatically

TreasureData.enableAutoAppendUniqId() — UUID of the device will be added to each event automatically. This value won't change until the application is uninstalled.

TreasureData.disableAutoAppendUniqId() — Disables adding UUID of device to each event automatically.

TreasureData.resetUniqId() — Resets UUID of device.

Adding a UUID to each event record automatically

TreasureData.enableAutoAppendRecordUUID() — Adds UUID to each event record automatically. Each event has different UUID.

TreasureData.disableAutoAppendRecordUUID() — Disables adding record UUID to each event automatically.

Adding Advertising ID to each event record automatically

enableAutoAppendAdvertisingIdentifier — Advertising ID will be added to each event record automatically.

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.

User must also not turn on Limit Ad Tracking feature in their device, otherwise, Treasure Data will not attach Advertising ID to the record. Due to asynchronous nature of getting Advertising ID, after the enableAutoAppendAdvertisingIdentifier method is called, it may take some time for the Advertising ID to become available and 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.

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

TreasureData.disableAutoAppendAdvertisingIdentifier() — Disables adding Advertising ID.

Adding device model information to each event automatically

TreasureData.enableAutoAppendModelInformation() — Adds device model information to each event automatically.

TreasureData.disableAutoAppendModelInformation() — Disables adding device model information automatically.

Adding application package version information to each event automatically

TreasureData.enableAutoAppendAppInformation() — Adds application version information to each event automatically.

TreasureData.disableAutoAppendAppInformation() — Disables appending application package versions.

Adding locale configuration information to each event automatically

TreasureData.enableAutoAppendLocaleInformation() — Adds locale configuration information to each event automatically

TreasureData.disableAutoAppendLocaleInformation() — Disables adding locale information automatically.

Start/End session

TreasureData.startSession(sessionTable, sessionDatabase) — Starts tracking a session.

TreasureData.endSession(sessionTable, sessionDatabase) — Ends tracking the current session.

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.

Usage example:

Copy
Copied
TreasureData.fetchUserSegments(audienceTokens, keys, (jsonResponse) => {
  console.log('Fetch.User Segments', JSON.stringify(jsonResponse));
}, (errorCode, errorMessage) => {
  console.log('Failed to upload events', 'Error: ' + errorCode + ' ' + errorMessage);
});

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 be overridden 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
TreasureData.setDefaultValue("value", "key"); // Targeting all databases and tables
TreasureData.setDefaultValue("value", "key", "database_name"); // Targeting all tables of database "database_name"
TreasureData.setDefaultValue("value", "key", null, "table_name"); // Targeting all tables with "table_name" of any database
TreasureData.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".
TreasureData.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".
TreasureData.removeDefaultValue("key", "database_name", "table_name");

Enable/Disable debug log

TreasureData.enableLogging() — Enables the debug log.

TreasureData.disableLogging() — Disables the debug log.

Enable/Disable retry uploading

TreasureData.enableRetryUploading() — Enables retry uploading.

TreasureData.disableRetryUploading() — Disables retry uploading.

Device and Operating System Support

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