# OneTrust integration

## Configuration in AB Tasty Platform

You can configure OneTrust consent management directly within the AB Tasty platform through the **Settings > Privacy > Manage Visitor Consent** section using the JavaScript option.

#### Accessing the Configuration

1. Navigate to **Settings** in your AB Tasty dashboard
2. Go to **Privacy** section
3. Select **Manage Visitor Consent**
4. Choose **JavaScript option** for custom consent implementation

### OneTrust Group ID Checking

#### Legacy Implementation

For older OneTrust implementations:

```
javascriptUnwrapCopyreturn typeof window.OnetrustActiveGroups !== 'undefined' && 
       window.OnetrustActiveGroups.includes('C0002') && 
       window.OnetrustActiveGroups.includes('C0003');
```

#### Current Implementation

For recent OneTrust implementations that return comma-delimited strings:

```
javascriptUnwrapCopy// Check for Analytics consent (group 2)
return typeof OnetrustActiveGroups !== 'undefined' && 
       OnetrustActiveGroups.includes(',2,');

// Check for Marketing consent (group 4)
return typeof OnetrustActiveGroups !== 'undefined' && 
       OnetrustActiveGroups.includes(',4,');
```

{% hint style="success" %}
&#x20;Using  `.includes(',2,')` prevents false positives (e.g., matching group 12 when checking for group 2).
{% endhint %}

### Platform Configuration Details

#### JavaScript Consent Function Setup

In the AB Tasty privacy settings, you'll need to configure a JavaScript function that returns `true` when consent is granted and `false` when it's not. This function will be called by AB Tasty to determine whether to:

* Activate campaigns
* Collect visitor data
* Set tracking cookies

#### Configuration Options

{% tabs %}
{% tab title=" Single Consent Check" %}

```
javascriptUnwrapCopy// Simple consent check for analytics
function() {
    return typeof OnetrustActiveGroups !== 'undefined' && 
           OnetrustActiveGroups.includes(',2,');
}
```

{% endtab %}

{% tab title="Multiple Consent Categories" %}

```
javascriptUnwrapCopy// Check for both Analytics and Marketing consent
function() {
    return typeof OnetrustActiveGroups !== 'undefined' && 
           OnetrustActiveGroups.includes(',2,') && 
           OnetrustActiveGroups.includes(',4,');
}
```

{% endtab %}

{% tab title="Flexible Consent (Analytics OR Marketing)" %}

```
javascriptUnwrapCopy// Allow if either Analytics or Marketing consent is given
function() {
    if (typeof OnetrustActiveGroups === 'undefined') {
        return false;
    }
    return OnetrustActiveGroups.includes(',2,') || 
           OnetrustActiveGroups.includes(',4,');
}
```

{% endtab %}
{% endtabs %}

## Advanced Configuration Features

### Consent Monitoring

The platform automatically monitors consent changes and will:

* Start campaigns when consent is granted
* Stop data collection when consent is withdrawn
* Resume tracking when consent is re-granted

### Campaign Behavior Options

You can configure how campaigns behave based on consent status:

* **Wait for Consent**: Campaigns don't start until consent is given
* **Show Without Tracking**: Campaigns run but no data is collected until consent
* **Conditional Activation**: Different campaigns activate based on specific consent categories

## Testing Your Configuration

### In AB Tasty Platform

* Use the Preview Mode to test consent scenarios
* Check the Browser Console for consent-related logs
* Verify campaign activation in different consent states

### Browser Testing

```
javascriptUnwrapCopy// Test consent status in browser console
console.log('OneTrust Groups:', OnetrustActiveGroups);
console.log('Analytics Consent:', OnetrustActiveGroups.includes(',2,'));
console.log('Marketing Consent:', OnetrustActiveGroups.includes(',4,'));
```

## Common OneTrust Group Mappings

<table><thead><tr><th width="110.5234375">Group ID</th><th>Category</th><th>Description</th></tr></thead><tbody><tr><td><code>,1,</code></td><td>Strictly Necessary</td><td>Essential website functionality</td></tr><tr><td><code>,2,</code></td><td>Performance/Analytics</td><td>Website analytics and performance</td></tr><tr><td><code>,3,</code></td><td>Functional</td><td>Enhanced website features</td></tr><tr><td><code>,4,</code></td><td>Targeting/Marketing</td><td>Advertising and marketing cookies</td></tr></tbody></table>

### Best Practices for Platform Configuration

### 1. Start Simple

Begin with a basic consent check and gradually add complexity:

```
javascriptUnwrapCopy// Start with this
return typeof OnetrustActiveGroups !== 'undefined' && 
       OnetrustActiveGroups.includes(',2,');
```

### 2. Add Error Handling

```
javascriptUnwrapCopyfunction() {
    try {
        return typeof OnetrustActiveGroups !== 'undefined' && 
               OnetrustActiveGroups.includes(',2,');
    } catch (error) {
        console.error('Consent check error:', error);
        return false; // Default to no consent on error
    }
}
```

### 3. Log for Debugging

```
javascriptUnwrapCopyfunction() {
    const hasConsent = typeof OnetrustActiveGroups !== 'undefined' && 
                      OnetrustActiveGroups.includes(',2,');
    
    console.log('AB Tasty Consent Check:', {
        groups: OnetrustActiveGroups,
        hasConsent: hasConsent
    });
    
    return hasConsent;
}
```

## Validation and Monitoring

After configuration, monitor your setup through:

* **AB Tasty Analytics Dashboard**: Check visitor consent rates
* **Campaign Performance**: Verify campaigns activate correctly
* **Browser Developer Tools**: Monitor console logs for consent events
* **OneTrust Reports**: Cross-reference consent data

This configuration ensures your AB Tasty implementation respects user privacy preferences while maintaining optimal testing capabilities within GDPR compliance requirements.
