Time Tracking
Time tracking captures user engagement metrics by monitoring active time spent on pages and catalog items. Events are sent when configurable time thresholds are crossed (for example, 30 seconds or 60 seconds of active engagement).
Time tracking attaches itself to other events you send (such as catalog events) and automatically includes their context in engagement events. Only active time is tracked—periods when the user is actually interacting with the page through mouse movement, clicks, scrolling, or keyboard input.
By default, time tracking is disabled. To enable it, set enabled: true in your configuration. To disable it, set enabled: false or remove the time tracking configuration.
Configuration Options
| Option Name | Type | Default | Description |
|---|---|---|---|
enabled | boolean | false | Set to true to enable time tracking. |
thresholds | array | See below | Array of threshold objects with label (string) and threshold (milliseconds). |
eventTypes | array | ['catalog'] | Event types to capture context from. Only the first matching event is captured. |
activityTimeoutMillis | number | 5000 | Milliseconds of inactivity before user is considered inactive (minimum: 1000ms). |
minimumActivityTimeToRegister | number | 300 | Minimum milliseconds of activity required to count as active time. |
maxSessionDurationMillis | number | 3600000 | Maximum session duration in milliseconds (1 hour). Session resets after this time. |
sendPageExitWithoutThreshold | boolean | false | If true, send pageExit event even when no threshold was reached. |
maxEventsPerSession | number | 20 | Maximum time tracking events per session. Prevents event flooding. |
Default thresholds: [{label: 'LOW_INTEREST', threshold: 30000}, {label: 'HIGH_INTEREST', threshold: 60000}]
Implementation Examples
Time tracking captures context from other events you send. By default, it captures the first catalog event on a page and includes that catalog’s details (like catalogObject and catalogEventId) in all time tracking events. You can configure which event types to capture using the eventTypes option.
Enable with Default Settings
Enable time tracking with default thresholds (30 seconds and 60 seconds) and a catalog context.
1SalesforceInteractions.init({
2 consents: [{
3 purpose: SalesforceInteractions.ConsentPurpose.Tracking,
4 provider: "OneTrust",
5 status: consentStatus
6 }],
7 dataCloud: {
8 timeTracking: {
9 enabled: true
10 }
11 }
12});Custom Configuration
Configure custom thresholds and event types.
1SalesforceInteractions.init({
2 consents: [{
3 purpose: SalesforceInteractions.ConsentPurpose.Tracking,
4 provider: "OneTrust",
5 status: consentStatus
6 }],
7 dataCloud: {
8 timeTracking: {
9 enabled: true,
10 thresholds: [
11 { label: 'ENGAGED', threshold: 15000 },
12 { label: 'HIGH_ENGAGEMENT', threshold: 60000 }
13 ],
14 eventTypes: ['catalog', 'blogPost']
15 }
16 }
17});Event Structure
Time tracking generates events with the Engagement category and automatically includes fields from captured context events.
| Field Name | Field Type | Description |
|---|---|---|
eventType | string | Dynamically set to {contextType}Time (for example, catalogTime). Events are only sent after a context event has been captured. |
interactionName | string | Either timeOnPage or pageExit. |
category | string | Always Engagement. |
threshold | string | The threshold label that was crossed (for example, LOW_INTEREST) or pageExit. |
totalActiveTime | number | Total milliseconds of active time for this context/session. |
pageStartTime | string | ISO 8601 timestamp when tracking started for this context. |
lastActivityTime | string | ISO 8601 timestamp of the most recent user activity. |
pageViewId | string | UUID v4 generated per page view to correlate events. |
pingSequence | number | Incrementing counter for events in this page view. |
When a context event (for example, a catalog event) is captured, its fields are automatically copied to time tracking events. For catalog contexts, this includes catalogObject and catalogEventId.
Stopping Time Tracking
You can programmatically stop the time tracking service:
1SalesforceInteractions.DataCloud.stopTimeTracking()This is useful for:
- Privacy controls (user opts out)
- Conditional tracking based on page type
- Testing scenarios
Note: Once stopped, the service cannot be restarted without reinitializing the SDK.
Best Practices
Threshold Configuration
- Order thresholds from shortest to longest (they’re automatically sorted, but it’s clearer)
- Use meaningful labels that will be useful in analytics (e.g., ‘QUICK_VIEW’, ‘ENGAGED’, ‘HIGHLY_ENGAGED’)
- Consider your typical user engagement patterns when setting threshold values
- Ensure
maxEventsPerSessionis at leastthresholds.length + 1to allow all thresholds plus pageExit
Event Types
- If tracking catalog views, use
eventTypes: ['catalog'] - If tracking custom events, include them:
eventTypes: ['catalog', 'custom'] - Order matters: the first matching event type is captured
Activity Timeout
- Too short (e.g., 1 second): May miss brief pauses in user activity
- Too long (e.g., 30 seconds): May overcount inactive time
- Default (5 seconds) works well for most use cases
Session Duration
- Consider your typical session lengths
- Default (1 hour) prevents unrealistic accumulation for abandoned tabs
- For longer-form content, you may want to increase this
Page Exit Behavior
- Default (
sendPageExitWithoutThreshold: false) filters out bounce visits - Set to true if you want to track all page exits, including short visits
- Useful for bounce rate analysis
Troubleshooting
No Events Being Sent
- Check if enabled: Ensure
timeTracking.enabled: trueis set - Check consent: Time tracking respects consent management; ensure Opt-In consent exists
- Check context capture: Verify that events matching eventTypes are being sent
- Check thresholds: Ensure thresholds are reachable (not too high)
- Check rate limits: Verify
maxEventsPerSessionhasn’t been exceeded
Events Missing Context
- Verify event types: Ensure the events you’re sending match eventTypes configuration
- Check timing: Context is captured from the first matching event; ensure it’s sent before significant time passes
- Check event structure: Ensure your events have the expected structure and fields
Too Many Events
- Reduce thresholds: Fewer thresholds mean fewer events
- Lower maxEventsPerSession: Set a stricter limit
- Increase threshold values: Higher thresholds mean events are sent less frequently
Inaccurate Time Tracking
- Check activityTimeoutMillis: Too short may miss activity; too long may overcount
- Check minimumActivityTimeToRegister: Too high may undercount; too low may include noise