# LC Analytics

[![NPM version](https://img.shields.io/npm/v/@loyalty-corp/analytics.svg?style=fla)](http://npmjs.org/gh-jira)
[![NPM downloads](http://img.shields.io/npm/dm/@loyalty-corp/analytics.svg?style=flat)](http://npmjs.org/gh-jira)
[![Codeship](https://img.shields.io/codeship/918898c0-f367-0135-fd72-3e09b2bc026f.svg)](https://app.codeship.com/projects/272366)

> Loyalty Corp Analytics wrapper

We wrapped the most used analytics providers for you. Enjoy!

## Usage

> Before start, make sure you load the providers SDKs. This library rely on their global variables.

1.  Install it via NPM: `yarn add @loyalty-corp/analytics`
2.  Configure the providers you want to use:

```js
import { Analytics } from "@loyaltycorp/analytics";

const analytics = new Analytics({
  use: ["segment", "ensighten"]
});
```

3.  Start tracking:

```js
analytics.page();
analytics.track("Added to Cart", {
  cart: {
    currency: "AUD",
    total: 100,
    products: [{ name: "Optus Benefit Card", price: 50, quantity: 2 }]
  }
});
analytics.identify("ciro@loyaltycorp.com.au");
```

## API

| Method   | Usage                                                                        |
| -------- | ---------------------------------------------------------------------------- |
| Track    | `analytics.track(eventName: string, eventProperties: any, isLazy?: boolean)` |
| Identify | `analytics.identify(userId: string, userProperties: any, isLazy?: boolean)`  |
| Page     | `analytics.page(name?: string, customProperties?: any)`                      |

The `isLazy` property saves `track` and `identify` calls and trigger them in the next page load.

## Providers

| Provider  | Name      |
| --------- | --------- |
| Segment   | segment   |
| Ensighten | ensighten |

## Team

Built with ❤️ by the [Loyalty Corp](https://loyaltycorp.com.au) team.
