getVisitorData()

Returns data about the current visitor and their A/B test assignments. This is a synchronous method — it returns data immediately without a Promise.

The primary use case is sending Shoplift test data to third-party analytics platforms so you can analyze test results alongside your existing metrics.

Signature

window.shoplift.getVisitorData(): ExternalVisitorData

Parameters

None.

Returns

ExternalVisitorData — an object containing two properties:

interface ExternalVisitorData {
  visitor: Visitor | null;
  visitorTests: ExternalTestRelation[];
}

Note: This is a synchronous call (not a Promise). No await needed. Invalid test assignments are automatically filtered out, and internal tracking fields are excluded.

visitor

Information about the current visitor. Returns null if the visitor hasn't been synced with the server yet (typically because this is the visitor's first page load and analytics consent hasn't been granted). Once populated, the visitor object persists in memory for the remainder of the session.

interface Visitor {
  id: string;                        // Unique Shoplift visitor ID (UUID)
  storedAt: Date;                    // When visitor record was last stored
  createdAt: Date;                   // When visitor first arrived
  shopifyAnalyticsId: string | null; // Shopify's analytics ID (if available)
  device: 'desktop' | 'mobile';     // Device type
  country: string | null;           // Visitor country (if available)
  utmSource: string;                // UTM source parameter
  utmMedium: string;                // UTM medium parameter
  utmCampaign: string;              // UTM campaign parameter
  utmContent: string;               // UTM content parameter
  referrer: string;                 // Original referring URL
}

visitorTests

An array of test assignments for the current visitor. Each entry represents one test the visitor is participating in. Internal tracking fields are removed before returning.

In practice, every entry in the returned array will have a non-null hypothesisId — blocked and excluded visitors are filtered out automatically.

Basic Usage

Common Patterns

Send Test Data to an Analytics Platform

Retrieve visitor data and forward it to your analytics tool:

For platform-specific implementations, see the integration guides for Segment, Heap, Hotjar, Microsoft Clarity, and Adobe Analytics.

Debugging in the Console

Quick way to inspect the current visitor state:

Conditional Logic Based on Test Participation

Check whether a visitor is in any test before running custom logic:

Edge Cases

  • Visitor is null: The visitor object is null until Shoplift has synced with the server, which requires analytics consent. On return visits, the visitor may be rehydrated from stored state. In preview mode (?isShopliftMerchant=true), visitor is always null.

  • Invalid assignments filtered: Internally invalid test assignments (marked isInvalid) are automatically excluded from the returned array — you don't need to filter them yourself.

  • No active tests: If the visitor isn't participating in any tests, visitorTests will be an empty array. visitor data may still be available.

  • UTM parameters: UTM fields are populated from the visitor's landing page URL. They'll be empty strings if no UTM parameters were present.

  • Country detection: The country field uses GeoIP and may be null if the visitor's location couldn't be determined.

Last updated

Was this helpful?