Skip to content

Configuration & API

window.usertraxConfig = {
// API endpoint (unified for all events)
endpoint: "https://api.usertrax.io/api/events",
// Cross-domain settings
crossDomainParamName: "uxs",
crossDomainDomains: ["checkout.example.com"],
// Session & privacy
sessionTimeout: 24 * 60 * 60 * 1000, // 24 hours of inactivity
respectDoNotTrack: false,
// Silence tracking on selected paths (SPA-aware)
disableOnPages: ["/form/*"],
// Ads / marketing forwarding (all off by default)
ads: false, // Legacy: enables ga4 + tagManager + facebook
ga4: false,
tagManager: false,
facebook: false,
posthog: false,
};

Set window.usertraxConfig before loading the tracker script.

OptionTypeDefaultDescription
endpointstringhttps://api.usertrax.io/api/eventsUnified ingest URL for all tracker events
crossDomainParamNamestring"uxs"URL parameter name for the session ID
crossDomainDomainsarray[]Domains for cross-domain tracking ([] = all)
sessionTimeoutnumber86400000 (24h)Session TTL in milliseconds (inactivity)
respectDoNotTrackbooleanfalseWhen true, stop tracking if the browser DNT flag is set
disableOnPagesarray[]Paths with tracking off (exact strings, * globs, RegExp, or (pathname, location) => boolean; SPA-aware). Session ID in localStorage is kept
adsbooleanfalseLegacy shorthand: enables ga4, tagManager, and facebook together
ga4booleanfalseForward conversions to gtag (GA4)
tagManagerbooleanfalseForward conversions to dataLayer (GTM)
facebookbooleanfalseForward conversions to fbq (Meta Pixel)
posthogbooleanfalseForward events/identify to window.posthog

Details on ads forwarding and Enhanced Conversions: Ads & Enhanced Conversions.

// Current configuration
console.log("Config:", window.usertraxConfig);
// Session ID (localStorage)
console.log("Session ID:", localStorage.getItem("uxs_id"));
console.log("Last activity:", localStorage.getItem("uxs_last"));

There is no debugMode flag on the main tracker. Use the Network tab (/api/events) and the values above when debugging.

  1. Missing Auth Key: Ensure the data-key attribute is set on the script tag
  2. CORS Errors: Verify API endpoints are accessible
  3. Parameter Not Captured: Check URL format and parameter names
  4. Session Not Persisting: Verify localStorage is enabled
  5. No ads forwarding: Flags (ga4 / tagManager / facebook / ads) default to false
// Use consistent, descriptive event names
usertrax.push({ event: "product_purchase" });
usertrax.push({ event: "newsletter_signup" });
usertrax.push({ event: "free_trial_start" });
// Include relevant context
usertrax.push({
event: "purchase",
total: 99.99,
metadata: {
product_category: "electronics",
product_brand: "Apple",
checkout_method: "credit_card",
user_segment: "premium",
},
});
// Always specify currency for monetary events
usertrax.push({
event: "purchase",
total: 99.99,
currency: "EUR", // Explicit currency
});
// Only include necessary user data
usertrax.push({
event: "signup",
user_data: {
email: "user@example.com", // Only essential data
// Avoid sensitive information like passwords
},
});
usertrax.push(eventObject);

Parameters:

  • eventObject (object): Event data with any of the supported parameters

Returns: void

See Events & Parameters for all object keys.

usertrax.identify(distinctId, traits);

Parameters:

  • distinctId (string): Stable external user id (e.g. database primary key)
  • traits (object, optional): Person properties; canonical keys merge into user_data, others appear only in meta_data.$usertrax_identify

Returns: void

Details in User Identification.

window.usertrax.getVariant(testKey);

Parameters:

  • testKey (string): A/B test identifier

Returns: string - Current variant key or null

window.usertrax.getAssignments();

Returns: object - All current A/B test assignments

More in the A/B Testing documentation.