> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lemrock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Shopify pixel: previous version

> The Lemrock Shopify code used before October 2026, kept for stores that still run it.

> [!WARNING]
>
> This version is replaced. To install the pixel or update your store, follow [Conversion tracking on Shopify](https://docs.lemrock.com/en/conversion-tracking/shopify.md). This page only helps you recognise and read the previous version.

Until October 2026, the Shopify install was the snippet below, pasted in full in a custom pixel. It starts with `const PIXEL_ID` and sends `pixel_version: "shopify-1.0.0"`.

```js theme={null}
const PIXEL_ID = "lr_px_...";
const VALIDATE_ONLY = false; // true while testing: events are checked, not recorded

const ENDPOINT = "https://api.lemrock.com/v1/browser/events";
const COOKIE = "lemrock_click";
const LRCLID = /^lr_clk_[A-Za-z0-9_-]{22}$/;

const cents = (money) => {
  if (!money || money.amount == null) return undefined;
  return Math.round(Number(money.amount) * 100);
};

const item = (variant, quantity) => ({
  id: String(variant?.product?.id ?? ""),
  name: variant?.product?.title,
  quantity,
  amount: cents(variant?.price),
  currency: variant?.price?.currencyCode,
});

const checkoutData = (checkout) => ({
  amount: cents(checkout.subtotalPrice),
  currency: checkout.currencyCode,
  contents: checkout.lineItems.map((line) => item(line.variant, line.quantity)),
});

async function sha256(text) {
  const bytes = new TextEncoder().encode(text);
  const hash = await crypto.subtle.digest("SHA-256", bytes);
  return Array.from(new Uint8Array(hash), (b) =>
    b.toString(16).padStart(2, "0"),
  ).join("");
}

async function send(eventType, eventId, event, data, user) {
  const lrclid = await browser.cookie.get(COOKIE);
  if (!lrclid && !user) return;

  fetch(ENDPOINT, {
    method: "POST",
    headers: { "content-type": "application/json" },
    keepalive: true,
    body: JSON.stringify({
      event_type: eventType,
      event_id: String(eventId),
      event_time_ms: Date.parse(event.timestamp) || Date.now(),
      lrclid: lrclid || undefined,
      user,
      source_url: event.context.document.location.href,
      pixel_id: PIXEL_ID,
      pixel_version: "shopify-1.0.0",
      data: { type: "contents", ...data },
      validate_only: VALIDATE_ONLY,
    }),
  });
}

analytics.subscribe("page_viewed", async (event) => {
  const url = new URL(event.context.document.location.href);
  const token = (url.searchParams.get("lrclid") || "").trim();
  if (LRCLID.test(token)) {
    await browser.cookie.set(
      `${COOKIE}=${token}; path=/; max-age=${90 * 86400}; SameSite=Lax; Secure`,
    );
  }
});

analytics.subscribe("product_viewed", (event) => {
  const variant = event.data.productVariant;
  send("contents_viewed", event.id, event, { contents: [item(variant, 1)] });
});

analytics.subscribe("product_added_to_cart", (event) => {
  const line = event.data.cartLine;
  send("items_added", event.id, event, {
    amount: cents(line.cost.totalAmount),
    currency: line.cost.totalAmount.currencyCode,
    contents: [item(line.merchandise, line.quantity)],
  });
});

analytics.subscribe("checkout_started", (event) => {
  send("checkout_started", event.id, event, checkoutData(event.data.checkout));
});

analytics.subscribe("checkout_completed", async (event) => {
  const checkout = event.data.checkout;
  const email = checkout.email?.trim().toLowerCase();
  const user = email ? { email_sha256: await sha256(email) } : undefined;
  send(
    "order_created",
    checkout.order?.id ?? event.id,
    event,
    checkoutData(checkout),
    user,
  );
});
```

* **Product IDs must match your catalog feed.** The snippet sends the Shopify product ID. If your feed uses variant IDs or SKUs, replace `variant?.product?.id` with `variant?.id` or `variant?.sku`.
* **The snippet sends the customer's email hashed, never in clear.** It's hashed in the browser before sending, so Lemrock never receives the address itself. Nothing to set up.

To move to the current version, see [Already using the previous version?](https://docs.lemrock.com/en/conversion-tracking/shopify.md#already-using-the-previous-version).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.