{"id":27627187,"url":"https://github.com/treasure-data/td-cordova-sdk","last_synced_at":"2025-04-23T13:53:26.536Z","repository":{"id":45882066,"uuid":"286775147","full_name":"treasure-data/td-cordova-sdk","owner":"treasure-data","description":"Treasure Data SDK Cordova Plugin","archived":false,"fork":false,"pushed_at":"2025-04-17T00:54:33.000Z","size":3299,"stargazers_count":3,"open_issues_count":6,"forks_count":1,"subscribers_count":60,"default_branch":"master","last_synced_at":"2025-04-17T13:56:24.659Z","etag":null,"topics":["security-production"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/treasure-data.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-08-11T15:06:33.000Z","updated_at":"2024-02-14T11:12:12.000Z","dependencies_parsed_at":"2025-04-21T23:31:46.865Z","dependency_job_id":null,"html_url":"https://github.com/treasure-data/td-cordova-sdk","commit_stats":{"total_commits":16,"total_committers":6,"mean_commits":"2.6666666666666665","dds":0.4375,"last_synced_commit":"539ee385ff90691ec816be8f1ac8c7196f1221d0"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasure-data%2Ftd-cordova-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasure-data%2Ftd-cordova-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasure-data%2Ftd-cordova-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasure-data%2Ftd-cordova-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treasure-data","download_url":"https://codeload.github.com/treasure-data/td-cordova-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250444181,"owners_count":21431594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["security-production"],"created_at":"2025-04-23T13:53:25.899Z","updated_at":"2025-04-23T13:53:26.533Z","avatar_url":"https://github.com/treasure-data.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Treasure Data Android and iOS SDKs Cordova Plugin\ntd-cordova-sdk module that uses native iOS and Android SDK underneath to provide Treasure Data Mobile SDK features for cordova apps.\n\nYou can see more detailed documentation in repositories for [td-android-sdk](https://github.com/treasure-data/td-android-sdk) and [td-ios-sdk](https://github.com/treasure-data/td-ios-sdk)\n\n## Getting started\n```\ncordova plugin add td-cordova-sdk\n```\n\n## Usage\n\nAfter installing the plugin, you can access the methods through `cordova.plugins.TreasureDataPlugin` namespace.\n\n## Configuration\n```javascript\nTreasureDataPlugin.setup({\n  apiEndpoint: 'https://us01.records.in.treasuredata.com', // Or other supported endpoints\n  encryptionKey: 'xxxxx',\n  apiKey: 'xxxxx', /// You should use write only api key\n  defaultDatabase: 'default_database',\n  defaultTable: 'default_table_name',\n  cdpEndpoint: 'https://cdp.in.treasuredata.com' // Or other cdp endpoints\n})\n```\n\n## Add an event to local buffer\nYou can add custom events to a specific database and table. If database param is not specified, `defaultDatabase` configuration in `TreasureDataPlugin.setup({...})` will be used instead.\nSpecify the database and table to which you want to import the events. The total length of database and table must be shorter than 129 characters.\n```javascript\nconst customEvent = {event: 'Custom event', data: new Date().getSeconds()};\nTreasureDataPlugin.addEvent(customEvent, 'table', 'database');\n// or\nTreasureDataPlugin.addEvent(customEvent, 'table');\n```\n\nOr if you need to know when `addEvent` is successful or has failed, use `addEventWithCallback` instead. You can pass `null` or `undefined` as database param and `defaultDatabase` configuration in `TreasureDataPlugin.setup({...})` will be used instead.\n```javascript\nconst customEvent = {event: 'Custom event', data: new Date().getSeconds()};\nTreasureDataPlugin.addEventWithCallback(customEvent, 'table', 'database', () =\u003e {\n  console.log('Add Event Successfully');\n}, (errorCode, errorMessage) =\u003e {\n  console.log('Add Event Failed', errorCode, errorMessage);\n});\n```\n\n## Upload buffered events to TreasureData\nYou can upload all buffered events to Treasure Data at anytime with `uploadEvent` function\n```javascript\nTreasureDataPlugin.uploadEvents();\n```\n\nOr if you need to know when `uploadEvents` is successful or has failed, use `uploadEventsWithCallback` instead.\n```javascript\nTreasureDataPlugin.uploadEventsWithCallback(() =\u003e {\n  console.log('Upload events successfully')\n}, (errorCode, errorMessage) =\u003e {\n  console.log('Failed to upload events', errorCode, errorMessage);\n});\n```\n\n## Custom Events\nAdd and upload custom events are enabled by default. However you can disable and enable this feature at any time using:\n```javascript\nTreasureDataPlugin.enableCustomEvent();\n```\nTo disable custom events\n```javascript\nTreasureDataPlugin.disableCustomEvent();\n```\n\n## (Android only) Track app lifecycle events automatically\nThis feature is only available in Android. App lifecycle event tracking is optional and not enable by default. You can track app lifecycle events automatically using:\n```javascript\nTreasureDataPlugin.enableAppLifecycleEvent();\n```\nTo disable tracking app lifecycle events:\n```javascript\nTreasureDataPlugin.disableAppLifecycleEvent();\n```\nTo check if tracking app lifecycle events is enabled:\n```javascript\nTreasureDataPlugin.isAppLifecycleEventEnabled((enabled) =\u003e {\n  console.log('Tracking app lifecycle event is enabled?', enabled ? 'yes' : 'no');\n})\n```\n\n## Track in app purchase events automatically\nYou don't need to check for platform when calling this feature's APIs, they will simply be no-op.\nIn app purchase event tracking is optional and not enable by default. To track in app purchase events automatically, you only need to add a line of code:\n```javascript\nTreasureDataPlugin.enableInAppPurchaseEvent();\n```\nTo disable tracking in app purchase events:\n```javascript\nTreasureDataPlugin.disableInAppPurchaseEvent();\n```\nTo check if tracking in app purchase events is enabled:\n```javascript\nTreasureDataPlugin.isInAppPurchaseEventEnabled((enabled) =\u003e {\n  console.log('Tracking in app purchase event is enabled?', enabled ? 'yes' : 'no');\n})\n```\n\n## Adding UUID of the device to each event automatically\nUUID 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.\n```javascript\nTreasureDataPlugin.enableAutoAppendUniqId();\n```\nTo disable adding UUID of device to each event automatically:\n```javascript\nTreasureDataPlugin.disableAutoAppendUniqId();\n```\nTo reset UUID of device\n```javascript\nTreasureDataPlugin.resetUniqId();\n```\n\n## Adding an UUID to each event record automatically\nUUID will be added to each event record automatically if you call `enableAutoAppendRecordUUID`. Each event has different UUID.\n```javascript\nTreasureDataPlugin.enableAutoAppendRecordUUID();\n```\nTo disable adding record UUID to each event automatically:\n```javascript\nTreasureDataPlugin.disableAutoAppendRecordUUID();\n```\n\n## Adding Advertising Id to each event record automatically\nAdvertising Id will be added to each event record automatically if you call `enableAutoAppendAdvertisingIdentifier`.\n\nIn Android, you must install Google Play Service Ads (Gradle `com.google.android.gms:play-services-ads`) as a dependency for this feature to work.\n\nIn iOS, you must link Ad Support framework in Link Binary With Libraries build phase for this feature to work.\n\nUser 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 `enableAutoAppendAdvertisingIdentifier` method 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.\n```javascript\nTreasureDataPlugin.enableAutoAppendAdvertisingIdentifier();\n// Or specify custom column\nTreasureDataPlugin.enableAutoAppendAdvertisingIdentifier('custom_aaid_column');\n```\nTo disable adding Advertising Id:\n```javascript\nTreasureDataPlugin.disableAutoAppendAdvertisingIdentifier();\n```\n\n## Adding device model information to each event automatically\nTo add device model information to each event automatically\n```javascript\nTreasureDataPlugin.enableAutoAppendModelInformation();\n```\nTo disable:\n```javascript\nTreasureDataPlugin.disableAutoAppendModelInformation();\n```\n\n## Adding application package version information to each event automatically\nTo add application version information to each event automatically\n```javascript\nTreasureDataPlugin.enableAutoAppendAppInformation();\n```\nTo disable:\n```javascript\nTreasureDataPlugin.disableAutoAppendAppInformation();\n```\n\n## Adding locale configuration information to each event automatically\nTo add locale configuration information to each event automatically\n```javascript\nTreasureDataPlugin.enableAutoAppendLocaleInformation();\n```\nTo disable:\n```javascript\nTreasureDataPlugin.disableAutoAppendLocaleInformation();\n```\n\n## Start/End session\nCall `startSession` to start tracking a session\n```javascript\nTreasureDataPlugin.startSession(sessionTable, sessionDatabase);\n```\nCall `endSession` to end tracking current session\n```javascript\nTreasureDataPlugin.endSession(sessionTable, sessionDatabase);\n```\n\n## Profile API\nThis 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:\n\n```javascript\nvar plugin = cordova.plugins.TreasureDataPlugin;\nfunction success(response) {\n  /* response format =\u003e [\n    {\n      \"segments\": [\"segment_id\"],\n      \"attributes\": {\n        \"age\": ##,\n        \"td_client_id\": \"xxxxxxxxxxxxx\"\n      },\n      \"audienceId\": \"audience_id\",\n      \"key\": { \"name\": \"user_id\", \"value\": \"xxxxxxx\" }\n    },\n    {\n      \"segments\": [\"segment_id\", \"segment_id\"],\n      \"attributes\": {\n        \"im_segments\": \"xxxxxxxxxxxx\",\n        \"work_style_per_family\": \"xxxxxxxx\"\n      },\n      \"audienceId\": \"audience_id\",\n      \"key\": {\n        \"name\": \"td_client_id\",\n        \"value\": \"xxxxxxxxxxxxx\"\n      }\n    }\n  ] */\n\n  // yay\n}\n\nfunction error() {\n  // nay\n}\n\nplugin.fetchUserSegments(\n  [\"audience_id\",\"audience_id\"],\n  {\n    user_id: \"xxxxx\",\n    td_client_id: \"xxxxx\"\n  },\n  success,\n  error\n);\n```\n\n## Default values\n\nSet 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.\nIf you have multiple default values set to the same key, newly added event will have the default value applied and override in following order:\n1. Default value targeting all tables and databases will be applied first.\n2. Default value targeting all tables in a database will then be applied.\n3. Default value targeting the table to which the event is added will then be applied.\n4. Default value targeting the table and database to which the event is added will then be applied.\n5. Finally, if the event has a value for the key, that value will override all default values.\n\nTo set default value:\n```javascript\nTreasureDataPlugin.setDefaultValue(\"value\", \"key\"); // Targeting all databases and tables\nTreasureDataPlugin.setDefaultValue(\"value\", \"key\", \"database_name\"); // Targeting all tables of database \"database_name\"\nTreasureDataPlugin.setDefaultValue(\"value\", \"key\", null, \"table_name\"); // Targeting all tables with \"table_name\" of any database\nTreasureDataPlugin.setDefaultValue(\"value\", \"key\", \"database_name\", \"table_name\"); // Targeting table \"table_name\" of database \"database_name\"\n```\n\nTo get default value:\n```javascript\n// Get default value for key targeting database \"database_name\" and table \"table_name\".\nTreasureDataPlugin.defaultValue(\"key\", \"database_name\", \"table_name\", (defaultValue) =\u003e {\n  console.log('Default Value', defaultValue);\n});\n```\n\nTo remove default value:\n```javascript\n// Only remove default values targeting database \"database_name\" and table \"table_name\".\nTreasureDataPlugin.removeDefaultValue(\"key\", \"database_name\", \"table_name\");\n```\n\n## Enable/Disable debug log\nTo enable debug log\n```javascript\nTreasureDataPlugin.enableLogging();\n```\nTo disable:\n```javascript\nTreasureDataPlugin.disableLogging();\n```\n\n## Enable/Disable retry uploading\nTo enable retry uploading\n```javascript\nTreasureDataPlugin.enableRetryUploading();\n```\nTo disable:\n```javascript\nTreasureDataPlugin.disableRetryUploading();\n```\n\n## Device and OS support\nSee native SDKs repository for more information about supported devices and OS\n\n## Support\nNeed a hand with something? Shoot us an email at [support@treasuredata.com](mailto:support@treasuredata.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreasure-data%2Ftd-cordova-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreasure-data%2Ftd-cordova-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreasure-data%2Ftd-cordova-sdk/lists"}