@factor/plugin-server-analytics

Analytics for your server and endpoints.

Usage no npm install needed!

<script type="module">
  import factorPluginServerAnalytics from 'https://cdn.skypack.dev/@factor/plugin-server-analytics';
</script>

README

Factor Server Analytics

This plugin adds tracking of server activity via Google Analytics.

Install

npm add  @factor/plugin-server-analytics

Settings

// factor-settings.js
export default {
  serverAnalytics: {
    trackingId: "", // GA tracking ID - ua-xxxx-xx
    trackEndpointHits: true, // Send endpoint request events (track each endpoint request)
  },
}

Usage

Tracking endpoint requests

By default this plugin will track endpoint requests with the following:

  • event: 'endpointRequest'
  • action: the id of the endpoint
  • method: the method called

Triggering Custom Server Events

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:

import axios from "axios"

axios.get("/__track_event__?event=myEvent&action=theAction&label=theLabel")

A Note On Traffic Filtering

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..