614 GitHub stars and counting — nfl/react-metrics is a JavaScript project TopGit is tracking across repositories on the platform. An analytics module for React
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
React Metrics depends on Promise to be available in browser. If your application support the browser which doesn't support Promise, please include the polyfill.
Getting Started
1. Configure Metrics
Refer to the docs for more information on configuration.
// Application.js
import {metrics} from "react-metrics";
const config = {
vendors: [{
name: "Google Analytics",
api: new GoogleAnalytics({
trackingId: "UA-********-*"
})
}],
pageViewEvent: "pageLoad",
pageDefaults: () => {
return {
siteName: "My Web Site",
...
};
}
}
2. Wrap Application Level Component
Compose your top level application component with metrics in order to provide metrics to all components and automatically enable page view tracking.
react-metrics does not automatically supply any vendor analytics. You need to integrate with an analytics vendor to actually track something for reporting.
Refer to Vendor Examples for Omniture, Google Analytics and other implementations.
Also check out the awesome segmentio library which provides a lot of third party analytics vendors.
Advanced Usage
Override Default Page View Tracking
Use the @exposeMetrics decorator and willTrackPageView() methods on a route-handling component to override the default page view tracking behavior and pageDefaults data.
// PageComponent.js
// Must be a "route handling" component: <Route path="my-page" component={PageComponent}/>
import {exposeMetrics, PropTypes} from "react-metrics";
@exposeMetrics
class PageComponent extends React.Component {
static contextTypes = {
metrics: PropTypes.metrics
}
static willTrackPageView() {
// first, suppress the automatic call.
return false;
}
componentDidMount() {
const {value1, value2} = this.props;
this.context.metrics.pageView({value1, value2});
}
render () {
...
}
}
Example: add custom data to automatic page view tracking.
// PageComponent.js "route-handler
// A route handling component: <Route path="my-page" component={PageComponent}/>
import {exposeMetrics} from "react-metrics";
@exposeMetrics
class PageComponent extends React.Component {
static willTrackPageView(routeState) {
// return a promise that resolves to custom data.
return yourPromise.then(data => {
// data gets merged with `pageDefaults` object
return data;
});
}
render () {
...
}
}
Imperative Custom Event Tracking
Use this.context.metrics.track() to trigger custom event tracking as an alternative to declarative custom link tracking.
Define metrics as a contextType in your component and trigger custom track events using metrics.track().
react-metrics provides a low level factory API; this is convenient for exposing an instance of the metrics API outside of a React component.
Use createMetrics to create a metrics instance and expose the metrics.api.
No homepage URL was recorded for nfl/react-metrics in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Is nfl/react-metrics open source?
Yes — nfl/react-metrics ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/nfl/react-metrics.
What is nfl/react-metrics?
nfl/react-metrics (nfl/react-metrics) is a JavaScript project on GitHub. From the project's own README: An analytics module for React
What license does nfl/react-metrics use?
nfl/react-metrics is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
Where do I read more about nfl/react-metrics?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/nfl/react-metrics is the definitive source.
Read full README in the tab above.
Still deciding about react-metrics?
One click hands the question to an AI along with this page — see what it says about react-metrics.