Set consent
The script follows the consent of the visitor. Before consent, it stores no visitor ID. Use this page to connect the script to your cookie banner.
What the script does
| Consent | Result |
|---|---|
unknown | The script sends events with context.consent: "unknown" and without a visitor ID. QuickPipe counts them and keeps them only in traffic statistics without an identifier of a person. |
granted | The script stores the visitor ID lg_aid in a first party cookie and in localStorage for 13 months. The events have context.consent: "granted". |
denied | The script deletes the visitor ID and asks QuickPipe to erase its data. Then the script sends events with context.consent: "denied" and without an identifier. QuickPipe only counts them. |
The consent state is unknown until the visitor accepts or refuses.
Purposes
The table above is for the purpose analytics. The script also has the purpose ads for data for ad platforms, for example the ad click IDs clickIds. Each purpose has its own state. The script sends ad data only when analytics and ads are both granted.
| Purpose | Consent Mode v2 | Cookiebot | CookieYes | OneTrust |
|---|---|---|---|---|
analytics | analytics_storage | statistics | analytics | C0002 |
ads | ad_storage and ad_user_data | marketing | advertisement | C0004 |
A purpose with two or more groups is granted only when all its groups are granted. It is denied when one of them is denied.
Procedure: with Google Consent Mode v2
- Keep the default
consent: auto. - Make sure that your cookie banner pushes Consent Mode v2 to the
dataLayer.
The script reads analytics_storage, ad_storage and ad_user_data from the dataLayer. It needs no other change.
Procedure: with Cookiebot, CookieYes or OneTrust
Keep the default
consent: auto.If your banner uses groups that are different from the table in Purposes, set the groups of each purpose on the script tag. Divide two or more groups with commas:
html<script async src="…/lg.js" data-key="lg-pub-live-…" data-onetrust-analytics="C0002" data-onetrust-ads="C0004,C0005"></script>
The adapter for your banner sends the consent to the script.
Procedure: with a different banner
To connect the banner with no code on each page, write a consent adapter. Refer to Write a consent adapter. To use calls, do these steps:
Set
data-consent="manual"on the script tag, orconsent: 'manual'increateClient.When the visitor makes a choice, call
consentwith the state of each purpose:jslg('consent', { analytics: 'granted', ads: 'denied' });When the visitor changes the choice, call
consentagain. A purpose that the call does not give keeps its state.
The call lg('consent', 'granted') with a string sets only analytics. It never gives consent for ads.
Safari
Safari keeps a cookie from a script for 7 days only. After 7 days, a visitor who comes again gets a new visitor ID. To keep the visitor ID for 13 months, send the events through a path of your website. Refer to Use a first party endpoint.