{"id":4441,"url":"https://github.com/quipper/react-native-td","last_synced_at":"2025-07-31T13:30:55.637Z","repository":{"id":139698949,"uuid":"115089786","full_name":"quipper/react-native-td","owner":"quipper","description":"An unofficial React Native SDK for Treasure Data.","archived":true,"fork":false,"pushed_at":"2018-07-01T04:25:38.000Z","size":326,"stargazers_count":28,"open_issues_count":0,"forks_count":4,"subscribers_count":172,"default_branch":"master","last_synced_at":"2024-08-15T00:20:10.279Z","etag":null,"topics":["react-native","treasuredata","typescript"],"latest_commit_sha":null,"homepage":"","language":"Java","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/quipper.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-12-22T07:34:19.000Z","updated_at":"2023-01-28T10:44:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"9239d817-5c19-4c78-ac1d-1498ec6767b1","html_url":"https://github.com/quipper/react-native-td","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Freact-native-td","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Freact-native-td/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Freact-native-td/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quipper%2Freact-native-td/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quipper","download_url":"https://codeload.github.com/quipper/react-native-td/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228248566,"owners_count":17891447,"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":["react-native","treasuredata","typescript"],"created_at":"2024-01-05T20:17:12.079Z","updated_at":"2024-12-05T06:31:40.507Z","avatar_url":"https://github.com/quipper.png","language":"Java","readme":"# react-native-td [![CircleCI](https://circleci.com/gh/quipper/react-native-td.svg?style=svg)](https://circleci.com/gh/quipper/react-native-td) [![npm version](https://badge.fury.io/js/react-native-td.svg)](https://badge.fury.io/js/react-native-td)\n\nreact-native-td is an unofficial React Native SDK for Treasure Data.\n\nThe module is a light-weight layer sitting on-top of the TreasureData SDK for both [iOS](https://github.com/treasure-data/td-ios-sdk) and [Android](https://github.com/treasure-data/td-android-sdk).\n\n## Installation\n\nYou can install react-native-td into your project in the following way.\n\n```sh\nnpm install --save react-native-td\nreact-native link react-native-td\n```\n\n### iOS configuration\n\nIf you haven't introduced cocoapods, install it and run `pod init` under `ios/`and make sure lines below are in `Podfile`.\n\n```diff\n+ pod 'React', :path =\u003e '../node_modules/react-native', :subspecs =\u003e [\n+   'Core',\n+   'DevSupport', # Include this to enable In-App Devmenu if RN \u003e= 0.43\n+   'RCTText',\n+   'RCTNetwork',\n+   'RCTWebSocket', # needed for debugging\n+ ]\n+ pod 'yoga', :path =\u003e '../node_modules/react-native/ReactCommon/yoga'\n+ pod 'RNTreasureData', :path =\u003e '../node_modules/react-native-td'\n```\n\n## Usage\n\nBasically react-native-td imitates the interface of TreasureData iOS/Android SDK as close as possible.\n\nHence to know more detail check official documents below.\n\n- iOS: https://docs.treasuredata.com/articles/ios-sdk\n- Android: https://docs.treasuredata.com/articles/android-sdk\n\n### Instantiate with your API key\n\n```ts\nimport TreasureData from \"react-native-td\";\n\nTreasureData.initialize(\"your API key\");\n```\n\nWe recommend to use a write-only API key for the SDK. To obtain one, please:\n\n1. Login to the Treasure Data Console at http://console.treasuredata.com;\n2. Visit your Profile page at http://console.treasuredata.com/users/current;\n3. Insert your password under the 'API Keys' panel;\n4. In the bottom part of the panel, under 'Write-Only API keys', either copy the API key or click on 'Generate New' and copy the new API key.\n\n### Add a event to local buffer\n\nTo add an event to local buffer, you can call `addEvent` or `addEventWithCallback` API.\n\n```ts\nTreasureData.addEventWithCallback(\n  { event: \"event_name\" },\n  \"database_name\",\n  \"record_name\",\n  () =\u003e {\n    console.log(\"onSuccess is called.\");\n  },\n  (error, message) =\u003e {\n    console.log(`Error: ${error}`);\n    console.log(`Message: ${message}`);\n  }\n);\n```\n\nOr simply:\n\n```ts\nTreasureData.addEvent(\"database_name\", \"table_name\", { event: \"event_name\" });\n```\n\n### Upload buffered events to Treasure Data\n\nTo upload events buffered events to Treasure Data, you can call `uploadEvents` or `uploadEventsWithCallback` API.\n\n```ts\nTreasureData.uploadEventsWithCallback(\n  () =\u003e {\n    console.log(\"onSuccess is called.\");\n  },\n  (error, message) =\u003e {\n    console.log(`Error: ${error}`);\n    console.log(`Message: ${message}`);\n  }\n);\n```\n\nOr simply:\n\n```ts\nTreasureData.uploadEvents();\n```\n\n### Start/End session\n\n```ts\nTreasureData.startSession(\"table_name\");\n\nTreasureData.endSession(\"table_name\");\n```\n\nIf you want to handle the following case, use a pair of methods `startSession` and `endSession` for global session tracking.\n\n* User opens the application and starts session tracking using startSession\n* User moves to home screen and finishes the session using endSession\n* User reopens the application and restarts session tracking within default 10 seconds. But you want to deal with this new session as the same session.\n\n```ts\nTreasureData.setSessionTimeoutMilli(30 * 1000); // Default is 10 seconds\n\nTreasureData.startSession();\n\nTreasureData.endSession();\n```\n\nIn this case, you can get the current session ID using `getSessionId`.\n\n```ts\nTreasureData.getSessionId().then(sessionId =\u003e {\n  console.log(sessionId);\n});\n```\n\n### Detect if it's the first running\n\nYou can detect if it's the first running or not easily using `isFirstRun` method and then clear the flag with `clearFirstRun`.\n\n```ts\nTreasureData.isFirstRun()\n  .then(() =\u003e {\n    TreasureData.clearFirstRun();\n    TreasureData.uploadEvents();\n  })\n  .catch(error =\u003e {\n    console.log(error);\n  });\n```\n\n## About Error code\n\n`addEventWithCallback` and `uploadEventsWithCallback` methods call back `onError` with errorCode argument.\n\nThis argument is useful to know the cause type of the error. There are the following error codes.\n\n* `init_error` : The initialization failed.\n* `invalid_param` : The parameter passed to the API was invalid\n* `invalid_event` : The event was invalid\n* `data_conversion` : Failed to convert the data to/from JSON\n* `storage_error` : Failed to read/write data in the storage\n* `network_error` : Failed to communicate with the server due to network problem\n* `server_response` : The server returned an error response\n\n## Additional Configuration\n\n### Endpoint\n\n```ts\nTreasureData.initializeApiEndpoint(\"https://in.treasuredata.com\");\nTreasureData.initialize(\"your API key\");\n```\n\n### Encryption key\n\n```ts\nTreasureData.initializeEncryptionKey(\"hello world\");\n```\n\n### Default database\n\n```ts\nTreasureData.setDefaultDatabase(\"default_db\");\n```\n\n### Adding UUID of the device to each event automatically\n\n```ts\nTreasureData.enableAutoAppendUniqId();\n```\n\n### Adding an UUID to each event record automatically\n\n```ts\nTreasureData.enableAutoAppendRecordUUID();\n```\n\n### Adding device model information to each event automatically\n\n```ts\nTreasureData.enableAutoAppendModelInformation();\n```\n\n### Adding application package version information to each event automatically\n\n```ts\nTreasureData.enableAutoAppendAppInformation();\n```\n\n### Adding locale configuration information to each event automatically\n\n```ts\nTreasureData.enableAutoAppendLocaleInformation();\n```\n\n### Use server side upload timestamp\n\n```ts\nTreasureData.enableServerSideUploadTimestamp();\n// Add server side upload time as a customized column name\nTreasureData.enableServerSideUploadTimestamp(\"server_upload_time\");\n```\n\n### Enable/Disable debug log\n\n```ts\nTreasureData.enableLogging();\nTreasureData.disableLogging();\n```\n","funding_links":[],"categories":["Components"],"sub_categories":["Analytics"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquipper%2Freact-native-td","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquipper%2Freact-native-td","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquipper%2Freact-native-td/lists"}