Skip to content

E-Commerce Tracking

All method calls must be inside the async IIFE shown in the Getting Started guide for sub-pages.

Track Product View

No URL params — call on product detail pages.

javascript
await sdk.trackProductDetailsViewed({
  product: {
    productId: "PROD-001",
    name: "Running Shoes",
    price: 44.99,
    category: "Footwear", // Optional
    sku: "SHOE-RUN-42", // Optional
  },
});

Track Add to Cart

No URL params — call when user adds an item to cart.

javascript
await sdk.trackAddToCart({
  cartId: "cart_abc", // Optional
  items: [
    {
      productId: "PROD-001",
      name: "Running Shoes",
      price: 44.99,
      quantity: 1,
      category: "Footwear", // Optional
      sku: "SHOE-RUN-42", // Optional
    },
  ],
});

Track Remove from Cart

No URL params — call when user removes an item from cart.

javascript
await sdk.trackRemoveFromCart({
  cartId: "cart_abc", // Optional
  items: [{ productId: "PROD-001", quantity: 1 }],
});

Track Order

No URL params — call on the order confirmation page. Duplicate orders are automatically prevented.

Attribution: The SDK sends cookie_token in the order payload. The backend resolves which affiliate (ref) and discount code were used by looking up cookie_token against the original click record. No ref or discount_code fields are sent explicitly.

javascript
const result = await sdk.trackOrder({
  orderId: "ORD-12345",
  total: 99.99,
  subtotal: 89.99, // Optional
  discount: 10.0, // Optional
  tax: 8.0, // Optional
  customer: {
    email: "customer@example.com",
    userId: "user_12345", // Optional
    name: "John Doe", // Optional
    address: {
      // Optional
      address_line1: "123 Main St",
      city: "New York",
      state: "NY",
      country: "US",
    },
  },
  lineItems: [
    // Optional — required for revenue-by-category reporting
    {
      productId: "PROD-001",
      name: "Running Shoes",
      qty: 2,
      price: 44.99,
      category: "Footwear", // Optional
    },
  ],
});
// Returns: { conversionId, commissionAmount, affiliateId }

Track Thank You Page

No URL params — call after trackOrder() on the order confirmation page.

javascript
await sdk.trackThankYouPageViewed({
  orderId: "ORD-12345",
  customer: {
    email: "customer@example.com",
  },
});

Released under the MIT License.