E-Commerce Event Tracking

Track product views, cart actions, purchases, and refunds with the JustAnalytics e-commerce API.

Overview#

JustAnalytics provides a dedicated e-commerce tracking API that captures the full shopping journey -- from product impressions to purchase completion and refunds. This data powers revenue dashboards, product performance reports, funnel analysis, and attribution modeling.

E-commerce tracking uses the client-side JA.trackEcommerce() method, which sends structured events to the JustAnalytics ingestion API. No additional script is required beyond the standard tracker.

Prerequisites#

Ensure the tracking script is installed on your site:

<script
  defer
  src="https://justanalytics.app/tracker.js"
  data-site-id="YOUR_SITE_ID"
></script>

The JA global object is available after the script loads. For safety, wrap calls in a check:

if (typeof JA !== 'undefined') {
  JA.trackEcommerce('view_item', { /* ... */ });
}

E-Commerce Event Types#

view_item -- Product Viewed#

Fire when a user views a product detail page:

JA.trackEcommerce('view_item', {
  currency: 'USD',
  value: 49.99,
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      item_category: 'Electronics',
      item_category2: 'Audio',
      item_brand: 'SoundMax',
      price: 49.99,
      quantity: 1,
    },
  ],
});

view_item_list -- Product List Viewed#

Fire when a user views a category page, search results, or product carousel:

JA.trackEcommerce('view_item_list', {
  item_list_id: 'category_electronics',
  item_list_name: 'Electronics',
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      item_category: 'Electronics',
      item_brand: 'SoundMax',
      price: 49.99,
      index: 1,
    },
    {
      item_id: 'SKU-67890',
      item_name: 'USB-C Charging Cable',
      item_category: 'Electronics',
      item_brand: 'ChargePro',
      price: 12.99,
      index: 2,
    },
    {
      item_id: 'SKU-11111',
      item_name: 'Laptop Stand',
      item_category: 'Electronics',
      item_brand: 'DeskRise',
      price: 34.99,
      index: 3,
    },
  ],
});

select_item -- Product Clicked from List#

Fire when a user clicks a product from a list (category page, search results, carousel):

JA.trackEcommerce('select_item', {
  item_list_id: 'search_results',
  item_list_name: 'Search Results',
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      item_category: 'Electronics',
      price: 49.99,
      index: 3, // Position in the list
    },
  ],
});

add_to_cart -- Item Added to Cart#

Fire when a user adds an item to their shopping cart:

JA.trackEcommerce('add_to_cart', {
  currency: 'USD',
  value: 49.99,
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      item_category: 'Electronics',
      item_brand: 'SoundMax',
      item_variant: 'Black',
      price: 49.99,
      quantity: 1,
    },
  ],
});

remove_from_cart -- Item Removed from Cart#

Fire when a user removes an item from their cart:

JA.trackEcommerce('remove_from_cart', {
  currency: 'USD',
  value: 49.99,
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      price: 49.99,
      quantity: 1,
    },
  ],
});

view_cart -- Cart Viewed#

Fire when a user opens their shopping cart page:

JA.trackEcommerce('view_cart', {
  currency: 'USD',
  value: 112.97,
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      price: 49.99,
      quantity: 1,
    },
    {
      item_id: 'SKU-67890',
      item_name: 'USB-C Charging Cable',
      price: 12.99,
      quantity: 2,
    },
    {
      item_id: 'SKU-11111',
      item_name: 'Laptop Stand',
      price: 34.99,
      quantity: 1,
    },
  ],
});

begin_checkout -- Checkout Started#

Fire when a user begins the checkout process:

JA.trackEcommerce('begin_checkout', {
  currency: 'USD',
  value: 112.97,
  coupon: 'SUMMER20',
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      price: 49.99,
      quantity: 1,
    },
    {
      item_id: 'SKU-67890',
      item_name: 'USB-C Charging Cable',
      price: 12.99,
      quantity: 2,
    },
    {
      item_id: 'SKU-11111',
      item_name: 'Laptop Stand',
      price: 34.99,
      quantity: 1,
    },
  ],
});

add_shipping_info -- Shipping Info Added#

Fire when a user submits their shipping information:

JA.trackEcommerce('add_shipping_info', {
  currency: 'USD',
  value: 112.97,
  shipping_tier: 'express',
  items: [/* same items array */],
});

add_payment_info -- Payment Info Added#

Fire when a user submits their payment method:

JA.trackEcommerce('add_payment_info', {
  currency: 'USD',
  value: 112.97,
  payment_type: 'credit_card',
  items: [/* same items array */],
});

purchase -- Purchase Completed#

Fire when a transaction is completed successfully. This is the most important e-commerce event:

JA.trackEcommerce('purchase', {
  transaction_id: 'TXN-20260315-001',
  currency: 'USD',
  value: 122.96,
  tax: 9.99,
  shipping: 5.99,
  coupon: 'SUMMER20',
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      item_category: 'Electronics',
      item_category2: 'Audio',
      item_brand: 'SoundMax',
      item_variant: 'Black',
      price: 49.99,
      quantity: 1,
      coupon: 'SUMMER20',
      discount: 10.00,
    },
    {
      item_id: 'SKU-67890',
      item_name: 'USB-C Charging Cable',
      item_category: 'Electronics',
      item_brand: 'ChargePro',
      price: 12.99,
      quantity: 2,
    },
    {
      item_id: 'SKU-11111',
      item_name: 'Laptop Stand',
      item_category: 'Electronics',
      item_brand: 'DeskRise',
      price: 34.99,
      quantity: 1,
    },
  ],
});

Important: Always fire the purchase event on the order confirmation page, not the checkout page. Ensure transaction_id is unique per order to prevent duplicate tracking.

refund -- Refund Processed#

Fire when an order is fully or partially refunded:

// Full refund
JA.trackEcommerce('refund', {
  transaction_id: 'TXN-20260315-001',
  currency: 'USD',
  value: 122.96,
});

// Partial refund (specific items)
JA.trackEcommerce('refund', {
  transaction_id: 'TXN-20260315-001',
  currency: 'USD',
  value: 49.99,
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Bluetooth Headphones',
      price: 49.99,
      quantity: 1,
    },
  ],
});

Item Schema Reference#

Each item in the items array supports the following fields:

| Field | Type | Required | Description | |-------|------|----------|-------------| | item_id | string | Yes | Unique product identifier (SKU) | | item_name | string | Yes | Product name | | item_category | string | No | Primary category | | item_category2 | string | No | Secondary category | | item_category3 | string | No | Tertiary category | | item_brand | string | No | Brand name | | item_variant | string | No | Variant (color, size, etc.) | | price | number | Yes | Unit price | | quantity | number | Yes | Quantity (default: 1) | | coupon | string | No | Item-level coupon code | | discount | number | No | Discount amount per item | | index | number | No | Position in a list | | currency | string | No | ISO 4217 currency code (inherits from event) |

Revenue Tracking#

Revenue is calculated from purchase events. The value field on each purchase event represents the total order value including tax and shipping. Refund events subtract from total revenue.

Revenue Formula#

Net Revenue = Sum(purchase.value) - Sum(refund.value)
Product Revenue = Sum(item.price * item.quantity) across purchases - refunds
Average Order Value = Net Revenue / Number of Purchases

Multi-Currency Support#

If your store supports multiple currencies, always include the currency field:

// EUR transaction
JA.trackEcommerce('purchase', {
  transaction_id: 'TXN-EU-001',
  currency: 'EUR',
  value: 89.99,
  items: [/* ... */],
});

// GBP transaction
JA.trackEcommerce('purchase', {
  transaction_id: 'TXN-UK-001',
  currency: 'GBP',
  value: 74.99,
  items: [/* ... */],
});

Revenue reports in the dashboard show a currency selector. You can view revenue in the original currency or convert to a base currency using daily exchange rates.

Purchase Funnel Analysis#

JustAnalytics automatically builds a purchase funnel from your e-commerce events:

view_item_list → select_item → view_item → add_to_cart → begin_checkout → purchase

The funnel report shows:

