Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yahoo/react-i13n
A performant, scalable and pluggable approach to instrumenting your React application.
https://github.com/yahoo/react-i13n
instrumentation react ui web
Last synced: 7 days ago
JSON representation
A performant, scalable and pluggable approach to instrumenting your React application.
- Host: GitHub
- URL: https://github.com/yahoo/react-i13n
- Owner: yahoo
- License: other
- Created: 2015-05-22T20:37:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-21T13:54:22.000Z (about 2 months ago)
- Last Synced: 2024-10-23T15:13:36.323Z (about 2 months ago)
- Topics: instrumentation, react, ui, web
- Language: JavaScript
- Homepage:
- Size: 2.54 MB
- Stars: 382
- Watchers: 23
- Forks: 42
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-react-cn - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application (Uncategorized / Uncategorized)
- awesome-react-components-all - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Uncategorized / Uncategorized)
- awesome-react-components - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Code Design / Data Store)
- awesome-react - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application
- awesome-learning-resources - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application (Uncategorized / Uncategorized)
- awesome-list - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Code Design / Data Store)
- awesome-react-components - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Code Design / Data Store)
- awesome-react-components - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Code Design / Data Store)
- awesome-react-components - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Code Design / Data Store)
- best-of-react - GitHub - 15% open ยท โฑ๏ธ 29.04.2024): (State Management)
- fucking-awesome-react-components - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. (Code Design / Data Store)
- awesome-react - react-i13n - A performant, scalable and pluggable approach to instrumenting your React application. ` ๐ 5 days ago` (React [๐](#readme))
README
# react-i13n
[![npm version](https://badge.fury.io/js/react-i13n.svg)](http://badge.fury.io/js/react-i13n)
![Build Status](https://github.com/yahoo/react-i13n/actions/workflows/node.js.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/yahoo/react-i13n/badge.svg?branch=master&service=github)](https://coveralls.io/github/yahoo/react-i13n?branch=master)`react-i13n` provides a performant, scalable and pluggable approach to instrumenting your React application.
Typically, you have to manually add instrumentation code throughout your application, e.g., hooking up `onClick` handlers to the links you want to track. `react-i13n` provides a simplified approach by letting you define the data model you want to track and handling the beaconing for you.
`react-i13n` does this by building an [instrumentation tree](#i13n-tree) that mirrors your applications React component hierarchy. All you have to do is leverage our [React component](./docs/guides/integrateWithComponents.md) to denote which components should fire the tracking events.
## Features
* **i13n tree** - Automated [instrumentation tree](#i13n-tree) creation that mirrors your applications React component hierarchy.
* **React integration** - Provides a [createI13nNode](./docs/api/createI13nNode.md#createi13nnodecomponent-options) component that easily integrate with your application.
* **Pluggable** - A pluggable interface lets you integrate any data analytics library (i.e. Google Analytics, Segment, etc). Take a look at the [available plugins](#available-plugins).
* **Performant** - Tracking data (`i13nModel`) can be a plain JS object or custom function. This means you can [dynamically change tracking data](./docs/guides/integrateWithComponents.md#dynamic-i13n-model) without causing unnecessary re-renders.
* **Adaptable** - If you are using an isomorphic framework (e.g. [Fluxible](http://fluxible.io)) to build your app, you can easily [change the tracking implementation](./docs/guides/createPlugins.md) on the server and client side. For example, to track page views, you can fire an http request on server and xhr request on the client.
* **Optimizable** - We provide an option to enable viewport (integrating [subscribe-ui-event](https://github.com/yahoo/subscribe-ui-event)) checking for each `I13nNode`. Which means that data will only be beaconed when the node is in the viewport. This reduces the network usage for the user and provides better tracking details.
* **Auto Scan Links** - Support [auto scan links](./docs/api/createI13nNode.md) for the cases you are not able to replace the component you are using to get it tracked, e.g., if you have dependencies or you are using `dangerouslySetInnerHTML`. We scan the tags you define on client side, track them and build nodes for them in i13n tree.## Install
```
npm install react-i13n --save
```## Runtime Compatibility
react-i13n is written with ES2015 in mind and should be used along with polyfills
for features like [`Promise`][Promise] and [`Object.assign`][objectAssign]
in order to support all browsers and older versions of Node.js. We recommend using [Babel][babel].[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[objectAssign]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
[babel]: https://babeljs.io/## Usage
* Choose the appropriate [plugin](#available-plugins).
* Use the [setupI13n](./docs/api/setupI13n.md) utility to wrap your application component.
* Define your instrumentation data and [integrate with your components](./docs/guides/integrateWithComponents.md)
* (Optionally) follow the [event system](./docs/guides/eventSystem.md) if you want to fire events manually.```js
import React, { Component } from 'react';
import {
ReactI13n,
createI13nNode,
setupI13n
} from 'react-i13n';
import somePlugin from 'some-i13n-plugin'; // a plugin for a certain instrumentation mechanism// create a i13n anchor for link tracking
const I13nAnchor = createI13nNode('a', {
isLeafNode: true,
bindClickEvent: true,
follow: true
});class DemoApp extends Component {
componentDidMount () {
// fire a custom event
this.props.i13n.executeEvent('pageview', {});
}render() {
...
// this link will be tracked, and the click event handlers provided by the plugin will get the model data as
// {site: 'foo', action: 'click', label: 'foo'}
}
};const I13nDempApp = setupI13n(DemoApp, {
rootModelData: { site: 'foo' },
isViewportEnabled: true
}, [somePlugin]);// then you could use I13nDemoApp to render you app
```## Available Plugins
* [react-i13n-ga](https://github.com/kaesonho/react-i13n-ga) - Google Analytics plugin
* [react-i13n-mixpanel](https://github.com/adlenafane/react-i13n-mixpanel) - Mixpanel plugin
* [react-i13n-segment](https://github.com/adlenafane/react-i13n-segment) - Segment pluginOr follow our guide and [create your own](./docs/guides/createPlugins.md).
## I13n Tree
![I13n Tree](https://cloud.githubusercontent.com/assets/3829183/7980892/0b38eb70-0a60-11e5-8cc2-712ec42089fc.png)`react-i13n` builds the instrumentation tree by leveraging the React `context` feature. Each component can define a `i13nModel` prop that defines the data it needs to track. This approach is more performant, as it means you do not need additional DOM manipulation when you want to collect the tracking data values for sending out beacons.
Since the i13n data is defined at each level. Whenever you want to get the `i13nModel` for a certain node, `react-i13n` will traverse back up the tree to merge all the `i13nModel` information in the hierarchy. Since the tree is already built, you do not need extra DOM access, which is cheap and efficient.
## Performance
The performance has always been a topic we are working on, and yes it's an overhead to create an additional react component wrapping the link, the performance benchmark as below:
```
link-without-react-component x 131,232 ops/sec ยฑ1.08% (82 runs sampled)
link-wrapped-with-react-component x 111,056 ops/sec ยฑ1.55% (88 runs sampled)
link-wrapped-with-react-component-with-i13n-high-order-component x 64,422 ops/sec ยฑ1.95% (84 runs sampled)
```## Presentation
Take a look at [Rafael Martins' slides](http://www.slideshare.net/RafaelMartins21/instrumentation-talk-39547608) from a recent React meetup to understand more.## Debugging
Add `i13n_debug=1` to the request url, you will get the i13n model for each `i13n node` directly shown on the page. It shows the information for each model data and where the data inherits from.## Examples
* [react-i13n-flux-examples](https://github.com/kaesonho/react-i13n-flux-examples) - we forked the [flux examples](https://github.com/facebook/flux/tree/master/examples) and integrated `react-i13n` with it.
* [fluxible.io](http://fluxible.io/) - [fluxible](https://github.com/yahoo/fluxible) site integrating `react-i13n` and [react-i13n-ga](https://github.com/kaesonho/react-i13n-ga).## Set ENV during CI process
We check `process.env.NODE_ENV !== 'production'` to determine if we should do some action like print out warning message, that means it's recommended to use tools like `envify` as part of your build process to strip out non-production code for production build.### With Webpack
Use `DefinePlugin` to define the value for `process.env`.
```js
// Example of the webpack configuration:plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
...
]
```### With Browserify
Similar to webpack, you can also use `envify` to set process.env.NODE_ENV to the desired environment
```bash
$ browserify index.js -t [ envify --NODE_ENV production ] | uglifyjs -c > bundle.js```
## Testing
### Unit
* `grunt unit` to run unit tests
* `grunt cover` to generate the istanbul coverage report### Functional
* debug locally:
* `grunt functional-debug`
* check functional testing result on `http://127.0.0.1:9999/tests/functional/page.html`
* run functional test on `saucelabs`:
* make sure you have a saucelab account setup, get the user id ane the access key
* setup [sauce-connect](https://docs.saucelabs.com/reference/sauce-connect/)
* `SAUCE_USERNAME={id} SAUCE_ACCESS_KEY={accessKey} grunt functional`## License
This software is free to use under the Yahoo Inc. BSD license.
See the [LICENSE file](./LICENSE.md) for license text and copyright information.