This is a JavaScript module that can be used to include Amplitude Analytics tracking code in a website or app that uses React for its front-end codebase.
Feel free to file issues, ideas and pull requests against this repo.
With yarn:
yarn add react-amplitudeWith npm:
npm install react-amplitude --saveInitializing:
import React from 'react';
import ReactDOM from 'react-dom';
...
import Amplitude from 'react-amplitude';
Amplitude.initialize('YOUR_UNIQUE_TRACKING_CODE');
...
document.addEventListener('DOMContentLoaded', function() {
ReactDOM.render(<App />, document.getElementById('app'));
});Must be initialized using this function before any of the other tracking functions will record any data.
Amplitude.initialize('YOUR_UNIQUE_TRACKING_CODE');| Value | Notes |
|---|---|
| gaTrackingID | String. Required. |
Log an event to Amplitude.
Amplitude.event('EVENT_NAME_TO_BE_LOGGED', eventProperties);| Value | Notes |
|---|---|
| eventName | String. Required. |
| eventProperties | Object. Optional. |
Remove user tracking (e.g. on logging out).
Amplitude.resetUserId();Track users through a unique user id.
Amplitude.setUserId(userId);| Value | Notes |
|---|---|
| userId | String. Required. |
git clone https://github.com/rorygarand/react-amplitude.git
yarn install
npm run build