# Getting Started (ngrx)

In a nutshell: for each analytics event, pick out an event definition (listed in each target's docs) and map it to an action. The map should be an object with the action type as a key, and event definition as the value. Then, you simply provide your target and the events map to Redux Beacon's `createMetaReducer` function.

## Step 1

Choose a target, and follow the setup instructions.

* [GoogleAnalytics: Setup](../index/google-analytics#setup)
* [GoogleAnalyticsGtag: Setup](../index/google-analytics-gtag#setup)
* [GoogleTagManager: Setup](https://rangle.gitbook.io/redux-beacon/index/google-tag-manager#setup)
* [Segment: Setup](../index/segment#setup)
* [Amplitude: Setup](../index/amplitude#setup)
* React Native:
  * [GoogleAnalytics: Setup](../index/react-native-google-analytics#setup)
  * [GoogleTagManager: Setup](../index/react-native-google-tag-manager#setup)
  * [Segment: Setup](../index/react-native-segment#setup)

{% hint style="info" %}
Don't see the target you need? Follow the instructions [here](../examples-and-recipes#how-to-create-own-target.md) to build your own.
{% endhint %}

## Step 2

Decide what you want to track and pick out the corresponding event definition:

* [GoogleAnalytics: Event Definitions](../index/google-analytics#event-definitions)
* [GoogleAnalyticsGtag: Event Definitions](../index/google-analytics-gtag#event-definitions)
* [GoogleTagManager: Event Definitions](https://rangle.gitbook.io/redux-beacon/index/google-tag-manager#event-definitions)
* [Segment: Event Definitions](../index/segment#event-definitions)
* [Amplitude: Event Definitions](../index/amplitude#event-definitions)
* React Native:
  * [GoogleAnalytics: Event Definitions](../index/react-native-google-analytics#event-definitions)
  * [GoogleTagManager: Event Definitions](../index/react-native-google-tag-manager#event-definitions)
  * [Segment: Event Definitions](../index/react-native-segment#event-definitions)

## Step 3

Complete the event definition by filling in the object properties, and match it to an action.

For example, say you want to intercept a `PLAY_VIDEO` action and track it as a Google Analytics event:

```javascript
import { createMetaReducer, EventsMap } from 'redux-beacon';
import GoogleAnalytics, { trackEvent } from '@redux-beacon/google-analytics';

import logger from '@redux-beacon/logger'; // optional

// Copy & paste the event definition you chose in step 2, then fill it in.
const emitVideoPlayed = trackEvent(action => ({
  category: 'Videos',
  action: action.type,
}));

// Match the event definition to a Redux action:
const eventsMap: EventsMap = {
  'PLAY_VIDEO': emitVideoPlayed,
};

// Create the meta reducer
const ga = GoogleAnalytics();
const gaMetaReducer = createMetaReducer(eventsMap, ga, { logger });
```

* [GoogleAnalytics: Usage](../index/google-analytics#usage)
* [GoogleAnalyticsGtag: Usage](../index/google-analytics-gtag#usage)
* [GoogleTagManager: Usage](https://rangle.gitbook.io/redux-beacon/index/google-tag-manager#usage)
* [Segment: Usage](../index/segment#usage)
* [Amplitude: Usage](../index/amplitude#usage)
* React Native:
  * [GoogleAnalytics: Usage](../index/react-native-google-analytics#usage)
  * [GoogleTagManager: Usage](../index/react-native-google-tag-manager#usage)
  * [Segment: Usage](../index/react-native-segment#usage)

## Step 4

Follow the instructions [here](https://github.com/ngrx/platform/blob/master/docs/store/api.md#meta-reducers) to apply the meta reducer to your store.

## Next Steps

### Track More Events:

Repeat steps [2](#step-2) and [3](#step-3) for every event you want to track. In a nutshell: 1. Find the event definition for the thing you want to track. 2. Match the event definition to a Redux action then complete the event definition.

### Decide Where to put Analytics Logic:

As the number of events you track grows, it might make sense to move your event definitions and events map into their own files. Redux Beacon has no requirements on where these are kept. Have a discussion with your team on how you'd like to organize your app's analytics logic.

### Check Out the Recipes:

We have a number of recipes to get you started with Redux Beacon. Check them out [here](examples-and-recipes).

### Check Out the Extensions:

We have extensions for logging and for buffering analytics events offline. Check them out [here](index-2).
