0.1.7 • Published 6 years ago

react-amplitude v0.1.7

Weekly downloads
186
License
Apache-2.0
Repository
github
Last release
6 years ago

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);
ValueNotes
apiKeyString. Required.
userIdString. Optional.
configObject. Optional.
callbackFunction. Optional.

Amplitude.logEvent(eventName, eventProperties, callback)

Log an event to Amplitude.

Example
Amplitude.logEvent(eventName, eventProperties, cb);
ValueNotes
eventNameString. Required.
eventPropertiesObject. Optional.
callbackFunction. Optional.

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

Log an event to Amplitude.

Example
Amplitude.logEventWithTimestamp(eventName, eventProperties, timestamp, cb);
ValueNotes
eventNameString. Required.
eventPropertiesObject. Optional.
timestampNumber. Optional.
callbackFunction. 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);
ValueNotes
userIdString. Required.

Amplitude.setUserProperties(userProps)

Track user properties

Example
Amplitude.setUserProperties(userProps);
ValueNotes
userPropsobject. 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);
ValueNotes
idObjobject. Required.
callbackFunction. 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

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.6

7 years ago

0.0.5-b

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago