Mini-Cart Test

This example demonstrates how to test showing or hiding a specific element (like a free shipping message) in your mini cart. Visitors only enter the test when they interact with the cart.

What We're Testing

  • Control: Standard mini cart without promotional message

  • Variant: Mini cart with free shipping progress bar

Step 1: Create Your Test in Shoplift

  1. Navigate to Tests → Create New Test

  2. Select "JavaScript API" as the test type

  3. Choose Manual trigger (only assigns users who open cart)

  4. Create your hypothesis and copy the ID

Step 2: Add HTML Structure

Add the test element to your mini cart, hidden by default:

<!-- In your mini cart template -->
<div class="mini-cart">
  <div class="cart-header">
    <h3>Your Cart</h3>
    <button class="close-cart">×</button>
  </div>
  
  <!-- Free shipping element - hidden by default -->
  <div class="free-shipping-progress" style="display: none; opacity: 0;">
    <div class="shipping-message">
      <span class="shipping-icon">🚚</span>
      <span class="shipping-text">You're $<span class="amount-remaining">50</span> away from free shipping!</span>
    </div>
    <div class="progress-bar">
      <div class="progress-fill" style="width: 0%"></div>
    </div>
  </div>
  
  <div class="cart-items">
    <!-- Cart items here -->
  </div>
  
  <div class="cart-footer">
    <!-- Checkout button etc -->
  </div>
</div>

Step 3: Add CSS for Smooth Transitions

Step 4: Implement the Test Logic

Step 5: Test Your Implementation

1. Force the Variant

Open the cart - you should see the free shipping message.

2. Test Control

Open in incognito without URL parameters - the message should be hidden.

3. Debug in Console

Last updated

Was this helpful?