getVisitorData()

Retrieve visitor information and test assignments for analytics and debugging.

getVisitorData()

Returns comprehensive 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 (Segment, Heap, Hotjar, etc.) so you can analyze test results alongside your existing metrics.

Signature

window.shoplift.getVisitorData(): VisitorData

Parameters

None.

Returns

VisitorData — an object containing two properties:

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

visitor

Information about the current visitor. May be null if the visitor hasn't been initialized yet.

visitorTests

An array of test assignments for the current visitor. Each entry represents one test the visitor is participating in.

Basic Usage

Common Patterns

Send Test Data to an Analytics Platform

This is the core pattern used by all custom analytics integrations. 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 not initialized: If called before Shoplift has fully initialized, visitor will be null and visitorTests will be an empty array. Use a polling pattern to wait for data.

  • No active tests: If the visitor isn't participating in any tests, visitorTests will be an empty array. visitor data will 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?