Consent and Campaigns
Pomelo does not collect consent itself and does not read your consent platform. Your site does: it tells the script what each visitor chose. The script keeps that choice in memory only, and never writes it to the visitor’s device.
Two choices exist, and they are independent:
| Key | What it controls |
|---|---|
measurement |
Whether the audience measurement may send. Used where measurement requires agreement. |
campaigns |
Whether the Campaigns option may collect campaign data (UTM parameters, channels). |
For the scope of each, see Audience measurement and the Campaigns option.
Audience measurement alone: nothing to do
Section titled “Audience measurement alone: nothing to do”On a site with no consent mechanism, the script measures from page load, without
waiting for anything. Do not add data-consent or call pomelo.consent: this
is the normal operation.
Campaigns: pass the visitor’s choice
Section titled “Campaigns: pass the visitor’s choice”Campaigns collects campaign data only for a visitor who accepted, and only on a
site where the option is turned on in the site settings. Until your site calls
pomelo.consent with campaigns: true, no campaign data is collected, even if
the option is on. The dashboard shows how many visits carried an agreement.
Call pomelo.consent when your consent platform reports the visitor’s choice,
and again on every page: the choice is not stored by the script.
// Called by your consent platform each time the choice is known or changes.function onConsentChange(choice) { window.pomelo.consent({ campaigns: choice.marketing === true });}Behaviour:
pomelo.consent({ campaigns: true })allows campaign data from then on.pomelo.consent({ campaigns: false })withdraws it. Campaign data already attached to events still waiting to be sent is removed too.- A key you leave out changes nothing. A value that is not
trueorfalseis ignored. - Declining Campaigns never changes the audience measurement: a visitor who declines is measured like on a site without the option, where audience measurement is exempt. It never counts as agreement to the audience measurement.
- The parameters are read when each event is sent, from the address of the
page:
utm_source,utm_medium,utm_campaign,utm_content,utm_term, andrefwhen there is noutm_source.
Where measurement requires agreement: data-consent="required"
Section titled “Where measurement requires agreement: data-consent="required"”In a country that does not exempt audience measurement, you must collect your
visitors’ agreement before measuring. Add data-consent="required" to the
script tag:
<script defer src="https://collect.pomeloanalytics.com/s/YOUR_SITE_ID.js" data-consent="required"></script>With this attribute, the script makes no request to Pomelo and sends nothing
until your site passes measurement: true:
window.pomelo.consent({ measurement: true, campaigns: false });- When
measurementbecomestrue, measurement starts from the current page: its pageview is sent, and its time spent is counted from that moment. Nothing that happened before the agreement is replayed. - When
measurementbecomesfalse, the script stops sending, drops events still waiting to be sent, and waits for a new agreement. - The setting is off by default. You decide it, because you know your audience: Pomelo never turns it on by itself.
An objection prevails over everything: a visitor who objected (see Privacy and objection) is not measured, whatever the consent calls say.
Before the script has loaded
Section titled “Before the script has loaded”The script is loaded with defer, so your consent platform may answer before it
exists. Queue the command; the script replays the queue in order when it
starts:
<script> // Call this from your consent platform's callback, once the visitor has // chosen. Adapt the fields of `choice` to its format. function onConsentChoice(choice) { window.pomelo = window.pomelo || { q: [] }; window.pomelo.q.push([ 'consent', { measurement: choice.measurement === true, campaigns: choice.campaigns === true, }, ]); }</script>After the script has loaded, window.pomelo.q.push(...) and
window.pomelo.consent(...) have the same effect.
Reference
Section titled “Reference”interface PomeloConsent { measurement?: boolean; // true: may send. false: stop, wait for a new agreement. campaigns?: boolean; // true: campaign data allowed. false: withdrawn.}
window.pomelo.consent(choice: PomeloConsent): void;window.pomelo.q.push(['consent', choice]);| Script attribute | Effect |
|---|---|
data-consent="required" |
The measurement waits for measurement: true. Any other value: no wait. |
Check that it works
Section titled “Check that it works”In the dashboard, the Acquisition page shows the number of visits with
agreement out of all visits. If it stays at zero, your site is not passing
campaigns: true: check that pomelo.consent is called on every page, after
the script has loaded or through the queue.
Add ?pomelo_debug to a page address to see the script’s messages in the
browser console.