# shore-tracker

> A generic module to track user actions inside Shore

Latest version **1.0.0** (published 2016-09-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install shore-tracker
pnpm add shore-tracker
yarn add shore-tracker
bun add shore-tracker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-09-09 |
| First published | 2016-09-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shore GmbH |
| Maintainers | dejanr |

## Links

- npm: https://www.npmjs.com/package/shore-tracker
- npm.io page: https://npm.io/package/shore-tracker

## Recent versions

- 1.0.0 (latest) — 2016-09-09

## README

# shore-tracker

A generic module to track user actions inside Shore

## Install

```
npm install @shore/shore-tracker
```

## Usage

Ensure you are in an ES6 environment, if not use polyfills!

### Creating the client
```javascript
import { initialize } from '@shore/shore-tracker';

// 1. Initializing the tracker
initialize({
  trackMethod: analytics.track // The track method of some third party analytics tracker
});

```

### Creating and using as Redux middileware

```javascript
import { createReduxMiddleware } from '@shore/shore-tracker';
import actionTypes from 'constants/action-types';
const { HIDE, SHOW, SAVE } = actionTypes.currentCustomer.additionalAttributes;

const Shore = window.Shore;

// Sample helper method to generate event data
const generateTrackerData = eventName => (state, actionPayload) => ({
  eventName,
  eventPayload: {
    ...actionPayload,
    ...{
      'Merchant uuid': Shore.merchant_uuid,
      'Merchant account id': Shore.merchant_account_id,
      'Merchant name': Shore.merchantName,
      'Merchant account name': Shore.merchant_account_name,
      name: Shore.merchant_account_full_name,
      phone: Shore.merchantPhone,
      website: Shore.merchantWebsite,
    },
  },
});

// This map tells which redux action will be track with what data
const mapping = {
  [HIDE]: generateTrackerData('customer_detail_additional_attributes_hide'),
  [SHOW]: generateTrackerData('customer_detail_additional_attributes_show'),
  [SAVE]: generateTrackerData('customer_detail_additional_attributes_save')
};

// Creating the middleware
const trackerMiddleware = createReduxMiddleware(mapping);

// Then when creating redux store you can use it like so 
let store = createStore(
  reducers,
  applyMiddleware(trackerMiddleware)
)

// Then redux will track the actions mentioned inside the mapping
```

### TODO
  - Add tests
  - Add documentation for how to use it for non redux app

---
_Source: https://npm.io/package/shore-tracker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
