react-amplitude
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/react-amplitude package

0.1.7 • Public • Published

react-amplitude

React Amplitude Analytics

npm version npm downloads

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.

Installation

With yarn:

yarn add react-amplitude

With npm:

npm install react-amplitude --save

Usage

Initializing:

import React from 'react';
import ReactDOM from 'react-dom';
 
...
import Amplitude from 'react-amplitude';
Amplitude.init('YOUR_UNIQUE_TRACKING_CODE');
...
 
document.addEventListener('DOMContentLoaded', function() {
  ReactDOM.render(<App />, document.getElementById('app'));
});
 

API

Amplitude.init(apiKey, userId, config, callback)

Must be initialized using this function before any of the other tracking functions will record any data.

Example
Amplitude.init(apiKey, userId, config, cb);
Value Notes
apiKey String. Required.
userId String. Optional.
config Object. Optional.
callback Function. Optional.

Amplitude.logEvent(eventName, eventProperties, callback)

Log an event to Amplitude.

Example
Amplitude.logEvent(eventName, eventProperties, cb);
Value Notes
eventName String. Required.
eventProperties Object. Optional.
callback Function. Optional.

Amplitude.logEventWithTimestamp(eventName, eventProperties, timestamp, callback)

Log an event to Amplitude.

Example
Amplitude.logEventWithTimestamp(eventName, eventProperties, timestamp, cb);
Value Notes
eventName String. Required.
eventProperties Object. Optional.
timestamp Number. Optional.
callback Function. Optional.

Amplitude.resetUserId()

Remove user tracking (e.g. on logging out).

Example
Amplitude.resetUserId();

Amplitude.setUserId(userId)

Track users through a unique user id.

Example
Amplitude.setUserId(userId);
Value Notes
userId String. Required.

Amplitude.setUserProperties(userProps)

Track user properties

Example
Amplitude.setUserProperties(userProps);
Value Notes
userProps object. Required.

Amplitude.clearUserProperties()

Clear user properties (careful, this is irreversible!)

Example
Amplitude.clearUserProperties();

Amplitude.getSessionId()

Returns current session id

Example
Amplitude.getSessionId();

Amplitude.identify(idObj, callback)

Send an identify call containing user property operations to Amplitude servers

Example
Amplitude.identify(idObj, cb);
Value Notes
idObj object. Required.
callback Function. Optional.

Amplitude.isNewSession()

Returns if a new session was created at init

Example
Amplitude.isNewSession();

Development

git clone https://github.com/rorygarand/react-amplitude.git
yarn install
npm run build

Acknowledgements

Contributors

Package Sidebar

Install

npm i react-amplitude

Weekly Downloads

143

Version

0.1.7

License

Apache-2.0

Unpacked Size

49.1 kB

Total Files

10

Last publish

Collaborators

  • rorygarand