Single Page Application
About Single Page Applications
Single Page Applications (SPA) are a special type of web app. An SPA will load a single page when you enter a website and, from that point on, load all subsequent content in that same page as you navigate. This will appear to work like a normal website, but when switching between “pages,” the page doesn’t actually reload.
By default, deployment code runs as soon as a web page loads. However, because SPAs don’t refresh when navigating between pages, deployment code will not re-evaluate as you navigate between pages. By using the techniques outlined below, you can enable the deployment code to function on your SPA site seamlessly.
Auto Re-evaluating Intercept Logic Upon URL Change
If your Single Page Application depends on client-side routing for user navigation, you can force re-evaluation of intercepts upon subsequent URL changes by enabling the Re-evaluate intercept logic when the URL changes setting. Checking this setting will allow for intercept logic evaluation in addition to the evaluation that occurs upon the initial page load.
To enable auto re-evaluation of the intercept logic, follow the steps below:
- Go to Intercepts.
- Go to Intercept settings.
- Make sure that Re-evaluate intercept logic when the URL changes is checked under the Single-page App (SPA) Support section.
- Click Apply changes.
Re-evaluating Intercept Logic and Track Activity Upon URL Change
In the previous section, we showed how to support single-page applications for all intercepts in a project. However, if you want to support this behavior for all intercepts in a project and Digital Experience Analysis, you need to adjust a setting at the project-level instead.
- Go to Manage project.
- Make sure that Re-evaluate intercept logic and/or track activity whenever the URL changes is checked under the Single-page App (SPA) Support section.
- Click Apply changes.
Attention: If you decide to use this SPA setting in conjunction with the intercept-level option to Display with custom Javascript code (manually), then you will still need to call the
QSI.API.run();
method in order to get the intercept to display on each SPA page.
Implementing Manually with JavaScript API
This method outlines how to switch your deployment code to run manually. This means that the deployment code won’t run or evaluate the associated logic until the appropriate JavaScript API request is initiated.
To implement manually
- Go to Intercepts.
- Go to Intercept settings.
- Under the Intercept loading options heading, select Manually Load Project.
- Click Apply changes.
- If desired, return to one of your intercepts, and set logic to your entire intercept or individual action sets.
- Place the deployment code into your website, preferably in a global header or footer so that it loads on all pages.
- Add the appropriate JavaScript API requests based on how many times you want your website to reference the Intercept. See section below for these requests.
JavaScript API Requests
If you want Qualtrics to evaluate your project in a single instance, use these two requests:
- This request loads the deployment code for any Intercepts and Creatives on the page. The “load” API is the same as reloading a page that has code on it.
QSI.API.load();
Qtip: If you have Manually Load Project enabled in your project settings, you will not need to call this API to load the deployment code upon initial page load. It will only be required to force loading to account for state changes on the page that occur without reload. - This starts the deployment code evaluation and will make any Creative appear if it passes the display conditions.
QSI.API.run();
If you want Qualtrics to evaluate your project code more than once on the same page, repeat the following three steps each time:
- This request removes the deployment code for any Intercepts or Creatives present on the page.
QSI.API.unload();
- This loads the deployment code for any Intercepts or Creatives on the page. This is the same as reloading the page.
QSI.API.load();
- This starts the deployment code evaluation and will make any Creative appear if it passes the display conditions.
QSI.API.run();
FAQs
- I activated my intercept, but it‘s not showing up on my site. Why not?
-
There are numerous potential causes as to why an intercept may not be appearing once it has been implemented. These causes may stem from the setup of the intercept itself or the implementation of the code.
- Logic: intercept targeting logic and action set logic are the conditions that must be met in order for an intercept to be displayed to a visitor. Checking this logic will be helpful in discovering why the Intercept is not displaying on a page.
- Logic sets that use “Contains”: A common cause of logic error is the use of the “Contains” vs. “Is.” To say a condition “Contains” means that the parameter you are basing the logic off (i.e., Current URL) will have the specified value present in addition to more information. For example, if I had logic that read as Current URL contains ‘qualtrics’, this would cause the intercept to display on any URL that has the word qualtrics present. The other option you have is using Current URL is [URL]. This condition depends on the visited URL being an exact match. Any differences or additional characters will prevent the intercept logic from passing.
- Intercept Revisions: When making edits to intercepts, changes are not made live until the intercept is published. When publishing an Intercept, a version of the intercept, or a “revision,” is saved. Reviewing the revisions that have been made is very useful for identifying any changes that may have suddenly prevented the intercept from appearing.
- Debug Window: The debug window is an invaluable tool for testing why an intercept is not displaying on a particular page.
For intercepts whose deployment code was implemented before March 2019, to enable the debug window, append a query string to any given URL called Q_DEBUG. This must be prefixed with a ? or a & like the following examples: https://www.qualtrics.com?Q_DEBUG, https://www.qualtrics.com/blog?item=value&Q_DEBUG.
For intercepts whose deployment code was implemented after March 2019, run the following JavaScript snippet in the Console of your web page:
The debug window breaks down all conditions required for intercepts running on the URL to appear. If you find that an intercept is not appearing, locate it in the debug window and identify any red failed warnings.QSI.API.unload(); QSI.isDebug = true; QSI.API.load(); QSI.API.run();
Qtip: The Website Insights debugger does not function if the code has been implemented using a tag manager. Also, if the URL already has a query string with a ?, then the debugger will require a & instead. - Network Request: Most browsers possess a developer tools menu that allows a user to see a site’s source code, resources, cookies, and network calls. Website Insights possesses a distinct presence in the Network section of these tools. To check for these scripts running, open the developer tools and navigate to the Network section. Once here, reload the webpage and the menu should begin to populate with all network requests being made by the website. To identify Website Insights code, look for calls that begin with ?Q_ZID or ?Q_SID. This is the code itself running checks on the display logic. If you cannot find anything matching this format, then there is an issue with the implementation of your project code. You can refer to our support page on implementation for advice on where is best to place the code.
- Content Security Policy Issues: If you receive a console log that violates a Content Security Policy, there is most likely a restriction on your website that is blocking our intercepts from deploying. We recommend reaching out to your web-development team to resolve. To ensure your intercepts work, we generally recommend allowlisting the following items in your Content Security Policy headers:
- connect-src https://*.qualtrics.com
- frame-src https://*.qualtrics.com
- img-src https://siteintercept.qualtrics.com
- script-src https://*.qualtrics.com
- I have built my intercept but would like to test it before activation. How can I do that?
-
There is a tool called a bookmarklet that allows you to test any intercept without having to activate it.