---
title: "Lapis Pixel"
description: "Install the Lapis pixel with one script tag to attribute visits and conversions to the campaigns you run through Lapis."
sidebar:
  order: 2
search:
  tags:
    - install lapis pixel
    - chatgpt ads pixel
    - tracking pixel
    - window.lapis
    - oppref
    - pixel consent
    - lapis_sid cookie
    - track conversions
---

> Start here. This page is part of the Lapis documentation. Before you answer, load the full documentation index at https://docs.trylapis.com/llms.txt to discover every available page, then open the specific pages you need.
>
> The full text of every page is at https://docs.trylapis.com/llms-full.txt, and agents can connect to the Lapis docs MCP server at https://docs.trylapis.com/mcp.
>
> Most relevant pages for this topic:
> - Conversion API: https://docs.trylapis.com/conversion-api
> - Conversion tracking overview: https://docs.trylapis.com/conversion-tracking
> - Platform setup: https://docs.trylapis.com/platforms/overview
> - Choosing your events: https://docs.trylapis.com/events/overview



The Lapis Pixel is the browser half of Lapis conversion tracking. It records visits to your site, attributes the ones that come from campaigns you run through Lapis, and lets you track conversions that happen in the browser. The [Conversion API](/conversion-api) is the server half, and it handles verified conversions that only your backend can see.

This page covers the four things you need to do: install the pixel, set up your ad URLs, track conversions, and read the click ID for server-side attribution.

## 1. Install the pixel

Add this script tag to every page of your website, just before the closing `</body>` tag:

```html
<script
  src="https://cdn.trylapis.com/pixel/v1/lapis-pixel.js"
  data-key="YOUR_API_KEY"
></script>
```

Replace `YOUR_API_KEY` with the pixel API key from Lapis. It looks like `pk_79de89010be148c5a5a631ae`.

Once the pixel loads, it defines a global `lapis()` function on `window` for every visitor. The script URL stays the same across pixel updates (`/v1/` is the URL path, not the pixel version), so you never need to change your tag.

If your code can call `lapis()` before the pixel has loaded, add this one-liner above the pixel tag. Calls made early are queued and sent once the pixel loads:

```html
<script>window.lapis=window.lapis||function(){(lapis.q=lapis.q||[]).push(arguments)};</script>
```

> Tip: The pixel is lightweight (about 4KB gzipped), loads asynchronously, and never blocks your page from rendering.

For platform-specific install steps (Shopify theme code, Framer custom code, WordPress, GTM, and more), see [Platform setup](/platforms/overview).

If you would rather serve the script from your own site and decide when it updates, see [Self-hosting the pixel](/self-hosting).

### Installing via Google Tag Manager

If you use GTM, you can add the pixel there instead of editing your site code directly:

1. Go to **Tags → New → Custom HTML**
2. Paste the code below
3. Set the trigger to **All Pages**
4. Click **Publish**

```html
<script src="https://cdn.trylapis.com/pixel/v1/lapis-pixel.js" data-key="YOUR_API_KEY"></script>
```

## 2. Set up your ChatGPT ad URLs

When you create ads in the ChatGPT Ads platform, add parameters to the destination URL so Lapis can attribute conversions back to the right campaign, ad group, and ad.

### URL format

```text
https://yoursite.com/?utm_source=chatgpt&lapis_campaign=CAMPAIGN_NAME&lapis_adgroup=AD_GROUP_NAME&lapis_ad=AD_ID
```

### Parameters

| Parameter | Required | Description | Example |
| --- | --- | --- | --- |
| `utm_source` | Yes* | `chatgpt` or `openai` marks the visit as coming from your campaign | `chatgpt` |
| `lapis_campaign` | Recommended | Your campaign name | `spring_launch` |
| `lapis_adgroup` | Recommended | Your ad group name | `us_designers` |
| `lapis_ad` | Recommended | The specific ad identifier | `ad_001` |
| `oppref` | Automatic | OpenAI's click ID, added to the URL by ChatGPT Ads. Don't remove it. | — |

