npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-td

v0.9.3

Published

An unofficial React Native SDK for Treasure Data.

Downloads

21

Readme

react-native-td CircleCI npm version

react-native-td is an unofficial React Native SDK for Treasure Data.

The module is a light-weight layer sitting on-top of the TreasureData SDK for both iOS and Android.

Installation

You can install react-native-td into your project in the following way.

npm install --save react-native-td
react-native link react-native-td

iOS configuration

If you haven't introduced cocoapods, install it and run pod init under ios/and make sure lines below are in Podfile.

+ pod 'React', :path => '../node_modules/react-native', :subspecs => [
+   'Core',
+   'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
+   'RCTText',
+   'RCTNetwork',
+   'RCTWebSocket', # needed for debugging
+ ]
+ pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
+ pod 'RNTreasureData', :path => '../node_modules/react-native-td'

Usage

Basically react-native-td imitates the interface of TreasureData iOS/Android SDK as close as possible.

Hence to know more detail check official documents below.

  • iOS: https://docs.treasuredata.com/articles/ios-sdk
  • Android: https://docs.treasuredata.com/articles/android-sdk

Instantiate with your API key

import TreasureData from "react-native-td";

TreasureData.initialize("your API key");

We recommend to use a write-only API key for the SDK. To obtain one, please:

  1. Login to the Treasure Data Console at http://console.treasuredata.com;
  2. Visit your Profile page at http://console.treasuredata.com/users/current;
  3. Insert your password under the 'API Keys' panel;
  4. 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.

Add a event to local buffer

To add an event to local buffer, you can call addEvent or addEventWithCallback API.

TreasureData.addEventWithCallback(
  { event: "event_name" },
  "database_name",
  "record_name",
  () => {
    console.log("onSuccess is called.");
  },
  (error, message) => {
    console.log(`Error: ${error}`);
    console.log(`Message: ${message}`);
  }
);

Or simply:

TreasureData.addEvent("database_name", "table_name", { event: "event_name" });

Upload buffered events to Treasure Data

To upload events buffered events to Treasure Data, you can call uploadEvents or uploadEventsWithCallback API.

TreasureData.uploadEventsWithCallback(
  () => {
    console.log("onSuccess is called.");
  },
  (error, message) => {
    console.log(`Error: ${error}`);
    console.log(`Message: ${message}`);
  }
);

Or simply:

TreasureData.uploadEvents();

Start/End session

TreasureData.startSession("table_name");

TreasureData.endSession("table_name");

If you want to handle the following case, use a pair of methods startSession and endSession for global session tracking.

  • User opens the application and starts session tracking using startSession
  • User moves to home screen and finishes the session using endSession
  • 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.
TreasureData.setSessionTimeoutMilli(30 * 1000); // Default is 10 seconds

TreasureData.startSession();

TreasureData.endSession();

In this case, you can get the current session ID using getSessionId.

TreasureData.getSessionId().then(sessionId => {
  console.log(sessionId);
});

Detect if it's the first running

You can detect if it's the first running or not easily using isFirstRun method and then clear the flag with clearFirstRun.

TreasureData.isFirstRun()
  .then(() => {
    TreasureData.clearFirstRun();
    TreasureData.uploadEvents();
  })
  .catch(error => {
    console.log(error);
  });

About Error code

addEventWithCallback and uploadEventsWithCallback methods call back onError with errorCode argument.

This argument is useful to know the cause type of the error. There are the following error codes.

  • init_error : The initialization failed.
  • invalid_param : The parameter passed to the API was invalid
  • invalid_event : The event was invalid
  • data_conversion : Failed to convert the data to/from JSON
  • storage_error : Failed to read/write data in the storage
  • network_error : Failed to communicate with the server due to network problem
  • server_response : The server returned an error response

Additional Configuration

Endpoint

TreasureData.initializeApiEndpoint("https://in.treasuredata.com");
TreasureData.initialize("your API key");

Encryption key

TreasureData.initializeEncryptionKey("hello world");

Default database

TreasureData.setDefaultDatabase("default_db");

Adding UUID of the device to each event automatically

TreasureData.enableAutoAppendUniqId();

Adding an UUID to each event record automatically

TreasureData.enableAutoAppendRecordUUID();

Adding device model information to each event automatically

TreasureData.enableAutoAppendModelInformation();

Adding application package version information to each event automatically

TreasureData.enableAutoAppendAppInformation();

Adding locale configuration information to each event automatically

TreasureData.enableAutoAppendLocaleInformation();

Use server side upload timestamp

TreasureData.enableServerSideUploadTimestamp();
// Add server side upload time as a customized column name
TreasureData.enableServerSideUploadTimestamp("server_upload_time");

Enable/Disable debug log

TreasureData.enableLogging();
TreasureData.disableLogging();