Skip to content
  • There are no suggestions because the search field is empty.

Single Page Application (SPA) Troubleshooting Guide

Find and fix experiences that don't show, don't update or don't go away on single page apps

Author: George F. Crewe

 THIS ARTICLE WILL HELP YOU:


Overview and Quick Checks

Single page apps (SPAs), built with frameworks like React, Angular and Vue, redraw the part of the page that changes instead of loading a new page. Convert's tracking script handles this by default. See SPA Optimizations. If an experience doesn't behave as you expect, go through these checks first.

  1. SPA optimizations are on. Under Configuration > More Settings, Disable Single Page App Optimizations must be unchecked. Also check the address of the page you test. If it contains _conv_disable_spa_optimizations=true or _conv_disable_spa_optimizations=1, SPA optimizations are off for that page view.
  2. Your project runs the current tracking script. If Use Legacy Script shows under Configuration > Environments & Tracking Code, follow Migrate from the Legacy Tracking Script to the New Tracking Script (Step-by-Step).
  3. Old polling code is gone. Code that calls run when your app changes route isn't needed any more. See Running Experiments on Single Page Apps.
  4. The location matches the URL after the route change. A Page URL condition compares only the part before the ? and the #. If your routes live in the query string or after a #, use a Query string condition or a JS Condition such as window.location.hash === "#/pricing".
  5. The location's trigger is what you expect. A location with the Manually, DOM Element or When a callback is called trigger only starts the experience when that trigger fires. See Running Experiments on Single Page Apps.
  6. The page changes after the URL does. The script notices a new URL when something on the page changes.

To see what the script did on the current view, open your browser's console and type convert.currentData.experiences. It lists the experiences that started on the current view, and the script resets it each time it runs, so check it after you move to the route you're testing. See Reading Triggered Experiment Data for Using it in Third Party Systems. To read the script's log, add convert_log_level=debug to the page address (use ? to start the query string, or & if the address already has one) and reload.

Changes Appear on the First View but Not on Later Ones

Your variation shows on the first page you load, but not after you move to another route. The script didn't run for the new route, or it ran and the experience didn't match.

  1. Go through the quick checks above. Checks 1 to 5 cover the usual causes.
  2. Move to the route where the variation should show, then type convert.currentData.experiences in the console.
  3. Your experience isn't listed. It didn't start on this route. Check that the location's conditions match the new URL, the location's trigger, and the experience's audience.
  4. Your experience is listed, but you don't see the change. The experience started and the change didn't apply. Go to the next section.

You don't need to add code that runs the script again. If you turned SPA optimizations off on purpose, see Running Experiments on Single Page Apps for the ways to start experiences by hand.

Changes Appear in the Visual Editor but Not Outside It

You build the change in the Visual Editor, but when you preview it outside the editor, it doesn't appear.

The script finds the element to change with a CSS selector. If your app redraws the element, the script applies the change again when the selector matches the new element. If the selector no longer matches, the script keeps waiting for an element that doesn't exist, and the change never shows.

  • Shorten the selector. Replace long paths and position-based selectors with short ones that rely on a stable id or class, for example #hero-title or .promo-banner. Avoid class names your build generates, because they can change every time the site is deployed.
  • Test the selector on the page. On the route where the variation should show, type document.querySelectorAll("#hero-title").length in the console. You want 1.
  • Check the location. Your preview page's URL must match the experience's location conditions.
  • Turn on SPA Mode in the Visual Editor if clicking an element shows the message about not being able to determine the element selector. SPA Mode only changes how the editor works and doesn't affect live experiences. See How to Enable SPA Mode in the Convert Visual Editor.

Changes Keep Appearing on Later Views

The change shows on the right route, but it stays when the visitor moves to a route where the experience shouldn't run.

Each time the script runs, it removes the elements and styles that variations added, then applies the variations that match the new route. It doesn't undo:

  • edits to elements that stay on the page, such as changed text, classes, attributes or inline styles;
  • anything your own JavaScript adds or sets up, such as elements, event listeners and timers.

To fix this, add code that undoes what your variation did. Add it under Configuration > Global Javascript. Global Javascript runs every time the script runs, before the script checks your experiences. Your code undoes the change first, and a variation that still applies then makes it again.

// Runs each time the script runs, before variations are applied.
var button = document.querySelector("#signup-button");
if (button) {
// Undo what the variation added to this element.
button.classList.remove("promo");
button.style.removeProperty("background-color");
}
// Remove an element your own variation code added.
document.querySelectorAll(".promo-banner").forEach(function (el) {
el.remove();
});

📒Note: Change the selectors, the class and the style property to match what your variation changes. If your variation edits text, put the original text back in the same way. Test the code on a staging site before you use it on production.

If a variation still looks wrong after this, contact our support team. Send the page address, the experience ID, what convert.currentData.experiences shows before and after the route change, and the console output with convert_log_level=debug in the address.