alby Purchase Pixel

Track and analyze customer purchases with alby's purchase pixel for e-commerce websites.

Prerequisite

Before proceeding, you must have a Brand ID (brand_id). This unique identifier connects your website to alby. Reach out to your CSM or onboarding manager for this.

Add the alby Purchase Pixel to your website

Add the following JavaScript to your purchase confirmation page:

<script>
  (function () {
    // Replace placeholders with real order data
    var PIXEL = {
      brand_id: "PLACE_BRAND_ID_HERE",
      order_id: "PLACE_ORDER_ID_HERE",
      order_total: "PLACE_ORDER_TOTAL_HERE", // e.g. "123.45"
      currency: "USD",
      variant_ids: ["VARIANT_ID_1", "VARIANT_ID_2"],

      // Optional A/B test metadata
      test_id: "PLACE_TEST_ID_HERE",
      test_version: "alby", // alby | control | excluded
      test_description: "PLACE_TEST_DESCRIPTION_HERE"
    };

    var cookies = document.cookie.split(";");
    var sessionCookie = cookies.find(function (c) {
      return c.trim().startsWith("_alby_session=");
    });
    var userCookie = cookies.find(function (c) {
      return c.trim().startsWith("_alby_user=");
    });

    var data = {
      order_id: String(PIXEL.order_id),
      total: {
        amount: String(PIXEL.order_total),
        currencyCode: String(PIXEL.currency || "USD")
      },
      items: (PIXEL.variant_ids || []).map(function (variantId) {
        return {
          variant_id: String(variantId),
          quantity: 1,
          cost: {
            amount: String(PIXEL.order_total),
            currencyCode: String(PIXEL.currency || "USD")
          }
        };
      })
    };

    var params = new URLSearchParams();
    params.set("brand_id", String(PIXEL.brand_id));
    params.set("data", JSON.stringify(data));

    if (PIXEL.test_id && PIXEL.test_version && PIXEL.test_description) {
      params.set(
        "ab_testdata",
        JSON.stringify({
          test_id: String(PIXEL.test_id),
          test_version: String(PIXEL.test_version),
          test_description: String(PIXEL.test_description)
        })
      );
    }

    if (sessionCookie) params.set("session", sessionCookie.split("=")[1] || "");
    if (userCookie) params.set("user_id", userCookie.split("=")[1] || "");

    // Optional timestamp (unix seconds)
    params.set("event_timestamp", String(Math.floor(Date.now() / 1000)));

    fetch("https://tr.alby.com/p?" + params.toString(), {
      method: "GET",
      keepalive: true
    }).catch(function () {});
  })();
</script>

Query parameters

NameRequired?Description
brand_idYesUnique identifier that connects your website to alby.
dataYesJSON-encoded purchase payload.
sessionNoSession identifier (typically from _alby_session cookie).
user_idNoUser identifier (typically from _alby_user cookie, UUID format).
ab_testdataNoJSON-encoded A/B test metadata.
event_timestampNoEvent timestamp in unix seconds (or RFC3339).

data fields

NameRequired?Description
order_idYesUnique identifier for the purchase.
total.amountYesTotal purchase amount as numeric string (no currency symbol).
total.currencyCodeNoCurrency code (e.g. USD, EUR, GBP). Defaults to USD if omitted.
items[]RecommendedLine items for stronger conversion attribution/reporting.
items[].variant_idRecommendedVariant/child product ID shared with alby via product catalog integration.
items[].quantityRecommendedQuantity purchased for the variant.
items[].cost.amountRecommendedLine item amount as numeric string.
items[].cost.currencyCodeNoLine item currency code. Defaults to USD if omitted.

ab_testdata fields

NameRequired?Description
test_idNoUnique identifier for the A/B test.
test_versionNoAllowed values: alby, control, excluded.
test_descriptionNoOptional test description.

Save and Publish

Save the changes and publish your website.

If you encounter issues, contact [email protected].