Datalenk documentation

Install the script, pass on your visitors' consent from your own banner, and find the API reference.

Install the script

Paste this line once, on every page, before </head>. Your ready-to-paste snippet, with your site id (data-site) and its ingestion key (data-key), is in Settings.

index.html
<script defer data-site="42" data-key="dk_..." data-consent="simple" src="https://in.datalenk.com/dl.js"></script>

If your site already shows a consent banner (a consent management platform, or your own code), it tells Datalenk what the visitor answered, in one call. Until it does, Datalenk runs Simple measurement (or nothing, with data-consent="wait") and stores nothing.

What waits for the visitor's consent: tying the visit to its source and to a sale (campaign parameters, click ids, the Lenkli marker, links to Stripe and Calenkli, the return from Stripe, identify()), the Persistent layer if you turned it on, A/B tests, and replay if you turned it on.

Use the queue, window.datalenkQueue: it works before and after dl.js has loaded, and it never throws an error, even when dl.js did not start (a browser driven by a robot, a snippet without data-site, a blocked script). It is the safest form for a banner.

your banner
(window.datalenkQueue = window.datalenkQueue || []).push(["consent", true]);  // accepted
(window.datalenkQueue = window.datalenkQueue || []).push(["consent", false]); // refused or withdrawn

Once dl.js has loaded, datalenk.consent() does the same thing. But when dl.js did not start, datalenk does not exist: calling it throws an error that stops your banner's code. So check window.datalenk first. Before dl.js has loaded, this check skips the call: the queue stays the safest form.

// "Accept all"
window.datalenk && datalenk.consent(true);

// "Refuse all", or consent withdrawn later
window.datalenk && datalenk.consent(false);

If your banner offers the purposes one by one, pass an object. A missing key counts as refused.

(window.datalenkQueue = window.datalenkQueue || []).push(["consent", { attribution: true, experiments: false, replay: false }]);

// or, once dl.js has loaded
window.datalenk && datalenk.consent({ attribution: true, experiments: false, replay: false });

Three purposes: attribution (visit sources and sales, with the Persistent layer if you turned it on), experiments (A/B tests), replay (if you turned it on).

  1. Call it on every page load once the visitor has answered. Datalenk does not keep a choice made in your banner: your banner keeps it. Passing the same answer again changes nothing.
  2. When the visitor changes their mind (a "Cookie settings" link that reopens your banner), call it again with the new answer. datalenk.consent(false) deletes the identifier stored by Datalenk and gives marked links back the address your site wrote.
  3. Do not add data-banner to the snippet: that attribute shows Datalenk's own banner, for sites that have none. One banner per site.
  4. In your banner, "Refuse" must be as easy as "Accept", and nothing is ticked in advance.
window.datalenk && datalenk.consentStatus();  // "pending" (no answer yet) | "granted" | "partial" | "denied" | "off"
window.datalenk && datalenk.consentChoices(); // { attribution, experiments, replay }, or null before an answer
// undefined: dl.js did not start
index.html
<script defer data-site="42" data-key="dk_..." data-consent="simple" src="https://in.datalenk.com/dl.js"></script>
<script>
  // Your banner calls this when the visitor clicks, then on every page once they have answered.
  function passConsentToDatalenk(accepted) {
    (window.datalenkQueue = window.datalenkQueue || []).push(["consent", accepted === true]);
  }
</script>

Add data-banner to the snippet: Datalenk shows its own banner to your visitors, in their language (French or English), with "Accept" and "Refuse" side by side, and "Choose" to decide purpose by purpose. The details are in the API reference.

Go further