fair-analytics-client-api
Version:
The Fair Analytics client API
81 lines (57 loc) • 2.94 kB
Markdown
> The quickest way to integrate [Fair Analytics](https://github.com/vesparny/fair-analytics) in your app
[](https://travis-ci.org/vesparny/fair-analytics-client-api)
[](https://codecov.io/github/vesparny/fair-analytics-client-api)
[](https://david-dm.org/vesparny/fair-analytics-client-api)
[](https://www.npmjs.com/package/fair-analytics-client-api)
[](https://npm-stat.com/charts.html?package=fair-analytics-client-api&from=2017-04-01)
[](http://standardjs.com/)
[](https://github.com/vesparny/fair-analytics-client-api/blob/master/LICENSE)
[](https://unpkg.com/fair-analytics-client-api/dist/)
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.
```sh
$ npm i fair-analytics-client-api
```
Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else:
```javascript
// using ES6 modules
import fairAnalytics from 'fair-analytics-client-api'
// using CommonJS modules
var fairAnalytics = require('fair-analytics-client-api')
```
The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):
```html
<script src="https://unpkg.com/fair-analytics-client-api/dist/fair-analytics-client-api.umd.js"></script>
```
You can find the library on `window.fairAnalytics`.
```js
import fairAnalytics from 'fair-analytics-client-api'
// create a fa instance
const fa = fairAnalytics({
url: 'https://fa.yoursite.com' // the URL of your hosted Fair Analytics instance
})
// track events
fa.send({
event: 'pageView', // event is mandatory and can be anything
pathname: window.location.pathname
})
.then(res => {
if (res.ok) {
console.log('success')
}
})
.catch(err => {
console.error(err.message)
})
```
```sh
$ npm test
```
This project adheres to [Semantic Versioning](http://semver.org/).
Every release, along with the migration instructions, is documented in the [CHANGELOG.md](https://github.com/vesparny/fair-analytics-client-api/blob/master/CHANGELOG.md) file.
MIT