# Consent Management Integrations

Ensure Shoplift respects visitor privacy preferences by integrating with your custom consent management platform.

#### Overview

Shoplift is designed to work seamlessly with privacy regulations like GDPR, CCPA, and other data protection laws. By default, Shoplift automatically integrates with Shopify's Customer Privacy API to respect visitor consent preferences. For stores using third-party consent management platforms, Shoplift provides the `setAnalyticsConsent()` method to manually sync consent status.

This integration ensures that:

* Visitor data is only collected when appropriate consent is given
* Test assignments respect privacy preferences
* Analytics tracking aligns with consent status
* Your store remains compliant with privacy regulations

#### How Consent Works in Shoplift

**Default Behavior: Shopify Customer Privacy API**

For most Shopify stores, no additional configuration is needed. Shoplift automatically:

1. **Listens to Shopify's consent signals** via the Customer Privacy API
2. **Respects consent preferences** before collecting any analytics data
3. **Stores test assignments** but only tracks analytics when consent is granted
4. **Updates tracking status** if visitors change their consent preferences

#### How Test Assignment Works with Consent

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

* **Test Assignment**: Always occurs to ensure consistent user experience
* **Analytics Tracking**: Only occurs when consent is granted
* **Data Collection**: Respects consent preferences in real-time

This means visitors always see the correct test variant, but their data is only included in analytics when they've consented to tracking.

#### Custom Consent Management Platforms

If you're using a third-party consent management platform that doesn't integrate with Shopify's Customer Privacy API, use the `setAnalyticsConsent()` method to manually manage consent status.

**The setAnalyticsConsent Method**

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

**Parameters:**

* `consent` (boolean): `true` to enable analytics tracking, `false` to disable

**Returns**

* Promise that resolves when consent preference is updated

#### Basic Implementation Pattern

```javascript
// Generic implementation for any consent platform
function syncConsentWithShoplift(hasConsent) {
  if (window.shoplift && window.shoplift.setAnalyticsConsent) {
    window.shoplift.setAnalyticsConsent(hasConsent)
      .then(() => {
        console.log('Shoplift consent updated:', hasConsent);
      })
      .catch(error => {
        console.error('Failed to update Shoplift consent:', error);
      });
  } else {
    // Retry if Shoplift isn't loaded yet
    setTimeout(() => syncConsentWithShoplift(hasConsent), 100);
  }
}

// Example: Listen for consent changes from your platform
window.addEventListener('consentUpdated', (event) => {
  const hasAnalyticsConsent = event.detail.analytics || event.detail.statistics;
  syncConsentWithShoplift(hasAnalyticsConsent);
});
```

#### Understanding Consent Categories

Different consent platforms use various category names. Map these to Shoplift's analytics consent:

| Category   | Maps to Shoplift | Description                           |
| ---------- | ---------------- | ------------------------------------- |
| Analytics  | Enable tracking  | Performance measurement and analytics |
| Marketing  | Not required     | Shoplift doesn't do remarketing       |
| Functional | Not required     | Test assignment works regardless      |
| Necessary  | Not required     | Core functionality always available   |

**Important Notes**

1. **Test variants always display correctly** regardless of consent status
2. **Only analytics data collection** is affected by consent
3. **Consent can be updated** at any time during the session

#### Best Practices

1. **Set consent early**: Update consent status as soon as it's available
2. **Handle consent changes**: Listen for updates throughout the session
3. **Be transparent**: Clearly communicate what data is collected
4. **Test thoroughly**: Verify behavior with consent both granted and denied
5. **Document your setup**: Keep track of how consent categories map to Shoplift
