AxiTrace Begin Checkout event - parameters, required fields, and integration examples.

Begin Checkout Event

Track when users initiate the checkout process. This event maps to Facebook InitiateCheckout and TikTok InitiateCheckout standard events, enabling checkout abandonment analysis, retargeting audiences, and conversion funnel optimization.

POST /v1/checkout/begin

When to Use This Event

The begin_checkout event should be triggered when a user starts the checkout process. This typically occurs when:

  • User clicks "Checkout" or "Proceed to Checkout" button
  • User is redirected to the checkout page
  • User opens a checkout modal/drawer
  • First step of a multi-step checkout process loads
E-commerce Funnel Position

Begin Checkout is a key late-funnel event, right before the purchase. The typical e-commerce funnel tracked by AxiTrace is:

page.view → product.view → product.addToCart → begin_checkout → transaction.charge

Server Is Recommended, the Browser Works

Prefer your backend, through /v1/checkout/begin or the AxiTrace PHP SDK, because it gives you:

  • Accurate checkout state - the event fires when checkout actually initiates on your backend
  • Ad-blocker resistance - not affected by browser restrictions
  • Better security - Secret Keys stay out of the browser
  • Reliable Facebook CAPI delivery

The browser path works too: Axitrace._instance.track('begin_checkout', { ... }) is routed by /track, and if your shop already has a GA4 ecommerce dataLayer the SDK can translate its begin_checkout push for you - see the Google Tag Manager guide. Use it when you have no backend to send from; that is the whole point of a no-developer install.

Whichever you choose, send it from one side only. Both sides sending the same checkout counts it twice.

Related Checkout Events

AxiTrace tracks the complete checkout flow with these events:

Event Endpoint When to Trigger
begin_checkout /v1/checkout/begin User initiates checkout
add_shipping_info /v1/checkout/add_shipping_info User selects/enters shipping details
add_payment_info /v1/checkout/add_payment_info User enters payment information
transaction.charge /v1/transaction Purchase is completed

Request Parameters

Required Fields

Field Type Description
currency string ISO 4217 currency code (e.g., USD, EUR, GBP)
value number Total cart value. Must be >= 0. Maps to Facebook/TikTok value for ad optimization.
items array Array of items in the cart (see Items Array below)

User Identification

At least one of these identifiers is required:

Field Type Description
client_id string Your custom user/visitor identifier (use SDK's vt_vid cookie value)
user_id string Authenticated user ID (use SDK's vt_uid cookie value if set via identify())
session_id string Current session identifier (use SDK's vt_sid cookie value)
Critical: Match SDK User Identifiers

You must pass the same user identifiers that the JavaScript SDK generates. The SDK stores these in cookies:

  • vt_vid - Visitor ID → use as client_id
  • vt_sid - Session ID → use as session_id
  • vt_uid - User ID → use as user_id (if set via identify())

Read these cookies and pass them in your server-side events to properly link all events to the same user profile. See the User Identification guide for complete details.

Optional Fields

Field Type Description
email string Customer email address. Improves Facebook CAPI Event Match Quality by up to 41%.
phone string Customer phone number. Improves Facebook CAPI match quality.
coupon string Coupon code applied to the cart (e.g., SUMMER20)
payment_type string Payment method type (e.g., credit_card, paypal)
shipping_tier string Shipping tier selected (e.g., express, standard)
params object Additional custom parameters for your analytics needs

Items Array

Each item in the items array should contain:

Field Type Required Description
item_id string Required Product SKU or unique identifier
item_name string Recommended Product name
price number Recommended Unit price of the item
quantity integer Recommended Quantity of this item in cart
item_category string Optional Product category
item_brand string Optional Product brand
item_variant string Optional Product variant (e.g., Blue/Large)
discount number Optional Discount amount per item
coupon string Optional Item-specific coupon code

Facebook & TikTok Pixel Mapping

The begin_checkout event maps to these standard ad platform events:

AxiTrace Facebook Pixel TikTok Pixel
begin_checkout InitiateCheckout InitiateCheckout

When tracked server-side, the event is forwarded to Facebook CAPI and TikTok Events API. Including email and value/currency significantly improves match quality and enables value-based optimization.

Server-Enriched Fields

The following fields are automatically added by the server:

Field Description
ip Client IP address (extracted from X-Forwarded-For, CF-Connecting-IP, etc.)
userAgent Browser User-Agent string
timestamp Server timestamp (ISO 8601 format)

Examples

Server-Side (PHP SDK - Recommended)

<?php
use AxiTrace\AxiTrace;
use AxiTrace\Model\Product;

$axitrace = AxiTrace::init('sk_live_YOUR_SECRET_KEY');

// Read SDK cookies - CRITICAL for user profile linking
$visitorId = $_COOKIE['vt_vid'] ?? null;
$sessionId = $_COOKIE['vt_sid'] ?? null;

if ($visitorId) {
    $axitrace->setClientId($visitorId);
}
if ($sessionId) {
    $axitrace->setSessionId($sessionId);
}

// Forward client context for Facebook CAPI
$axitrace->setClientIp($_SERVER['REMOTE_ADDR']);
$axitrace->setClientUserAgent($_SERVER['HTTP_USER_AGENT'] ?? '');
$axitrace->setPageUrl('https://yoursite.com/checkout');

// Build items array
$items = [];
foreach ($cart->getItems() as $cartItem) {
    $items[] = (new Product($cartItem->getSku()))
        ->setItemName($cartItem->getName())
        ->setPrice($cartItem->getUnitPrice())
        ->setCurrency($cart->getCurrency())
        ->setQuantity($cartItem->getQuantity());
}

$coupon = $cart->getCouponCode();

$response = $axitrace->beginCheckout(
    $cart->getTotal(),         // value
    $cart->getCurrency(),      // currency
    $items,                    // items array
    $coupon ? ['coupon' => $coupon] : []  // optional params
);

if ($response->isSuccess()) {
    // Event tracked: $response->getEventId()
}

Server-Side (cURL)

# Read SDK cookies (vt_vid, vt_sid, vt_uid) and pass as identifiers
curl -X POST https://stat.axitrace.com/v1/checkout/begin \
  -u "sk_live_YOUR_SECRET_KEY:" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "value-from-vt_vid-cookie",
    "user_id": "value-from-vt_uid-cookie",
    "session_id": "value-from-vt_sid-cookie",
    "email": "customer@example.com",
    "currency": "USD",
    "value": 199.98,
    "coupon": "SUMMER20",
    "items": [
        {
            "item_id": "WIDGET-001",
            "item_name": "Premium Widget",
            "item_category": "Electronics",
            "item_brand": "WidgetCo",
            "price": 99.99,
            "quantity": 2
        }
    ]
  }'

Server-Side (PHP - Raw HTTP)

<?php
$secretKey = getenv('AXITRACE_SECRET_KEY');

// Read AxiTrace SDK cookies - CRITICAL for user profile linking
$visitorId = $_COOKIE['vt_vid'] ?? null;
$sessionId = $_COOKIE['vt_sid'] ?? null;
$userId = $_COOKIE['vt_uid'] ?? null;

// Get cart data from your application
$cart = getCart();
$customer = getCurrentCustomer();

// Build items array
$items = [];
foreach ($cart->getItems() as $item) {
    $items[] = [
        'item_id' => $item->getSku(),
        'item_name' => $item->getName(),
        'item_category' => $item->getCategory(),
        'item_brand' => $item->getBrand(),
        'price' => $item->getUnitPrice(),
        'quantity' => $item->getQuantity(),
    ];
}

$data = [
    'client_id' => $visitorId,
    'user_id' => $userId,
    'session_id' => $sessionId,
    'email' => $customer?->getEmail(),
    'currency' => $cart->getCurrency(),
    'value' => $cart->getTotal(),
    'coupon' => $cart->getCouponCode(),
    'items' => $items,
];

// Remove null values
$data = array_filter($data, fn($v) => $v !== null);

$ch = curl_init('https://stat.axitrace.com/v1/checkout/begin');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_USERPWD => $secretKey . ':',
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'User-Agent: MyApp/1.0'
    ],
    CURLOPT_POSTFIELDS => json_encode($data)
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode === 200) {
    $result = json_decode($response, true);
    // Event tracked successfully
}

Server-Side (Python)

import os
import requests
from flask import request  # Example using Flask

secret_key = os.environ.get('AXITRACE_SECRET_KEY')

# Read AxiTrace SDK cookies - CRITICAL for user profile linking
visitor_id = request.cookies.get('vt_vid')
session_id = request.cookies.get('vt_sid')
user_id = request.cookies.get('vt_uid')

# Get cart data from your application
cart = get_cart()
customer = get_current_customer()

# Build items array
items = [{
    'item_id': item.sku,
    'item_name': item.name,
    'item_category': item.category,
    'item_brand': item.brand,
    'price': float(item.unit_price),
    'quantity': item.quantity,
} for item in cart.items]

