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.
<script src="/path/to/ingest.js"></script>
<script>document.addEventListener("DOMContentLoaded", fsdIngest('YOUR_CLIENT_ID'));</script>
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> //
- Active time spent by the user on a page
- Maximum scroll depth by the user on the page
- User UUID (randomly generated)
- Session ID (randomly generated)
- URL Path
- Screen Resolution
- Whether or not the user is on mobile
- Lifetime number of pageviews
- Lifetime number of session
- Number of hits per session
- Whether the user has been active on the site recently
Works with all browsers that support ES6