Fair Analytics client JavaScript API
The quickest way to integrate Fair Analytics in your app
Install
This project uses node and npm. Go check them out if you don't have them locally installed.
$ npm i fair-analytics-client-api
Then with a module bundler like rollup or webpack, use as you would anything else:
// using ES6 modules
import fairAnalytics from 'fair-analytics-client-api'
// using CommonJS modules
var fairAnalytics = require('fair-analytics-client-api')
The UMD build is also available on unpkg:
<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
.
Usage
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)
})
Tests
$ npm test
Change Log
This project adheres to Semantic Versioning.
Every release, along with the migration instructions, is documented in the CHANGELOG.md file.
License
MIT