# Heap

Track Shoplift test variants in Heap to leverage automatic event capture and retroactive analysis capabilities.

#### Quick Start

Add this code after your Heap snippet:

```javascript
// Heap + Shoplift Integration
function initializeShopliftHeap() {
  if (window.shoplift && window.heap) {
    const visitorData = window.shoplift.getVisitorData();
    
    if (visitorData.visitor && visitorData.visitorTests.length > 0) {
      // Add user properties (works on both anonymous and identified users)
      const properties = {
        shoplift_visitor_id: visitorData.visitor.id,
        shoplift_device: visitorData.visitor.device,
        shoplift_first_seen: visitorData.visitor.createdAt.toISOString()
      };
      
      // Only add country if present
      if (visitorData.visitor.country) {
        properties.shoplift_country = visitorData.visitor.country;
      }
      
      // Add test assignments as properties
      visitorData.visitorTests.forEach(test => {
        properties[`test_${test.testId}`] = test.hypothesisId;
        properties[`test_${test.testId}_type`] = test.isThemeTest ? 'theme' : 'element';
        properties[`test_${test.testId}_assigned`] = test.createdAt.toISOString();
      });
      
      heap.addUserProperties(properties);
      
      // Track test exposure events
      visitorData.visitorTests.forEach(test => {
        heap.track('Shoplift Test Exposure', {
          test_id: test.testId,
          variant_id: test.hypothesisId,
          is_theme_test: test.isThemeTest
        });
      });
    }
  } else {
    setTimeout(initializeShopliftHeap, 100);
  }
}

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

#### Retroactive Analysis

Heap's automatic event capture means you can:

**Define Events After the Fact**

Create new events in Heap's UI and immediately analyze them by test variant without requiring code changes.

**Build Test-Specific Funnels**

1. Go to **Analyze > Funnels**
2. Add your conversion steps
3. Filter by `test_[test_id]` property
4. Compare conversion rates across variants

**Create Variant Cohorts**

1. Navigate to **Users > Segments**
2. Create segments based on test properties
3. Analyze long-term behavior differences

#### Visual Labeling

Use Heap's visual labeling to:

1. Tag elements involved in your tests
2. Create events specific to test interactions
3. Track engagement with variant-specific elements

#### Best Practices

1. **Use consistent property naming** (`test_` prefix for all test properties)
2. **Include assignment timestamps** to analyze time-based effects
3. **Track both automatic and manual allocation** tests
4. **Create saved reports** for each major test
5. **Export data via API** for custom analysis


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shoplift.ai/api-reference/guides/analytics-integrations/heap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
