How to Access the A/B Test Group Index for Custom Code Injection

If you’d like to inject custom JavaScript or CSS into your A/B test variants, you can use the test group index stored in the browser’s localStorage to conditionally apply changes. This is useful for developers or advanced users who want to apply logic based on whether a visitor is in the control or test group.

How It Works

Our A/B testing script assigns visitors to a test group based on your test configuration and stores this information in the browser’s local storage. This value can be read and used in your custom scripts or styles.

Group Index Reference

Group Index
Description

0

Original group

1

Variant 1

2

Variant 2

3

Variant 3

4

Variant 4

Accessing the Test Group Index

You can read the test metadata from the browser’s localStorage. Each test stores data under a specific key and includes information like experimentId, groupIndex, and sometimes startTime.

Test type
Key
Value

Price test (cart transform)

abconvert-experiment-to-group-index

{ experimentId, groupIndex}

Price test (duplicate variant)

abconvert-price-test-experiment-to-group-index

{ experimentId, groupIndex}

Url redirect test

abconvert-url-redirect-test-${experimentId}

{ experimentId, groupIndex, startTime }

Template test

abconvert-template-test-${experimentId}

{ experimentId, groupIndex, startTime }

Theme test

abconvert-theme-test-${experimentId}

{ experimentId, groupIndex, startTime }

Delivery customization test

abconvert-delivery-customization-test-experiment-to-group-index

{ experimentId, groupIndex}

Payment customization test

abconvert-payment-customization-test-experiment-to-group-index

{ experimentId, groupIndex}

Checkout UI test

abconvert-checkout-ui-test-experiment-to-group-index

{ experimentId, groupIndex}

experimentId

This is the unique identifier of the test in our database. It helps track and differentiate between various experiments running on your store.

startTime (included in some tests)

The timestamp (in milliseconds) representing when the test started running on your store.

For shipping test, please refer to Shipping Test Event Listeners.

Last updated