← Documentation

Tracking purchases

Views and clicks tell you whether your recommendations are looked at. Purchases tell you what they bring in, and they are also the strongest signal to train the model. Every site sends the same event, purchase; only where it is sent from changes.

It’s optional. Without purchases, recommendations show up and the model learns from views and clicks. Purchases add the attributed revenue in the console, and the strongest signal for the model.

What makes a purchase count

A purchase counts in the console’s attributed revenue when the same visitor clicked that product in a LIKYLY block (30 days at most) and the purchase has a numeric properties.price. LIKYLY ties the purchase to the click itself, through the visitor (session_id or user_id) and the product; a recommendation_id sent with the purchase comes first. A purchase with no click is still recorded and used for training. Send one event per product of the order.

FieldStatusRole
item_idRequiredThe product id, the same as in your LIKYLY catalog.
user_id and/or session_idRequiredThe signed-in customer, and/or the visitor's anonymous id (the same as for their views and clicks).
recommendation_idOptionalThe one of the recommendation where the product was clicked, if your code has it: it comes first. Without it, LIKYLY takes the recommendation of the same visitor's last click on this product (30 days) and notes properties.attribution = "click".
properties.priceFor attributed revenueThe unit price, as a number (49.9), not as text ("€49.90"). A line's revenue = price × quantity.
quantityRecommendedThe number of units (1 by default).
event_idRecommendedA unique key, for example purchase_<order>_<product>: a purchase sent twice only counts once.
properties.currency, .order_idOptionalKept as is with the event, for your own reconciliation.

Where to send it from, depending on your site

The rule: the purchase is sent from where the order is confirmed. When that place is your code, your code sends it; on Shopify, payment happens on Shopify’s checkout, where the theme’s code doesn’t run: a pixel relays it.

SiteTo do
Magento / Adobe Commerce (wizard module)AutomaticNothing to do: the module sends each purchase from the order confirmation page, with its price and the recommendation it came from.
WordPress / WooCommerce (LIKYLY plugin)AutomaticNothing to do: the plugin keeps the recommendation on the cart line, then sends the purchase when the order moves to “processing” or “completed”.
Shopify theme (wizard section)OptionalViews, impressions and clicks already go out from the theme section. To add add-to-carts and purchases (and revenue), paste the LIKYLY pixel (8 lines) once in the Shopify admin: payment happens on Shopify’s checkout, where theme code doesn’t run, and only a pixel sees these two events there.
Laravel (likyly/laravel package)OptionalOne required step: when the order is confirmed, send one purchase per line, with the same visitor as the click. LIKYLY ties the purchase to the click in the block itself.
Your code (SDK or REST API)OptionalOne required step: when the order is confirmed, send one purchase per line, with the same visitor as the click. LIKYLY ties the purchase to the click in the block itself.

Shopify: the pixel

On Shopify, payment happens on Shopify’s checkout, where the theme’s code doesn’t run. The LIKYLY pixel listens there for add-to-carts and orders, finds the recommendation of the click (kept in the browser by the LIKYLY block) and sends one purchase per product, with its price. It is 8 lines that load the LIKYLY script, kept up to date on our side. You paste it once, in the Shopify admin:

  1. Get the code: in the theme folder, npx @likyly/wizard pixel shows it with your public key and copies it; or, in the console, Events → Send purchases → Shopify: the code is ready there, with your public key.
  2. Shopify admin → Settings → Customer events → Add custom pixel; name it “LIKYLY”, paste the code, save, then Connect.
  3. Test from the store’s address, not from 127.0.0.1: the click in the block and the payment must happen on the same domain.
Show the pixel code
LIKYLY pixel for Shopify (replace the key)
// LIKYLY - add to cart and purchases, for the revenue of the recommendations.
const q = [];
analytics.subscribe("product_added_to_cart", (e) => q.push(e));
analytics.subscribe("checkout_completed", (e) => q.push(e));
const s = document.createElement("script");
s.src = "https://api.likyly.com/pixel/shopify.js";
s.onload = () => Likyly.pixel("pk_YOUR_PUBLIC_KEY", { analytics, browser, init, queue: q });
document.head.appendChild(s);

Only ever put a public key (pk_…) in a pixel. Changing your public key? Paste the pixel again with the new one.

Your code: SDK or REST API

The path of a sale, and what is left to do:

  1. 1Click in a block
    Already doneThe LIKYLY block sends the click, with its recommendation.
  2. 2Add to cart
    OptionalAn add_to_cart event, if you want it.
  3. 3Order confirmed
    To doOne purchase event per product, with its price.
