Analytics
Lightweight, privacy-friendly analytics for your SaaS. Track page views and custom events without cookies. Includes automatic UTM parameter capture, device/browser detection, and country-level geo data.
How it works
Section titled “How it works”- Add the analytics script to your site or call the API directly
- Page views are tracked automatically (including SPA navigation)
- View dashboards with top pages, referrers, countries, and devices
Tracking script
Section titled “Tracking script”Add this script tag to your site for automatic page view tracking:
<script defer data-project="pk_your_api_key" data-api="https://saasmaker-api.sarthakagrawal927.workers.dev" src="https://unpkg.com/@saas-maker/analytics-sdk/dist/index.global.js"></script>The script automatically:
- Tracks initial page views
- Handles SPA navigation (pushState / replaceState / popstate)
- Captures UTM parameters from the URL
- Respects
Do Not Trackbrowser setting - Sends screen width, referrer, and user agent
Custom events
Section titled “Custom events”After the script loads, use the global sm function:
// Track a custom eventsm('signup_completed');
// Track with propertiessm('plan_upgraded', { plan: 'pro', value: 49 });You can also queue events before the script loads:
window.sm = window.sm || { q: [] };sm.q.push(['button_clicked', { id: 'cta-hero' }]);API endpoints
Section titled “API endpoints”Track an event
Section titled “Track an event”POST /v1/analytics/eventsAuth: API Key
curl -X POST https://saasmaker-api.sarthakagrawal927.workers.dev/v1/analytics/events \ -H "Content-Type: application/json" \ -H "X-Project-Key: pk_abc123" \ -d '{ "name": "page_view", "url": "https://myapp.com/pricing", "referrer": "https://google.com", "utm_source": "google", "utm_medium": "cpc", "screen_width": 1440, "properties": { "variant": "B" } }'| Field | Type | Required | Description |
|---|---|---|---|
name | string | No | Event name (defaults to page_view) |
url | string | No | Page URL |
referrer | string | No | Referrer URL |
utm_source | string | No | UTM source |
utm_medium | string | No | UTM medium |
utm_campaign | string | No | UTM campaign |
screen_width | number | No | Viewport width |
properties | object | No | Custom event properties |
Dashboard overview
Section titled “Dashboard overview”GET /v1/analytics/overview?project_id=...&period=30dAuth: Session Token
Returns page views, unique visitors, top page, and top referrer.
Period options: 7d, 30d (default), 90d
Top pages
Section titled “Top pages”GET /v1/analytics/pages?project_id=...&period=30dAuth: Session Token
Top referrers
Section titled “Top referrers”GET /v1/analytics/referrers?project_id=...&period=30dAuth: Session Token
Country breakdown
Section titled “Country breakdown”GET /v1/analytics/countries?project_id=...&period=30dAuth: Session Token
Device breakdown
Section titled “Device breakdown”GET /v1/analytics/devices?project_id=...&period=30dAuth: Session Token
Custom event counts
Section titled “Custom event counts”GET /v1/analytics/events?project_id=...&period=30dAuth: Session Token