You don't need to change anything in the snippet — copy it from the install screen as it is (see Install the tracking script). This page explains what each part does, so you can review it, load it from your own code, or debug it.
The snippet
<link rel="preload" href="https://cdn.entail-insights.com/js/entail.js" as="script">
<link rel="preconnect" href="https://widgets.entail.ai/" crossorigin>
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.entailInsights=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src="https://cdn.entail-insights.com/js/entail.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="entailInsights",u.toString=function(t){var e="entailInsights";return"entailInsights"!==a&&(e+="."+a),t||(e+=" (stub)"),e},o="trackEvent capture opt_out_capturing has_opted_out_capturing opt_in_capturing reset".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.entailInsights||[]);
entailInsights.init('YOUR_SITE_TOKEN', { disable_decide: false });
</script>What each part does
Part | What it does |
|---|---|
| Starts downloading |
| Opens the connection to |
The inline script | Creates the |
| Tells the SDK which website it's on. The token identifies your website; disable_decide: false lets it read your website's settings. More options in init options . |
The placeholder (stub)
Until entail.js arrives, window.entailInsights is a placeholder. Its methods don't do anything yet — they write each call into a queue. That's why you can call it from any script on the page without waiting:
// Works even if entail.js hasn't loaded yet: the call is queued.
entailInsights.trackEvent('start-trial', { plan: 'pro' });The placeholder has these methods: init, trackEvent, capture, opt_out_capturing, opt_in_capturing and has_opted_out_capturing. Note that a queued has_opted_out_capturing() returns nothing useful — read it once the SDK has loaded.
When entail.js loads
- It replaces the placeholder with the real SDK, still at
window.entailInsights. - It runs your
initcall, then replays the queued calls in order. A queued opt-out is applied first, so nothing is stored or sent for a visitor who already declined (see Consent and privacy). - It sends a page view and starts tracking clicks and form submissions (see Automatically tracked events).
- It reads your website's settings and shows the campaigns, popups, quizzes and A/B tests that apply to this page and visitor.
Methods that need the loaded SDK. get_distinct_id() and showPopup() aren't part of the placeholder. Call them after the SDK has loaded — for example from the loaded callback in init options.
Installed twice? Nothing breaks
The snippet sets a flag (__SV) the first time it runs, and the real SDK carries it too. A second copy — say one in your theme and another in Google Tag Manager — sees the flag and skips its setup, so the SDK loads once. A second init call is ignored, so the first copy's options are the ones that apply.
Bots and crawlers
When the visitor looks like a bot or a headless browser, the SDK only records the page view. It shows no campaigns, popups or tests to it. Search engines that index your pages still see your widgets' content, but are never put into an A/B test or redirected.
Where to put it
In the <head> of every page, ideally just before </head>. A/B tests change the page before visitors see it, so the earlier it runs, the less chance the original version flashes first. For redirect tests, see Redirect tests without flicker.
- init options: Every option you can pass to init, with its default.
- Track custom events: Send your own events with trackEvent.
- Domains to allow: The hosts to add to your Content Security Policy.
Frequently asked questions
Does the snippet block page rendering?
No. It adds
as an entail.js
script, so the browser keeps drawing your page while the SDK downloads.async
Can I call entailInsights before entail.js has loaded?
Yes, for
, trackEvent
, capture
and opt_out_capturing
. The placeholder queues those calls and the SDK runs them in order once it loads. Other methods exist only after the SDK has loaded — use the opt_in_capturing
option for those.loaded
What if the snippet is installed twice?
The second copy sees the first and does nothing, so visits aren't counted twice. Only the first
call counts.init
