Skip to content

Troubleshooting

When variants do not appear, “stick,” or disappear in SPAs, work systematically: check assignment first, then markup/keys, then session and routing behavior.

/* Add CSS to <head> to reduce flicker */
.ab-test-loading {
visibility: hidden !important;
}
<body class="ab-test-loading">
</body>
// Make visible after variant application
document.body.classList.remove("ab-test-loading");

Combine this with an HTML fallback so users without JS or on a slow network still see content. See HTML variants → Anti-patterns.


  1. API available?

    typeof window.usertrax?.getVariant; // "function"

    Otherwise the script has not loaded yet — see JavaScript API → Queue.

  2. Assignment present?

    window.usertrax.getAssignments();
    // expected e.g. { button_color_test: "variant_red" }

    Empty? Is the test active? Does URL targeting match the current page? Domain/API key correct?

  3. Match keys

    data-usertrax-ab-test-group = test key, data-usertrax-ab-test-variant = variant key — exact match.

  4. Inline styles

    Non-assigned variants should start with style="display: none"; the assigned one has display cleared by the tracker. Your own CSS with display: none !important can override that.

  5. Fallback vs. assignment

    Once assigned, the tracker shows only the matching variant — even if another element has data-usertrax-ab-test-fallback.


Assignments are stored in sessionStorage under usertrax_ab_<test_key> and stay stable for the session — that is intentional, so users do not jump between variants.

To re-roll randomly (testing only):

// Remove all usertrax A/B keys and reload
Object.keys(sessionStorage)
.filter((k) => k.startsWith("usertrax_ab_"))
.forEach((k) => sessionStorage.removeItem(k));
location.reload();

Or use a private window / another browser. Traffic-split changes mainly affect new sessions, not ones already assigned.


The tracker listens for client-side navigation and can re-apply session / element visibility. Still, common pitfalls:

ProblemWhat to do
New route renders variant markup only after navigationSet attributes on the new DOM; call window.usertrax.applyElementVisibility() if needed
Test is URL-targeted; SPA changes path without reloadEnsure the URL pattern matches the client route; re-check assignment after navigation
Framework hydrates and resets stylesRe-apply visibility after hydration, or drive variants via framework state + getVariant
getVariant called too early in setup hooksWait until the method exists (see JavaScript API)
// After your own route change / dynamic insert
if (typeof window.usertrax?.applyElementVisibility === "function") {
window.usertrax.applyElementVisibility();
}

  • A/B test assignments are stored in sessionStorage (usertrax_ab_<test_key>)
  • Sessions remain active for 30 minutes after last activity
  • After expiry / a new session, a different variant may be assigned
  • Conversions automatically receive ab_test_data with current assignments
  • HTML elements with A/B attributes inserted after load are handled via a MutationObserver in fallback mode first, then switched correctly once tests are loaded

For broader session and attribution questions: Sessions & Attribution.