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
| Name | Required? | Description |
|---|---|---|
brand_id | Yes | Unique identifier that connects your website to alby. |
data | Yes | JSON-encoded purchase payload. |
session | No | Session identifier (typically from _alby_session cookie). |
user_id | No | User identifier (typically from _alby_user cookie, UUID format). |
ab_testdata | No | JSON-encoded A/B test metadata. |
event_timestamp | No | Event timestamp in unix seconds (or RFC3339). |
data fields
data fields| Name | Required? | Description |
|---|---|---|
order_id | Yes | Unique identifier for the purchase. |
total.amount | Yes | Total purchase amount as numeric string (no currency symbol). |
total.currencyCode | No | Currency code (e.g. USD, EUR, GBP). Defaults to USD if omitted. |
items[] | Recommended | Line items for stronger conversion attribution/reporting. |
items[].variant_id | Recommended | Variant/child product ID shared with alby via product catalog integration. |
items[].quantity | Recommended | Quantity purchased for the variant. |
items[].cost.amount | Recommended | Line item amount as numeric string. |
items[].cost.currencyCode | No | Line item currency code. Defaults to USD if omitted. |
ab_testdata fields
ab_testdata fields| Name | Required? | Description |
|---|---|---|
test_id | No | Unique identifier for the A/B test. |
test_version | No | Allowed values: alby, control, excluded. |
test_description | No | Optional test description. |
Save and Publish
Save the changes and publish your website.
If you encounter issues, contact [email protected].
Updated 8 days ago