Skip to main content

Basic Usage

This guide covers basic usage of the Web Feedback JavaScript APIs, including how to detect when the API is ready and how to load and run intercepts.


Detecting When the API Is Ready​

Website Feedback loads asynchronously. To run code only after the API is available, listen for the qsi_js_loaded event:

window.addEventListener("qsi_js_loaded", onInterceptLoaded, false);

function onInterceptLoaded() {
if (QSI && QSI.API) {
// Website Feedback is ready—safe to call QSI.API
console.log("Website Feedback loaded");
}
}

Always check that QSI and QSI.API are defined before calling API methods.


Basic Load and Run​

For traditional multi-page sites, intercepts typically load and run automatically. For manual control (e.g., conditional loading or SPAs), use:

// Load intercept scripts for the current page
QSI.API.load();

// Run intercept evaluation (show creatives that pass targeting)
QSI.API.run();

Chaining Load and Run​

The load() function is asynchronous. To avoid delays between load and run, chain them with .then():

QSI.API.load().then(QSI.API.run);

This ensures the intercept runs as soon as loading completes, without other code interrupting the flow.


Unloading Intercepts​

To remove all intercepts + creatives and reset the API state:

QSI.API.unload();

Common use cases:

  • Clearing intercepts before loading new ones (e.g., on SPA navigation).
  • Removing creatives when the user navigates away from a section.

Next Steps​

  • Event Usage – Track events for targeting and embedded data.
  • SPA Usage – Handle route changes in single-page applications.
  • API Reference – Full method and property reference.