Events
Track pageviews and custom events to understand user behavior across your application.
Pageview Tracking
Pageviews are the fundamental tracking unit. They capture when a user views a page or screen.
Automatic Pageviews
With autoPushPageview: true (default), a pageview is tracked automatically on initialization.
Manual Pageviews
For single-page applications or custom navigation:
// Track a pageview manually
alkeAnalytics.pushPageView();
The SDK automatically captures:
- Current URL (normalized, without tracking parameters)
- Page title
- Referrer
- Session data
Navigating in a single-page application
pushPageView() opens a page; it does not close the previous one. Declare the
navigation itself so the SDK knows where one page ends and the next begins:
alkeAnalytics.pushNavigation(); // reports and closes the current page
alkeAnalytics.pushPageView(); // opens the next one
pushNavigation() reports the page being left, clears its context — content
dimensions, goal, custom data — restarts the active time, engagement, scroll depth
and video sequence from zero, then re-derives the automatic dimensions from the page
now displayed. Call it after your router has changed the url and rendered, or it
reads the previous page. Reader and session data (loggedIn, subscriptionStatus,
abtest, traffic source, …) follow the visit and are kept.
What the page being left had measured is frozen at that instant, not just reset: a
report of that page still in flight is finalised later with its own engagement, active
time and Web Vitals. The boundary also opens the next pageviewId, so an ad request or
an event that follows it already belongs to the next page.
See Content Dimensions for which side of the boundary each value falls on.
pushPageView() used to reset the per-page counters — active time, engagement, scroll
depth, video sequence — and to open a new pageviewId. It no longer does either:
pushNavigation() is the page boundary, and the only one. This also affects sites that
are not single-page applications but call pushPageView() several times on the same
document — infinite scroll, multi-step funnels: the second pageview now inherits the
scroll depth and video sequence of the first, and reports the same pageviewId,
because without a navigation both describe the same page.
pushNavigation() between two pushPageView() calls on the same document is therefore
required, not merely recommended. Omitting it is not just a matter of counters: two
pageviews of the same url within the same minute become indistinguishable in storage, so
the second one never appears in your reports, and the ad revenue it earned is
attributed to the first.
Custom Events
Track specific user interactions beyond pageviews.
pushEvent()
// Simple event
alkeAnalytics.pushEvent('button_click', 'share_button');
// Event with custom data included
alkeAnalytics.pushEvent('purchase', 99.99, true);
| Parameter | Type | Description |
|---|---|---|
eventName | stringrequired | Name of the event (e.g., 'button_click', 'video_play') |
eventValue | string|number|booleanoptional | Optional value associated with the event |
includeCustomData | booleanoptional | Include current custom data with this event. Default: `false` |
includeCustomData gates the custom data slots cd1 to cd10 only. The named
dimensions — content hierarchy, article metadata, reader context — are attached to
every event of the page, custom events included, whatever that flag is set to.
They are resolved when the event is actually sent, so a value set just after
pushEvent() still reaches it. See Content Dimensions.Flushing Events
Events are automatically sent when:
- The page/app goes to background
- The page is about to unload (web)
- A new pageview is tracked
You can also manually flush:
visibilitychange and pagehide. Manual flush is rarely needed.Engagement Tracking
Track how much of the content users actually consume.
Scroll engagement is tracked automatically. The SDK records the maximum scroll depth as a percentage (0-100).
// Override with custom engagement (e.g., video progress)
alkeAnalytics.setEngagementPercent(75);