Skip to content

Script (CDN)

No npm, no build step, no fuss. Drop a <script> tag into your <head> and you are done.

<script
defer
src="https://forge.codeserk.es/cdn/stats.js"
data-base-url="https://api-events.forge.codeserk.es"
data-sdk="YOUR_SDK_KEY"
></script>

Use defer so the script loads in parallel and never blocks rendering.

Page views are tracked automatically via trackView. The script detects the context it is running in and adapts:

  • Astro - listens to astro:page-load to support View Transitions
  • SPA - patches history.pushState and listens to popstate
  • Plain HTML - fires once on load

No extra configuration needed for any of these - it just works.

Add data-errors to also capture uncaught errors and unhandled rejections:

<script
defer
src="https://forge.codeserk.es/cdn/stats.js"
data-base-url="https://api-events.forge.codeserk.es"
data-sdk="YOUR_SDK_KEY"
data-errors
></script>

All configuration is via data-* attributes on the script tag:

AttributeRequiredDescription
data-base-urlyesBase URL of the Forge Stats API
data-sdkyesBase64-encoded SDK key
data-errorsnoEnable global error capture when present
src/layouts/Layout.astro
<head>
<script
is:inline
defer
src="https://forge.codeserk.es/cdn/stats.js"
data-base-url="https://api-events.forge.codeserk.es"
data-sdk="YOUR_SDK_KEY"
data-errors
></script>
</head>

is:inline is required to prevent Astro from bundling the script, so that document.currentScript works correctly.

Looking for framework-specific setup? Check the integrations section: