> For the complete documentation index, see [llms.txt](https://docs.shoplift.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shoplift.ai/test/javascript-api/core-api-reference/getvisitordata.md).

# getVisitorData

### Access Visitor and Test Information

The `getVisitorData()` method provides comprehensive information about the current visitor and their test assignments. This synchronous method is essential for analytics integration, debugging, and understanding visitor behavior across your A/B tests.

### Method Signature

```javascript
getVisitorData(): VisitorData
```

#### Parameters

None - this method takes no parameters.

#### Returns

| Type        | Description                                                                         |
| ----------- | ----------------------------------------------------------------------------------- |
| VisitorData | Object containing visitor information and test assignments (returned synchronously) |

### Return Structure

```typescript
interface VisitorData {
  visitor: Visitor | null;
  visitorTests: TestRelation[];
}

interface Visitor {
  id: string;                        // Unique Shoplift visitor ID
  shopifyAnalyticsId: string | null; // Shopify's analytics visitor ID
  device: 'desktop' | 'mobile';      // Device type
  country: string | null;             // Two-letter country code (e.g., 'US', 'CA')
  createdAt: Date;                    // First visit timestamp
  storedAt: Date;                     // Last updated timestamp
  utmSource: string;                  // UTM source parameter
  utmMedium: string;                  // UTM medium parameter
  utmCampaign: string;                // UTM campaign parameter
  utmContent: string;                 // UTM content parameter
  referrer: string;                   // Referring URL
}

interface TestRelation {
  testId: string;                     // Unique test identifier
  hypothesisId: string;               // Hypothesis (variant) ID
  isThemeTest: boolean;               // Whether this is a theme test
  themeId?: number;                   // Shopify theme ID (if theme test)
  createdAt: Date;                    // Assignment timestamp
  isSaved: boolean;                   // Whether assignment is persisted
}
```

## Basic Usage

```javascript
// Get visitor data
const data = window.shoplift.getVisitorData();

// Access visitor information
if (data.visitor) {
  console.log('Visitor ID:', data.visitor.id);
  console.log('Device:', data.visitor.device);
  console.log('Country:', data.visitor.country);
}

// Access test assignments
data.visitorTests.forEach(test => {
  console.log('Test ID:', test.testId);
  console.log('Hypothesis ID:', test.hypothesisId);
  console.log('Assigned at:', test.createdAt);
});
```
