Back to Documentation

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):

javascript
// 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

javascript
// 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:

javascript
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:

FieldDescription
Element IDThe id attribute if present
Element textButton/link text (max 50 chars)
HrefLink destination
TagHTML tag name

Outbound vs Inbound links

  • Outbound — Links starting with http going 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()
  • popstate events (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.load
  • gtm.click, gtm.linkClick
  • gtm.formSubmit, gtm.scrollDepth
  • Events starting with gtm.

UTM parameters

UTM parameters are automatically captured from URLs:

ParameterDescription
utm_sourceTraffic source (google, newsletter)
utm_mediumMarketing medium (cpc, email, social)
utm_campaignCampaign name
utm_termPaid search keywords
utm_contentAd/link variant

Example URL:

https://yoursite.com/?utm_source=twitter&utm_medium=social&utm_campaign=launch

View 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