@factor/plugin-server-analytics
Version:
Analytics for your server and endpoints.
50 lines (32 loc) • 1.19 kB
Markdown
This plugin adds tracking of server activity via Google Analytics.
```bash
npm add @factor/plugin-server-analytics
```
```js
// factor-settings.js
export default {
serverAnalytics: {
trackingId: "", // GA tracking ID - ua-xxxx-xx
trackEndpointHits: true, // Send endpoint request events (track each endpoint request)
},
}
```
By default this plugin will track endpoint requests with the following:
- **event**: 'endpointRequest'
- **action**: the `id` of the endpoint
- **method**: the method called
To send a custom event, all that you need to do is send a get/post request to the `/__track_event__` endpoint.
The query parameters passed should event, action and/or label.
_Example:_
```js
import axios from "axios"
axios.get("/__track_event__?event=myEvent&action=theAction&label=theLabel")
```
Because server events are triggered from Node, they will show as "non-browser" traffic in analytics (no browser or language set). Keep this in mind when creating filters to screen out bot traffic, etc..