conversionloopdevelopers

Install the script

The script loads your live campaigns, decides in the browser which one to show, renders it and sends the answers back. It loads asynchronously and never blocks your page.

The script tag

Copy the tag for your project from the dashboard (Settings → Project) or from the API (Get the script tag). Paste it into the <head> of every page you want to run campaigns on:

<script async src="https://cdn.conversionloop.net/v1/p/prj_live_xxxxxxxxxxxxxxxxxxxxxxxx.js"></script>

Use the same tag on every page. It does not change when you add or edit campaigns.

Delivery: campaigns inside the script or loaded separately

There are two ways to deliver campaigns. You switch between them in the dashboard or with inlineConfig on the project.

Inside the script (default). The tag above. The script and your live campaigns come in a single request, so campaigns can show a little sooner on the first page view. The file grows with every live campaign. The dashboard shows how big it is.

Loaded separately. The script is the same file for every website, and it loads your campaigns with a second request:

<script async src="https://cdn.conversionloop.net/v1/loop.js"
        data-project="prj_live_xxxxxxxxxxxxxxxxxxxxxxxx"></script>

This keeps the script small and cached across sites. It is the better choice with many or large campaigns.

Both tags keep working whichever setting is active. When you switch, update the tag on your site whenever it suits you.

Allowed domains

Set the hostnames your site runs on in the project's Allowed domains (domains in the API). On any other host the script stays silent, and answers from other origins are rejected. That stops others from running your campaigns or sending fake answers with your public key.

  • example.com covers example.com and all its subdomains, like www.example.com and shop.example.com.
  • *.example.com covers the same.
  • An empty list means no restriction. That is handy for testing, but set the list before you go live.

If your site asks for consent before setting cookies or using local storage, choose a consent mode in the project:

Mode Behaviour before consent
not_required Runs right away.
required Does nothing until consent is given.
cookieless_fallback Runs, but stores nothing on the visitor's device. Frequency limits and visit counts then only apply within the page.

With required and cookieless_fallback, tell the script when consent is given. Any of these works:

  • Dispatch the event cl:consent on window. This always works, whatever the project's consent signal is:
window.dispatchEvent(new Event('cl:consent'));
  • Set a consent signal in the project, and the script also listens for a window event with that name.
  • Or name a global variable or function as the signal. The script checks it on load and every half second for 30 seconds. It starts when the variable is true or the function returns true.

If consent comes later than that, the script starts on the next page view.

Single-page apps

The script evaluates campaigns again on every page load. In a single-page app, tell it about route changes, so that it reads the new URL and checks all campaigns again:

router.afterEach(() => window.conversionloop?.refresh());

Content Security Policy

If your site sends a Content-Security-Policy header, allow:

Directive Value Why
script-src https://cdn.conversionloop.net The script itself
connect-src https://api.conversionloop.net Loading campaigns and sending answers
style-src 'unsafe-inline' Campaign styles. They live in a <style> element inside the campaign's Shadow DOM and do not affect your page.

Check the installation

  1. Turn on Engine debug logging in the project settings (debug: true in the API).
  2. Open your site and the browser console. The script logs with the prefix [conversionloop]: that it started and with how many campaigns, whether the domain is allowed, which data fields it received, and when it schedules and shows a campaign.
  3. Turn debug logging off again when you are done. Changes reach visitors within about five minutes.

Campaigns appear only when they are live, the visitor is in their audience, and the frequency limits allow it. To see one right away, call conversionloop.trigger('your-campaign-slug') in the console. See the JavaScript API.

Performance and privacy

  • The script loads with async and never blocks rendering.
  • Campaigns render in a Shadow DOM: your CSS does not break them, and theirs does not touch your page.
  • Audiences are evaluated in the browser. Before a campaign shows, nothing about the visitor is sent.
  • Visitor memory (visits, which campaigns were seen or answered) lives in first-party storage on your domain. There are no third-party cookies and no cross-site tracking.