setAnalyticsConsent()

Manually manage visitor analytics consent for custom privacy solutions.

setAnalyticsConsent()

Manually sets the visitor's analytics consent state. Only needed if you use a custom consent management platform (CMP) that does not integrate with Shopify's Customer Privacy API. If your store relies on Shopify's built-in privacy tools, Shoplift handles consent automatically and you can skip this method entirely.

Signature

window.shoplift.setAnalyticsConsent(consent: boolean): Promise<void>

Parameters

Parameter
Type
Required
Description

consent

boolean

Yes

true to allow analytics tracking, false to deny

Returns

Promise<void> — resolves when the consent preference has been saved.

When to Use This Method

Use when you have:

  • A third-party consent management platform (OneTrust, Cookiebot, TrustArc, etc.) that is not integrated with Shopify's Customer Privacy API

  • A custom-built consent solution

  • Region-specific consent requirements that Shopify doesn't handle

Do not use when:

  • Your store uses Shopify's standard Customer Privacy API (consent is handled automatically)

  • You're using Shopify's built-in cookie banner

  • You have no consent management system at all

Basic Usage

Understanding the distinction between test assignment and analytics tracking is important:

Concern
Consent Required?
Details

Test assignment

No

Visitors are always assigned to a variant to ensure a consistent experience.

Analytics tracking

Yes

Test data is only recorded in Shoplift's analytics when consent is granted.

Data collection

Yes

Visitor behavioral data respects the consent state in real-time.

This means a visitor will always see the correct variant, but their participation is only reflected in your test results if they've consented to analytics tracking.

Integration Pattern

The general pattern for connecting any CMP to Shoplift:

Mapping CMP Categories

Different CMPs use different category names. Shoplift only needs the analytics / statistics / performance category:

CMP Category
Maps to Shoplift?
Notes

Analytics / Statistics / Performance

Yes — pass true

This is the category Shoplift needs.

Marketing / Targeting

No

Shoplift doesn't do remarketing.

Functional / Preferences

No

Test assignment works regardless of consent.

Strictly Necessary

No

Core functionality always available.

Error Handling

Timing Considerations

  • Call early: Set consent as soon as it's available from your CMP. Data collected before consent is granted is not retroactively included.

  • Listen for changes: If the visitor updates their consent preferences mid-session, call setAnalyticsConsent() again with the new value.

  • No retroactive collection: When consent is granted after page load, Shoplift begins tracking from that point forward — it does not backfill data.

Last updated

Was this helpful?