Overview
The tracking system consists of three main components:- Tracker Module - Methods for tracking specific user events
- Request Queue - Batches and sends tracking events efficiently
- Event Dispatcher - Emits custom DOM events for tracking lifecycle
Enabling Tracking
Tracking is disabled by default. To enable it, setsendTrackingEvents: true during initialization:
How Tracking Works
Request Queue
When you call a tracking method, the event is added to a request queue instead of being sent immediately. This approach:- Batches events to reduce network requests
- Persists events in localStorage to prevent data loss
- Handles offline scenarios by queuing events until connectivity returns
- Prevents bot traffic using humanity checks
Send Delay
By default, the queue waits 250 milliseconds before sending events. This delay allows multiple rapid events (like typing in search) to be batched together:trackingSendDelay: 0 to send events immediately without batching:
Storage and Persistence
Events are stored in localStorage under the key_constructorio_requests. This ensures:
- Events survive page refreshes
- Events are retried if requests fail
- Stale events (older than 3 minutes) are automatically cleared
Core Tracking Methods
All tracking methods are accessed throughconstructorClient.tracker:
Session Events
trackSessionStart()
trackSessionStart()
Records when a user session begins. Typically called once per session.Parameters:
networkParameters(optional):{ timeout: number }
true or ErrortrackInputFocus()
trackInputFocus()
Records when a user focuses on a search input field.Parameters:
networkParameters(optional):{ timeout: number }
true or ErrorSearch Events
trackSearchSubmit()
trackSearchSubmit()
Records when a user submits a search query.Parameters:
term(required): The search term submittedparameters(required): Object containing:originalQuery(required): The autocomplete query that led to this searchgroupId(optional): Group identifier if searching within a groupdisplayName(optional): Display name of the groupanalyticsTags(optional): Additional analytics data
networkParameters(optional):{ timeout: number }
true or ErrortrackSearchResultsLoaded()
trackSearchResultsLoaded()
Records when search results are displayed to the user.Parameters:
searchTerm(required): The search queryparameters(required): Object containing:url(required): Current page URLitems(required): Array of item objects withitemId(max 100 items)resultCount(optional): Total number of resultsresultPage(optional): Current page numberresultId(optional): Result identifier from Constructor.io responseselectedFilters(optional): Applied filterssortOrder(optional):'ascending'or'descending'sortBy(optional): Sort method usedsection(optional): Index section (e.g., “Products”)analyticsTags(optional): Additional analytics data
networkParameters(optional):{ timeout: number }
true or ErrortrackSearchResultClick()
trackSearchResultClick()
Records when a user clicks on a search result.Parameters:
term(required): The search query that produced this resultparameters(required): Object containing:itemName(required): Product nameitemId(required): Product identifiervariationId(optional): Product variation identifierresultId(optional): Result identifier from Constructor.io responsesection(optional): Index sectionanalyticsTags(optional): Additional analytics dataslCampaignId(optional): Sponsored listing campaign IDslCampaignOwner(optional): Sponsored listing campaign owner
networkParameters(optional):{ timeout: number }
true or ErrorAutocomplete Events
trackAutocompleteSelect()
trackAutocompleteSelect()
Records when a user selects an autocomplete suggestion.Parameters:
term(required): The selected autocomplete termparameters(required): Object containing:originalQuery(required): The partial query that triggered autocompletesection(required): Section of the selected itemtr(optional): Trigger type ('click','enter', etc.)itemId(optional): Item identifier if selecting a productgroupId(optional): Group identifierdisplayName(optional): Display name of the groupslCampaignId(optional): Sponsored listing campaign IDslCampaignOwner(optional): Sponsored listing campaign owner
networkParameters(optional):{ timeout: number }
true or ErrorProduct Events
trackItemDetailLoad()
trackItemDetailLoad()
Records when a user views a product detail page.Parameters:
parameters(required): Object containing:itemName(required): Product nameitemId(required): Product identifierurl(required): Current page URLvariationId(optional): Product variation identifieranalyticsTags(optional): Additional analytics data
networkParameters(optional):{ timeout: number }
true or ErrorConversion Events
trackConversion()
trackConversion()
Records conversion events like add-to-cart, add-to-wishlist, or custom actions.Parameters:
term(optional): Search term that led to the conversionparameters(required): Object containing:itemId(required): Product identifieritemName(optional): Product namevariationId(optional): Product variation identifierrevenue(optional): Sale or retail pricetype(optional): Conversion type (default:'add_to_cart')isCustomType(optional): Whether this is a custom conversion typedisplayName(optional): Display name for custom typesection(optional): Index section (default:'Products')
networkParameters(optional):{ timeout: number }
true or ErrortrackPurchase()
trackPurchase()
Records completed purchases (typically on order confirmation page).Parameters:
parameters(required): Object containing:items(required): Array of item objects (max 100), each with:itemId(required): Product identifierprice(optional): Item pricecount(optional): Quantity purchaseditemName(optional): Product namevariationId(optional): Variation identifier
revenue(required): Total order subtotal (excluding tax, shipping)orderId(optional): Unique order identifiersection(optional): Index section (default:'Products')analyticsTags(optional): Additional analytics data
networkParameters(optional):{ timeout: number }
true or ErrorThe SDK prevents duplicate purchase events by tracking
orderId values. If you call trackPurchase with the same orderId twice, the second call will be ignored.Recommendation Events
trackRecommendationView()
trackRecommendationView()
Records when recommendation results are displayed.Parameters:
parameters(required): Object containing:podId(required): Recommendation pod identifiernumResultsViewed(required): Number of recommendations viewedurl(required): Current page URLitems(optional): Array of viewed items (max 100)resultCount(optional): Total number of recommendationsresultPage(optional): Page numberresultId(optional): Result identifier from Constructor.io responsesection(optional): Index section (default:'Products')analyticsTags(optional): Additional analytics dataseedItemIds(optional): Seed item(s) used for recommendations
networkParameters(optional):{ timeout: number }
true or ErrortrackRecommendationClick()
trackRecommendationClick()
Records when a user clicks on a recommendation.Parameters:
parameters(required): Object containing:podId(required): Recommendation pod identifierstrategyId(required): Recommendation strategy identifieritemId(required): Product identifieritemName(required): Product namevariationId(optional): Product variation identifierresultId(optional): Result identifier from Constructor.io responsesection(optional): Index section (default:'Products')analyticsTags(optional): Additional analytics dataseedItemIds(optional): Seed item(s) used for recommendations
networkParameters(optional):{ timeout: number }
true or ErrorEvent Dispatcher
The Event Dispatcher emits custom DOM events throughout the tracking lifecycle. These events can be used for debugging, analytics, or triggering custom behavior.Emitted Events
All events are dispatched on thewindow object with the cio.client. prefix:
Configuration
Control event dispatcher behavior during initialization:Event Dispatcher Options
Event Dispatcher Options
Enable or disable custom event dispatching on the
window object.If
true, the dispatcher waits for the cio.beacon.loaded event before dispatching queued events. This is for compatibility with legacy Constructor.io beacon implementations.Set to false if you’re not using the legacy beacon.Referrer Tracking
By default, Constructor.io includes referrer information with tracking events:- Current page URL (host + pathname)
- UTM parameters from the URL
- Document referrer (previous page)
Humanity Check
The SDK automatically filters bot traffic to ensure tracking data quality:- Checks user agent against a bot list
- Stores humanity check result in sessionStorage or localStorage
- Prevents bot events from being queued
Best Practices
1. Enable Tracking in Production
2. Track Complete User Journeys
Implement tracking at key touchpoints:3. Include Result IDs
Always passresultId from Constructor.io responses to tracking methods:
4. Handle Errors Gracefully
Tracking methods returntrue on success or an Error on failure:
5. Monitor Event Queue
Listen for success and error events from the request queue:Troubleshooting
Events aren't being sent
Events aren't being sent
- Verify
sendTrackingEvents: trueis set during initialization - Check that you’re not in a bot environment (humanity check)
- Look for errors in the browser console
- Check localStorage for
_constructorio_requestskey
Events are queued but not sending
Events are queued but not sending
- Check network connectivity
- Verify the
serviceUrlis correct - Ensure
trackingSendDelayhasn’t been set too high - Check if
pageUnloadingstate is blocking sends
Duplicate purchase events
Duplicate purchase events
The SDK automatically prevents duplicate purchases using
orderId. If you see duplicates:- Ensure you’re passing a unique
orderIdfor each order - Check if the order ID storage key
_constructorio_purchase_order_idsexists in localStorage