# Amplitude

* [Setup](/redux-beacon/index/amplitude.md#setup)
* [Usage](/redux-beacon/index/amplitude.md#usage)
* [Event Definitions](/redux-beacon/index/amplitude.md#event-definitions)

## Setup

1. Sign up for Amplitude at <http://amplitude.com> and make a note of your API key.
2. Install [amplitude-js](https://www.npmjs.com/package/amplitude-js): `npm install --save amplitude-js`.
3. Install the target:

   ```bash
    npm install --save @redux-beacon/amplitude
   ```

## Usage

```javascript
import amplitude from 'amplitude-js';
import Amplitude from '@redux-beacon/amplitude';

// Create or import an events map.
// See "getting started" pages for instructions.

// initialise amplitude
const amplitudeInstance = amplitude.getInstance();
amplitudeInstance.init('YOUR_API_KEY')

const target = Amplitude({ instance: amplitudeInstance });

const amplitudeMiddleware = createMiddleware(eventsMap, target);
const amplitudeMetaReducer = createMetaReducer(eventsMap, target);
```

## Event Definitions

* [`event`](/redux-beacon/index/amplitude.md#event)
* [`userId`](/redux-beacon/index/amplitude.md#userid)
* [`logout`](/redux-beacon/index/amplitude.md#logout)
* [`userProperties`](/redux-beacon/index/amplitude.md#userproperties)

Don't see your event listed? Please submit a pull request to the [Redux Beacon repository](https://github.com/rangle/redux-beacon) with the missing event. Use the source of the existing `event-helpers` to guide your work. If you need any support feel free to make the pull request with all you're able to do. We can fill in the gaps from there.

### event

#### Docs:

* <https://amplitude.zendesk.com/hc/en-us/articles/115001361248#tracking-events>
* <https://amplitude.zendesk.com/hc/en-us/articles/115001361248#setting-event-properties>

```javascript
import { logEvent } from '@redux-beacon/amplitude';

const event = logEvent((action, prevState, nextState) => {
  return {
    type: /* fill me in */,
    properties: /* (optional) */,
  };
});
```

### userId

#### Docs:

<https://amplitude.zendesk.com/hc/en-us/articles/115001361248#setting-custom-user-ids>

```javascript
import { setUserId } from '@redux-beacon/amplitude';

const event = setUserId((action, prevState, nextState) => {
  return /* (user Id) fill me in */
});
```

### logout

#### Docs:

<https://amplitude.zendesk.com/hc/en-us/articles/115001361248#logging-out-and-anonymous-users>

```javascript
import { logout } from '@redux-beacon/amplitude';

const event = logout();
```

### userProperties

#### Docs:

<https://amplitude.zendesk.com/hc/en-us/articles/115001361248#setting-multiple-user-properties>

```javascript
import { setUserProperties } from '@redux-beacon/amplitude';

const event = setUserProperties((action, prevState, nextState) => {
  return {
   [/* property key */]: /* property value */,
  };
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rangle.gitbook.io/redux-beacon/index/amplitude.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
