# Microsoft Clarity

```javascript
// Eraya + Microsoft Clarity Integration
function initializeErayaClarity() {
  if (window.Eraya && window.clarity) {
    const sdk = window.Eraya.getSDK();
    
    if (sdk) {
      const userManager = sdk.getUserManager();
      const erayaUserId = userManager.getErayaUserId();
      
      // Get all active experiments
      const activeTests = sdk.getActiveExperiments();
      
      if (activeTests && activeTests.length > 0) {
        // Track experiment exposures
        activeTests.forEach(test => {
          clarity('event', 'experiment_viewed', {
            experiment_id: test.testId,
            variant_id: test.variationId
          });
        });
        
        // Set user attributes with experiment data
        const attributes = {
          eraya_user_id: erayaUserId,
          eraya_visitor_type: userManager.getVisitorType(),
          eraya_country: userManager.getUserCountry()
        };
        
        // Add each test as an attribute
        activeTests.forEach(test => {
          attributes[`eraya_test_${test.testId}`] = test.variationId;
        });
        
        clarity('identify', erayaUserId, attributes);
      }
    }
  } else {
    setTimeout(initializeErayaClarity, 100);
  }
}

// Initialize on page load
initializeErayaClarity();
```