response = requests.post(
    'https://stat.axitrace.com/v1/checkout/begin',
    auth=(secret_key, ''),
    headers={
        'Content-Type': 'application/json',
        'User-Agent': 'MyApp/1.0'
    },
    json={
        'client_id': visitor_id,
        'user_id': user_id,
        'session_id': session_id,
        'email': customer.email if customer else None,
        'currency': cart.currency,
        'value': float(cart.total),
        'coupon': cart.coupon_code,
        'items': items,
    }
)

if response.status_code == 200:
    result = response.json()
    print(f"Event tracked: {result['eventId']}")

Response

Success Response (200 OK)

{
    "success": true,
    "eventId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "action": "begin_checkout"
}

Error Responses

Status Error Description
400 at least one of client_id, user_id, or session_id is required No user identifier provided
400 currency is required Missing currency field
400 value must be >= 0 Value is negative
400 items array is required Items array is empty or missing
401 unauthorized Invalid or missing API key

E-commerce Integration Examples

WooCommerce (WordPress)

<?php
// Track begin checkout when the checkout page loads (server-side)
add_action('woocommerce_before_checkout_form', function() {
    $cart = WC()->cart;
    if ($cart->is_empty()) return;

    $secretKey = get_option('axitrace_secret_key');
    $visitorId = $_COOKIE['vt_vid'] ?? null;
    $sessionId = $_COOKIE['vt_sid'] ?? null;

    if (!$visitorId && !$sessionId) return;

    $items = [];
    foreach ($cart->get_cart() as $cart_item) {
        $product = $cart_item['data'];
        $items[] = [
            'item_id' => $product->get_sku() ?: (string)$product->get_id(),
            'item_name' => $product->get_name(),
            'item_category' => implode('/', wp_get_post_terms(
                $product->get_id(), 'product_cat', ['fields' => 'names']
            )),
            'price' => (float)$product->get_price(),
            'quantity' => $cart_item['quantity'],
        ];
    }

    $coupons = $cart->get_applied_coupons();

    $data = array_filter([
        'client_id' => $visitorId,
        'session_id' => $sessionId,
        'email' => wp_get_current_user()->user_email ?? null,
        'currency' => get_woocommerce_currency(),
        'value' => (float)$cart->get_total('raw'),
        'coupon' => $coupons[0] ?? null,
        'items' => $items,
    ], fn($v) => $v !== null);

    wp_remote_post('https://stat.axitrace.com/v1/checkout/begin', [
        'headers' => [
            'Authorization' => 'Basic ' . base64_encode($secretKey . ':'),
            'Content-Type' => 'application/json',
        ],
        'body' => json_encode($data),
        'timeout' => 5,
        'blocking' => false, // Non-blocking to avoid slowing checkout
    ]);
});

Shopify

// Shopify Web Pixel - track begin checkout
// This fires via Shopify's server-to-server pixel infrastructure
analytics.subscribe("checkout_started", (event) => {
    const checkout = event.data.checkout;

    fetch('https://stat.axitrace.com/v1/checkout/begin', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Basic ' + btoa('sk_live_YOUR_SECRET_KEY:')
        },
        body: JSON.stringify({
            client_id: getCookie('vt_vid'),
            session_id: getCookie('vt_sid'),
            currency: checkout.currencyCode,
            value: parseFloat(checkout.totalPrice.amount),
            coupon: checkout.discountApplications?.[0]?.title || '',
            items: checkout.lineItems.map(item => ({
                item_id: item.variant?.sku || item.id,
                item_name: item.title,
                price: parseFloat(item.variant?.price?.amount || 0),
                quantity: item.quantity
            }))
        })
    });
});

Best Practices

  • Track at the right moment - Fire the event when the checkout page loads (GET request), not on form submission
  • Include email - Improves Facebook CAPI Event Match Quality by up to 41%. If the user is logged in, always pass their email.
  • Include value and currency - Enables value-based optimization in Facebook/TikTok ad campaigns
  • Include all items - Always pass the complete cart contents in the items array
  • Use consistent identifiers - Match item_id with SKUs used in product.view and product.addToCart
  • Track coupons - Include coupon codes to measure promotion effectiveness
  • Match SDK identifiers - Read SDK cookies (vt_vid, vt_sid) and pass them to link events
  • Single event per checkout - Fire once when checkout begins, not on every step. If the user refreshes, the event will be sent again (which is acceptable - the backend handles deduplication)
Checkout Abandonment Analysis

Tracking begin_checkout events enables powerful abandonment analysis. AxiTrace helps you identify:

  • Checkout abandonment rate (begin_checkout without transaction)
  • Where users drop off in multi-step checkouts
  • Cart values that are abandoned vs completed
  • Impact of coupon codes on checkout completion
  • Time between checkout start and purchase completion