Tracking Events
Once Analytics automatically tracks pageviews and clicks. You can also track custom events to measure specific actions.
Automatic tracking
The tracking script automatically captures:
- Page views — Every page load and SPA navigation
- Click events — Clicks on links, buttons, and form inputs
- Session data — Visit duration and page flow
- Technical data — Browser, OS, device type, country
No configuration required for basic tracking.
Custom events
Track any action using the dataLayer (same format as Google Tag Manager):
// Basic event
dataLayer.push({ event: 'signup' });
// Event with properties
dataLayer.push({
event: 'purchase',
value: 99.99,
currency: 'USD',
product: 'Pro Plan'
});Common events to track
// Newsletter signup
dataLayer.push({ event: 'newsletter_signup' });
// Form submission
dataLayer.push({ event: 'contact_form_submit' });
// Video play
dataLayer.push({ event: 'video_play', video_id: 'intro' });
// Download
dataLayer.push({ event: 'download', file: 'whitepaper.pdf' });
// Add to cart
dataLayer.push({
event: 'add_to_cart',
product_id: 'SKU123',
price: 49.99
});Event properties
Any properties you include with the event are stored in the event_data field as JSON:
dataLayer.push({
event: 'purchase',
order_id: '12345',
total: 149.99,
items: 3
});These properties can be queried directly from your D1 database.
Click tracking
Clicks are automatically tracked on:
- Links (
<a>) — Both internal and external - Buttons (
<button>) — Standard buttons - Form inputs (
<input>) — Buttons and submit inputs - Role buttons — Elements with
role="button"
Click data captured:
| Field | Description |
|---|---|
| Element ID | The id attribute if present |
| Element text | Button/link text (max 50 chars) |
| Href | Link destination |
| Tag | HTML tag name |
Outbound vs Inbound links
- Outbound — Links starting with
httpgoing to other domains - Inbound — Relative paths and same-domain links
SPA support
For single-page applications (React, Vue, Next.js, etc.), Once Analytics automatically tracks navigation by intercepting:
history.pushState()history.replaceState()popstateevents (browser back/forward)
No additional configuration needed for most SPAs.
Google Tag Manager
If you're already using GTM, Once Analytics captures all dataLayer.push() events automatically.
Tip: You can run Google Analytics and Once Analytics side-by-side. Both read from the same dataLayer without conflicts.
Filtered GTM events
These GTM system events are automatically filtered out:
gtm.js,gtm.dom,gtm.loadgtm.click,gtm.linkClickgtm.formSubmit,gtm.scrollDepth- Events starting with
gtm.
UTM parameters
UTM parameters are automatically captured from URLs:
| Parameter | Description |
|---|---|
utm_source | Traffic source (google, newsletter) |
utm_medium | Marketing medium (cpc, email, social) |
utm_campaign | Campaign name |
utm_term | Paid search keywords |
utm_content | Ad/link variant |
Example URL:
https://yoursite.com/?utm_source=twitter&utm_medium=social&utm_campaign=launchView UTM data in Dashboard → Campaigns.
Data sanitization
For privacy and security, these query parameters are automatically redacted:
Authentication: session_id, token, access_token, jwt, code
Personal data: user_id, email, username, phone
Security: password, secret, csrf_token, api_key
Payment: card, cvv, account_number
Ad tracking: fbclid, gclid, msclkid
Values are replaced with REDACTED before storage.
Questions? Email hello@onceanalytics.com