Skip to main content

Sync API

To ensure that your code runs after the RevIQ script is loaded, you can use the reviq command queue.
The RevIQ script loads asynchronously in order to not block the page. It’s important to make sure that the API is ready before you call it.
index.js
globalThis.reviq = globalThis.reviq || [];
reviq.push((reviq) => {
    // Your code here
    reviq.setKv('foo', 'bar');
});
Alternatively, you can create a Promise that resolves after the first reviq command is called.
index.js
const reviqReady = new Promise((resolve) => {
    reviq = reviq || [];
    reviq.push((reviq) => {
        resolve(reviq);
    });
});
async function doSetKv() {
    const reviq = await reviqReady;
    reviq.setKv('foo', 'bar');
}