Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.53 KB

README.md

File metadata and controls

47 lines (36 loc) · 1.53 KB

browser-analytics-capture-js

A tiny (4.9kb gzipped & minified) JS library to capture analytics in the browser and send them to a server. An example of using Cloudflare Workers for processing this data and adding it to BigQuery has also been open-sourced here.

Usage

For logging pageviews and engagement metrics

<script src="/path/to/ingest.js"></script>
<script>document.addEventListener("DOMContentLoaded", fsdIngest('YOUR_CLIENT_ID'));</script>

For logging events

After you've called fsdIngest, for updating the count of numeric events

<script>document.addEventListener("DOMContentLoaded", fsdUpdateEvent('EVENT_NAME'));</script> //

For capturing text based events

<script>document.addEventListener("DOMContentLoaded", fsdUpdateEvent('EVENT_NAME', 'EVENT_VALUE', 'text'));</script> //

What analytics does it capture?

Engagement Metrics

  • Active time spent by the user on a page
  • Maximum scroll depth by the user on the page

Unique identification and device metrics

  • User UUID (randomly generated)
  • Session ID (randomly generated)
  • URL Path
  • Screen Resolution
  • Whether or not the user is on mobile

Long-term usage metrics

  • Lifetime number of pageviews
  • Lifetime number of session
  • Number of hits per session
  • Whether the user has been active on the site recently

Referrer details

Any other metrics you want to capture

Comptability

Works with all browsers that support ES6