| Step | Sessions | Drop-off | |------|----------|----------| | View Item List | 10,000 | - | | Select Item | 6,200 | 38% | | View Item | 5,800 | 6.5% | | Add to Cart | 2,100 | 63.8% | | Begin Checkout | 890 | 57.6% | | Purchase | 420 | 52.8% |

Identifying Drop-off Points#

When you see high drop-off between steps:

  1. Click the drop-off percentage in the funnel report
  2. View session replays of users who dropped off at that step
  3. Look for frustration signals (rage clicks, errors, long pauses)
  4. Compare device types -- mobile often has higher checkout abandonment

Integration with Attribution Models#

E-commerce revenue data integrates with JustAnalytics attribution modeling to answer "which marketing channels drive the most revenue?"

See E-Commerce Reports for attribution-linked revenue reports and Conversions for setting up revenue-based conversion goals.

Framework Examples#

React / Next.js#

// components/ProductCard.tsx
export function ProductCard({ product }) {
  const handleClick = () => {
    JA.trackEcommerce('select_item', {
      items: [{
        item_id: product.sku,
        item_name: product.name,
        item_category: product.category,
        price: product.price,
      }],
    });
  };

  return (
    <div onClick={handleClick}>
      <img src={product.image} alt={product.name} />
      <h3>{product.name}</h3>
      <p>${product.price}</p>
    </div>
  );
}

// components/AddToCartButton.tsx
export function AddToCartButton({ product, quantity }) {
  const handleAddToCart = () => {
    addItemToCart(product, quantity);
    JA.trackEcommerce('add_to_cart', {
      currency: 'USD',
      value: product.price * quantity,
      items: [{
        item_id: product.sku,
        item_name: product.name,
        item_category: product.category,
        price: product.price,
        quantity,
      }],
    });
  };

  return <button onClick={handleAddToCart}>Add to Cart</button>;
}

Shopify (Liquid)#

<!-- In theme.liquid or a snippet -->
<script>
  document.addEventListener('DOMContentLoaded', function() {
    {% if template == 'product' %}
    JA.trackEcommerce('view_item', {
      currency: '{{ shop.currency }}',
      value: {{ product.price | money_without_currency }},
      items: [{
        item_id: '{{ product.variants.first.sku }}',
        item_name: '{{ product.title | escape }}',
        item_category: '{{ product.type | escape }}',
        item_brand: '{{ product.vendor | escape }}',
        price: {{ product.price | money_without_currency }},
        quantity: 1,
      }],
    });
    {% endif %}
  });
</script>

WooCommerce#

<!-- In your theme's functions.php or a custom plugin -->
<script>
  document.addEventListener('DOMContentLoaded', function() {
    <?php if (is_product()) : ?>
    <?php global $product; ?>
    JA.trackEcommerce('view_item', {
      currency: '<?php echo get_woocommerce_currency(); ?>',
      value: <?php echo $product->get_price(); ?>,
      items: [{
        item_id: '<?php echo $product->get_sku(); ?>',
        item_name: '<?php echo esc_js($product->get_name()); ?>',
        item_category: '<?php echo esc_js(
          wp_get_post_terms($product->get_id(), 'product_cat')[0]->name ?? ''
        ); ?>',
        price: <?php echo $product->get_price(); ?>,
        quantity: 1,
      }],
    });
    <?php endif; ?>
  });
</script>

Validating Your Setup#

Real-Time Event Stream#

  1. Navigate to Dashboard > Live Stream
  2. Trigger e-commerce events on your site
  3. Verify each event appears with the correct type and data

Browser DevTools#

Open the Network tab and filter for requests to /api/track. Each e-commerce event should appear as a POST request with the event payload:

{
  "type": "ecommerce",
  "action": "purchase",
  "data": {
    "transaction_id": "TXN-001",
    "currency": "USD",
    "value": 122.96,
    "items": [...]
  }
}

Common Mistakes#

  • Missing transaction_id on purchase -- causes duplicate tracking on page refresh
  • Firing purchase on checkout page -- should fire on confirmation/thank-you page
  • Wrong value calculation -- value should be the total including tax and shipping
  • Missing currency -- defaults to USD if not specified
  • Duplicate events -- ensure events fire once per action, not on every render

Next Steps#