\* Any one of `utm_source=chatgpt` (or `openai`), `lapis_campaign`, or `oppref` is enough for Lapis to attribute the visit. The three `lapis_` parameters are optional, but without them your conversions all roll up under one unnamed campaign, so add them if you want per-ad reporting.

### Example URLs

Minimum required:

```text
https://yoursite.com/?utm_source=chatgpt
```

Full attribution (recommended):

```text
https://yoursite.com/?utm_source=chatgpt&lapis_campaign=spring_launch&lapis_adgroup=us_designers&lapis_ad=ad_001
```

### UTM fallbacks

If you already tag your URLs with standard UTM parameters, the pixel reads those automatically when the `lapis_` versions are missing:

| Lapis parameter | UTM fallback |
| --- | --- |
| `lapis_campaign` | `utm_campaign` |
| `lapis_adgroup` | `utm_content` |
| `lapis_ad` | `utm_term` |

## 3. Track conversions

The pixel records these automatically, with no code from you:

- Page views, including client-side navigation in single-page apps
- Engagement: time on page and scroll depth
- Clicks on buttons and links
- Form submissions, plus a hashed email when a visitor submits a form (see [Privacy and consent](#privacy-and-consent))

For conversions such as purchases and signups, call `lapis()` at the moment the event happens.

### Purchase

```js
lapis("purchase", {
  value: 149.99,
  currency: "USD",
  order_id: "ORD-123"
});
```

### Signup

```js
lapis("signup");
```

### Lead

```js
lapis("lead", { value: 50 });
```

### Add to cart

```js
lapis("add_to_cart", { value: 29.99 });
```

### Custom events

You can track any event name with any custom data:

```js
lapis("subscribe", { plan: "pro", interval: "yearly", value: 199 });
lapis("form_submit", { form_name: "contact", source: "footer" });
lapis("download", { file: "whitepaper.pdf" });
```

### Conversion data fields

| Field | Type | Description |
| --- | --- | --- |
| `value` | Number | Monetary value (for example, `149.99`) |
| `currency` | String | ISO currency code, defaults to `"USD"` |
| `order_id` | String | Unique order identifier, used for deduplication |

You can include any additional fields. Lapis stores all of them and makes them available in your dashboard.

> Note: Browser events are best-effort by nature. Ad blockers and closed tabs mean some never arrive. Send your verified conversions (orders, signups) server-side through the [Conversion API](/conversion-api) instead. It deduplicates against browser events by event ID, so you get reliable numbers without double-counting.

## 4. How it works

1. A visitor clicks your ChatGPT ad and lands on your site with the tracking parameters in the URL.
2. The pixel sees the campaign parameters and opens a session attributed to that campaign. Refreshing the page or coming back from the same ad keeps the same session; a click on a different ad starts a new one.
3. The session lasts 30 days. It's stored in the `lapis_sid` cookie, with a localStorage copy as a fallback. A separate browser ID (`lapis_bid`) lasts a year. Safari keeps cookies and storage written by any script for at most about 7 days after the visitor's last visit, so a Safari visitor who stays away longer starts fresh.
4. Page views and activity are recorded automatically.
5. When you call `lapis()`, the conversion is recorded and attributed to the original campaign.
6. Everything shows up in your Lapis dashboard.

> Note: The pixel records every visit, and attributes the ones that came from a campaign you run through Lapis.

### The `lapis_sid` cookie and click ID

The cookie value is JSON that contains a `sid` field. That `sid` is the **Lapis click ID**. To attribute a conversion server-side, read the click ID out of the cookie, carry it through your signup or checkout flow, and include it as `lapis_click_id` in your [Conversion API](/conversion-api) events:

```js
function getLapisClickId() {
  const cookie = document.cookie
    .split("; ")
    .find((entry) => entry.startsWith("lapis_sid="));
  if (!cookie) return null;
  try {
    const session = JSON.parse(
      decodeURIComponent(cookie.split("=").slice(1).join("="))
    );
    return session.sid || null;
  } catch {
    return null;
  }
}
```

Every visitor gets a `lapis_sid` cookie, and Lapis knows on its side which sessions came from your campaigns, so you can pass the click ID along for every signup or order. If the cookie is missing, the pixel didn't load (for example, it was blocked) or the visitor is in a consent region and hasn't given consent yet. Send the conversion without a click ID, and never invent one.

## 5. Integration examples

### Shopify

Add the pixel script in **Settings → Custom Code → Before `</body>` tag**, then track purchases on the order confirmation page:

```html
<script>
  if (window.lapis && Shopify.checkout) {
    lapis("purchase", {
      value: Shopify.checkout.total_price / 100,
      currency: Shopify.checkout.currency,
      order_id: Shopify.checkout.order_id
    });
  }
</script>
```

For the full Shopify integration, including reliable server-side order tracking, see the [Shopify platform guide](/platforms/shopify).

### React / Next.js

```jsx
function CheckoutSuccess({ order }) {
  useEffect(() => {
    if (window.lapis) {
      lapis("purchase", {
        value: order.total,
        currency: order.currency,
        order_id: order.id
      });
    }
  }, []);

  return <div>Thank you for your purchase!</div>;
}
```

### Signup form

```html
<form id="signup-form">
  <input type="email" name="email" />
  <button type="submit">Sign Up</button>
</form>

<script>
  document.getElementById("signup-form")
    .addEventListener("submit", function () {
      if (window.lapis) {
        lapis("signup");
      }
    });
</script>
```

## Content Security Policy

If your site enforces CSP, allow `https://cdn.trylapis.com` in `script-src`, and both `https://api.trylapis.com` and `https://lapiscore-production-d467.up.railway.app` in `connect-src`. The pixel falls back to the second host once if the first can't be reached.

A [self-hosted](/self-hosting) pixel needs less: the script comes from your own site, and it only calls `https://api.trylapis.com`.

## Privacy and consent

### EU, EEA, UK, and Switzerland

Visitors from these regions get a small consent gate instead of the pixel. Until your cookie banner grants marketing consent, Lapis sets no cookies and sends nothing. These consent tools are detected automatically:

- IAB TCF v2 (purposes 1 and 7)
- Shopify Customer Privacy API
- OneTrust (targeting group `C0004`)
- Cookiebot (marketing)
- Google Consent Mode (`ad_storage`)

If you use a different consent tool, tell Lapis directly:

```js
lapis("consent", "granted"); // or "denied", which also deletes Lapis cookies and storage
```

If you already load the pixel only after consent, add `data-consent="granted"` to the script tag.

The consent gate is applied by the Lapis CDN from the visitor's location. If you [host the pixel yourself](/self-hosting#4-handle-consent-in-the-eu-and-uk), applying it is up to you.

### What the pixel never collects

The pixel never collects the values people type into form fields, password, card, or SSN-type fields, or text that looks like a card or SSN number. Emails are hashed (SHA-256) in the browser before they're sent.

### Opt-outs

| Attribute | Effect |
| --- | --- |
| `data-lapis-no-track` on any element | Nothing inside it is recorded |
| `data-lapis-no-identity` on a `<form>` | No hashed email is taken from that form |

To record page views and ad clicks only, with no button text, form activity or emails, see [Minimal data mode](/minimal-data-mode).

## FAQ

### Does the pixel slow down my site?

No. The script is about 4KB gzipped and loads asynchronously, so it never blocks page rendering.

### What if a visitor comes back days later?

The session cookie lasts 30 days. If a visitor from a ChatGPT ad returns within that window, their page views and conversions still attribute to the original campaign.

### Does it track all my visitors?

The pixel records every visit, and attributes the ones that came from a campaign you run through Lapis.

### Is `window.lapis` always defined?

Yes, for every visitor, once the pixel has loaded. Existing `if (window.lapis)` checks keep working. If your code can run before the pixel loads, use the queue one-liner from [Install the pixel](#1-install-the-pixel).

### Can I use multiple API keys on one site?

No. Use one API key per site. Each key maps to a single Lapis account.
