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();
  });
})();

OneTrust uses specific category codes. Map these to Shoplift's consent:

OneTrust Configuration

Finding Your Category IDs

  1. Log in to your OneTrust dashboard

  2. Navigate to Cookie Consent > Categorizations

  3. Find your Performance/Analytics category

  4. Note the category ID (e.g., C0002)

Testing Your Integration

Debug Console Commands

Test your integration using these console commands:

  1. First-time visitor (no consent)

    • Clear cookies and local storage

    • Verify banner appears

    • Confirm no analytics tracking before consent

  2. Accepting analytics cookies

    • Accept performance cookies in OneTrust banner

    • Verify Shoplift receives consent signal

    • Check that test data is being tracked

  3. Rejecting analytics cookies

    • Reject performance cookies

    • Verify test variants still display

    • Confirm no analytics data is sent

  4. Changing consent mid-session

    • Use OneTrust preference center to toggle consent

    • Verify Shoplift updates accordingly

Last updated

Was this helpful?