OneTrust
Connect Shoplift with OneTrust Cookie Consent to ensure A/B testing respects visitor privacy preferences managed through OneTrust.
Overview
OneTrust is a leading privacy management platform that helps businesses comply with GDPR, CCPA, and other privacy regulations. This guide shows how to integrate OneTrust's consent signals with Shoplift's analytics tracking.
Prerequisites
OneTrust Cookie Consent implemented on your Shopify store
OneTrust script loaded before Shoplift
Performance/Analytics cookies category configured in OneTrust
Implementation
Basic Integration
Add this code after your OneTrust script but before any analytics tracking:
// OneTrust + Shoplift Consent Integration
(function() {
// Function to sync OneTrust consent with Shoplift
function syncOneTrustWithShoplift() {
if (!window.OnetrustActiveGroups) {
// OneTrust not ready yet
setTimeout(syncOneTrustWithShoplift, 100);
return;
}
// Check if performance/analytics cookies are accepted
// C0002 is typically Performance Cookies - verify your OneTrust configuration
const hasAnalyticsConsent = window.OnetrustActiveGroups.includes('C0002');
// Update Shoplift consent
if (window.shoplift && window.shoplift.setAnalyticsConsent) {
window.shoplift.setAnalyticsConsent(hasAnalyticsConsent)
.then(() => {
console.log('Shoplift consent synchronized with OneTrust:', hasAnalyticsConsent);
})
.catch(error => {
console.error('Failed to update Shoplift consent:', error);
});
} else {
// Retry if Shoplift isn't ready
setTimeout(syncOneTrustWithShoplift, 100);
}
}
// Initial sync on page load
syncOneTrustWithShoplift();
// Listen for consent changes
window.OneTrust.OnConsentChanged(function() {
syncOneTrustWithShoplift();
});
})();Advanced Integration with Cookie Categories
OneTrust uses specific category codes. Map these to Shoplift's consent:
OneTrust Configuration
Finding Your Category IDs
Log in to your OneTrust dashboard
Navigate to Cookie Consent > Categorizations
Find your Performance/Analytics category
Note the category ID (e.g., C0002)
Testing Your Integration
Debug Console Commands
Test your integration using these console commands:
Testing Consent Scenarios
First-time visitor (no consent)
Clear cookies and local storage
Verify banner appears
Confirm no analytics tracking before consent
Accepting analytics cookies
Accept performance cookies in OneTrust banner
Verify Shoplift receives consent signal
Check that test data is being tracked
Rejecting analytics cookies
Reject performance cookies
Verify test variants still display
Confirm no analytics data is sent
Changing consent mid-session
Use OneTrust preference center to toggle consent
Verify Shoplift updates accordingly
Last updated
Was this helpful?