For brands

Add litchy to your Shopify checkout.

Shoppers leave litchy with a tagged link. This pixel tells us if they bought — order number and amount only. No names, emails, or addresses.

  1. In Shopify: Settings → Customer events
  2. Add custom pixel, name it litchy
  3. When it asks which website this pixel connects to, enter litchy.shop
  4. Paste the code below, then Save and Connect
const ENDPOINT = "https://litchy.shop/api/shopify/conversion";
const LID_KEY = "litchy_lid";

function lidFrom(href) {
  try {
    const url = new URL(href);
    const lid = url.searchParams.get("lid");
    if (!lid) return "";
    const source = (url.searchParams.get("utm_source") || "").toLowerCase();
    if (source && source !== "litchy") return "";
    return lid;
  } catch (error) {
    return "";
  }
}

async function remember(lid) {
  if (!lid) return;
  try {
    await browser.localStorage.setItem(LID_KEY, lid);
  } catch (error) {}
  try {
    await browser.cookie.set(LID_KEY, lid);
  } catch (error) {}
}

async function recalled() {
  try {
    const fromLs = await browser.localStorage.getItem(LID_KEY);
    if (fromLs) return fromLs;
  } catch (error) {}
  try {
    const fromCk = await browser.cookie.get(LID_KEY);
    if (fromCk) return fromCk;
  } catch (error) {}
  return "";
}

analytics.subscribe("page_viewed", (event) => {
  remember(lidFrom(event.context.document.location.href));
});

analytics.subscribe("product_viewed", (event) => {
  remember(lidFrom(event.context.document.location.href));
});

analytics.subscribe("checkout_completed", async (event) => {
  const lid = await recalled();
  if (!lid) return;
  const checkout = event.data && event.data.checkout ? event.data.checkout : {};
  const order = checkout.order || {};
  const total = checkout.totalPrice || {};
  const loc = event.context && event.context.document ? event.context.document.location : {};
  fetch(ENDPOINT, {
    method: "POST",
    headers: { "content-type": "application/json" },
    keepalive: true,
    body: JSON.stringify({
      lid: lid,
      orderId: order.id || checkout.token || "",
      checkoutToken: checkout.token || "",
      total: total.amount,
      currency: total.currencyCode || checkout.currencyCode || "INR",
      shop: loc.hostname || "",
    }),
  });
});

After it is connected, a test order from a litchy product link should show on our ops page. Questions: hello@litchy.shop

Bring your store to litchy