Skip to main content
The Gravity Pixel is a script that runs on your website. It records page views and the attribution context of each visit, for example the Gravity ad click that sent the visitor to you. The Pixel does not send conversions alone. Pair it with server-side conversions (CAPI) or a supported integration. Then Gravity can connect confirmed purchases, signups, and demo requests to your ads. With both parts in place, your dashboard shows the conversion rate and ROAS for each campaign and ad. To set up the Pixel and CAPI with your coding agent, use the Tracking CLI. To install the Pixel by hand, follow the steps on this page.

Before you start

  • Your Pixel ID. Find it in Events Manager. The Pixel ID is a UUID. It is not your account ID or your API key.
  • Access to the shared layout or header template of your website.
  • If your website is a Shopify store, connect the Shopify app instead. It installs a Pixel on your storefront.

Install the pixel

  1. Copy this snippet. Events Manager also shows a copy of it with your Pixel ID.
  2. Replace YOUR_PIXEL_ID with your Pixel ID.
  3. Paste the snippet into the <head> of the root layout or header template of your website. The Pixel must load on every page where visitors land or convert.
  4. Install the snippet on each subdomain where visitors land or convert, including your login, signup, onboarding, and checkout entry points. A subdomain does not get the Pixel from the main domain.
  5. Deploy your website.

Use one Pixel for advertiser and publisher accounts

Do this step only if your company is a Gravity advertiser and also a Gravity publisher (AI platform) on the same website. Each account has a different Pixel ID. Do not install two Pixel snippets on the same page. Install one snippet, and add the publisher Pixel ID as the publisherId option:
  • YOUR_ADVERTISER_PIXEL_ID is the Pixel ID from Events Manager in your advertiser account.
  • YOUR_PUBLISHER_PIXEL_ID is the pixel ID from Settings > Tracking in your publisher account.
Gravity records each event one time and credits it to both accounts. Both accounts show the Pixel as live. You can also set the option in window.GRAVITY_PIXEL_CONFIG with publisherId: "YOUR_PUBLISHER_PIXEL_ID". For server-side conversions, use the API key of your advertiser account. You do not need to change anything else. getCAPIData() reads the data from the single Pixel.

Verify the pixel

  1. Open a page of your website in a browser.
  2. Open the developer tools and select the Network tab.
  3. Find a request to api.trygravity.com/track/gr-events. Make sure that the response is successful.
  4. In Events Manager, find the Browser pixel row. It shows the most recent event that Gravity received.
The script loads from code.trygravity.com and sends events to api.trygravity.com. If you use a first-party proxy, the requests go to your own domain. A successful Pixel request does not verify your server-side conversions. Verify them separately in Events Manager.

Track conversions

The Pixel records page views and attribution context. To record a conversion (a purchase or a signup, for example), do these steps:
  1. In the browser, read the attribution data with window.gravityPixel.getCAPIData().
  2. Send that data to your backend with the business request, for example the order.
  3. After your backend confirms the action, send the conversion to Gravity with CAPI.
For the full procedure, see Server-side conversions. If you can record the conversion only in the browser, use the browser conversion tag. Connect the Pixel and your backend sender to your current consent rules:
  • Where the law requires consent, load the Pixel only after the visitor gives consent.
  • If the visitor withdraws consent, stop all future sends from the Pixel and your backend.
The Pixel does not send events when the browser sends a Global Privacy Control (GPC) signal.

Optional: Improve attribution with a first-party proxy

A first-party proxy sends Pixel requests through your own domain. It can help when a browser or extension blocks requests to third-party domains. By default, the script loads from code.trygravity.com and sends events, sessions, and configuration requests to api.trygravity.com. Old script URLs on the .ai domain continue to work.

Add a forwarding rule

Select your platform. Each rule forwards /gr/ on your domain to https://api.trygravity.com/proxy/.
Add this to your next.config.js (or next.config.ts):
Deploy your project. Vercel applies the rewrite at the edge.
Make a Worker that receives /gr/ requests:
In the Cloudflare dashboard, attach the Worker to a route on your domain.
Add this to your server block:
Turn on mod_proxy and mod_proxy_http. Then add:
This example uses the http-proxy-middleware package:
You can use a different path in place of /gr/. Use the same path in the Pixel configuration below.

Configure the pixel

Add this script before the Pixel snippet:
Replace /gr/ with the path of your forwarding rule.

Verify the proxy

  1. Open a page of your website in a browser.
  2. Open the developer tools and select the Network tab.
  3. Find requests to your domain at /gr/init, /gr/events, and /gr/session. Make sure that the responses are successful.
  4. In Events Manager, find a recent event in the Browser pixel row.

Troubleshoot

Next steps

Conversions API

Send confirmed conversions from your backend.

App installs

Track iOS and Android installs as conversions.