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.
<script defer data-site="42" data-key="dk_..." data-consent="simple" src="https://in.datalenk.com/dl.js"></script>
data-consent="simple": before your visitor's consent, Simple measurement only: the page, the referring domain, the device, the country, region and city. Nothing is written on the device, no campaign parameter or click id is sent, no link is marked, no visit is tied to a payment. A snippet without this attribute behaves exactly the same way.data-consent="wait": nothing at all is sent before your visitor's consent.
Your own consent banner: pass on the visitor's choice
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.
(window.datalenkQueue = window.datalenkQueue || []).push(["consent", true]); // accepted (window.datalenkQueue = window.datalenkQueue || []).push(["consent", false]); // refused or withdrawn
The direct call, once dl.js has loaded
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);
Purpose by purpose
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).
The rules
- 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.
- 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. - Do not add
data-bannerto the snippet: that attribute shows Datalenk's own banner, for sites that have none. One banner per site. - In your banner, "Refuse" must be as easy as "Accept", and nothing is ticked in advance.
Check what Datalenk received
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 startA complete example
<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>No banner of your own
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
- The API reference: every endpoint, and visitor consent in detail on the Ingestion page.
- The managed proxy: serve Datalenk from your own domain.
- The data processing agreement, section 11: your obligations, in plain words.