The common thread: the same visitor · sessionId (anonymous visitor) or userId (signed-in customer), the same on the click and on the purchase.

How LIKYLY ties the purchase to the click

Click · visitor A · product X · rec_123Purchase · visitor A · product Xtied to rec_123

You don’t have to keep the recommendation: LIKYLY finds this visitor’s last click on this product (30 days). If your code already has the recommendationId, send it: it comes first.

  1. 2. Add to cart · optional

    JavaScript, in your pages
    // On add to cart (optional): the same visitor as on the click.
    likyly.events.addToCart({
      itemId: product.id,
      sessionId: new LikylySession().getAnonymousId(),
      quantity: 1,
      properties: { price: product.price, currency: "EUR" },
    });
    Laravel
    // On add to cart (optional).
    Likyly::track('add_to_cart', $product, ['quantity' => $quantity]);
  2. 3. Order confirmed · one purchase per product

    An order of 3 products is 3 purchase events, each with its price, and the same visitor as on the click. Most reliable: from your server, with the secret key, once the payment is confirmed.

    JavaScript / TypeScript
    import { Likyly, LikylySession } from "@likyly/sdk";
    
    // On the order confirmation page (public key).
    const likyly = new Likyly({ apiKey: "pk_…" });
    const sessionId = new LikylySession().getAnonymousId(); // the same visitor as on the click
    
    for (const line of order.lines) {
      await likyly.events.purchase({
        itemId: line.productId,                // the product's id in your LIKYLY catalog
        sessionId,
        userId: order.customerId,              // and the customer's id when signed in
        quantity: line.quantity,
        eventId: `purchase_${order.id}_${line.productId}`, // if replayed, the purchase counts once
        properties: { price: line.unitPrice, currency: order.currency, order_id: order.id },
      });
    }
    Python
    import os
    from likyly import Likyly
    
    # On your server (secret key), once payment is confirmed.
    likyly = Likyly(api_key=os.environ["LIKYLY_SECRET_KEY"])
    
    for line in order.lines:
        likyly.events.purchase(
            item_id=line.product_id,
            user_id=order.customer_id,            # the signed-in customer (the same userId as on their clicks)
            session_id=order.likyly_session_id,   # a guest: the anonymous id kept on the order at checkout
            quantity=line.quantity,
            event_id=f"purchase_{order.id}_{line.product_id}",
            properties={"price": float(line.unit_price), "currency": order.currency, "order_id": order.id},
        )
    PHP
    use Likyly\LikylyClient;
    
    // On your server (secret key), once payment is confirmed.
    $likyly = new LikylyClient(apiKey: getenv('LIKYLY_SECRET_KEY'));
    
    foreach ($order->lines as $line) {
        $likyly->events()->purchase(
            itemId: $line->productId,
            userId: $order->customerId,            // the signed-in customer (the same userId as on their clicks)
            sessionId: $order->likylySessionId,    // a guest: the anonymous id kept on the order at checkout
            quantity: $line->quantity,
            properties: ['price' => (float) $line->unitPrice, 'currency' => $order->currency, 'order_id' => $order->id],
            eventId: "purchase_{$order->id}_{$line->productId}",
        );
    }
    REST API
    curl -X POST https://api.likyly.com/events/purchase \
      -H "X-API-Key: $LIKYLY_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "item_id": "SKU-42",
        "session_id": "the-visitor-anonymous-id",
        "user_id": "customer_123",
        "quantity": 1,
        "event_id": "purchase_1001_SKU-42",
        "properties": { "price": 49.9, "currency": "EUR", "order_id": "1001" }
      }'
    Laravel
    // When the order is confirmed: one purchase per line. The visitor (cookie and signed-in customer) is added by the package.
    foreach ($order->lines as $line) {
        Likyly::purchase($line->product, $order->id, $line->quantity, (float) $line->unit_price, 'EUR');
    }

Payment with Stripe, PayPal…

Nothing to install at Stripe or PayPal. Payment happens on their side, then they notify your server that the payment went through (the “payment succeeded” notification your site already receives to confirm the order). That is when your server sends the purchase, rather than from the return page, which the customer may close before it loads. For a guest, keep their anonymous id on the order at checkout: the server sends it with the purchase.

Checking

  • Console → Performance: attributed purchases, revenue, conversion (the breakdown per placement and per product on Pro). A message shows up there if something is missing: clicks with no purchase received, purchases without their recommendation, or a price sent as text.
  • Terminal: npx @likyly/wizard impact, or /likyly-impact in Claude Code.

Send purchases, in the console →