Skip to main content

Why you need this

Without the pixel, Gravity can measure impressions and clicks — but not what happens after the user lands on your site. Install the pixel and we can attribute purchases, signups, and demo requests back to the specific ad that drove them. This unlocks:
  • Per-campaign conversion rate and ROAS in your dashboard
  • Conversion reporting tied back to specific campaigns and ads
  • Retargeting audience segmentation (upcoming feature)

Install the pixel

Add this snippet to the <head> of your website. It must be on every page and every subdomain where visitors might land or convert.
<script>
  !function(w,d,t,u,n,a,m){w['GravityPixelObject']=n;w[n]=w[n]||function(){
  (w[n].q=w[n].q||[]).push(arguments)},w[n].l=1*new Date();a=d.createElement(t),
  m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
  }(window,document,'script','https://code.trygravity.ai/gr-pix.js','gravity');
  gravity('init', 'YOUR_ADVERTISER_ID');
</script>
YOUR_ADVERTISER_ID lives in your dashboard under Settings → Organization. It’s a UUID.
Add the pixel to your site’s root layout or header template — not individual pages. This ensures it loads everywhere automatically, including subdomains and new pages you add later.

Verify it’s firing

  1. Load any page on your site with the pixel installed.
  2. Open your browser DevTools → Network tab and look for a request to api.trygravity.ai/track/gr-events.
  3. A 200 response means the pixel is firing correctly. Events typically appear in your dashboard within ~10 minutes.

Tracking conversions

The pixel captures page views and attribution context. Conversions (purchases, signups, etc.) are tracked separately — see the CAPI guide for setup.

Optional — Improve attribution with a first-party proxy

By default, the Gravity pixel sends tracking requests to api.trygravity.ai. Some browsers (especially Safari) block or limit these third-party requests, which can reduce attribution accuracy. The fix is simple: add a forwarding rule to your web server so pixel requests go through your own domain instead. No custom code — just a one-line config change for your platform.

Add a forwarding rule

Pick your platform:
Add to your next.config.js (or next.config.ts):
module.exports = {
  async rewrites() {
    return [
      {
        source: "/gr/:path*",
        destination: "https://api.trygravity.ai/proxy/:path*",
      },
    ];
  },
};
Deploy as usual — Vercel handles everything at the edge.
Create a Worker that intercepts /gr/ requests:
export default {
  async fetch(request) {
    const url = new URL(request.url);
    if (url.pathname.startsWith("/gr/")) {
      const target = "https://api.trygravity.ai/proxy/"
        + url.pathname.slice(4) + url.search;
      const headers = new Headers(request.headers);
      headers.set("Host", "api.trygravity.ai");
      headers.set("X-Forwarded-For",
        request.headers.get("CF-Connecting-IP"));
      return fetch(target, {
        method: request.method,
        headers,
        body: request.body,
      });
    }
    return fetch(request);
  },
};
Attach the Worker to your domain’s route via the Cloudflare dashboard.
Add to your server block:
location /gr/ {
    proxy_pass https://api.trygravity.ai/proxy/;
    proxy_set_header Host api.trygravity.ai;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_ssl_server_name on;
}
handle_path /gr/* {
    rewrite * /proxy{uri}
    reverse_proxy https://api.trygravity.ai {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-For {remote_host}
    }
}
Enable mod_proxy and mod_proxy_http, then add:
ProxyPass        "/gr/" "https://api.trygravity.ai/proxy/"
ProxyPassReverse "/gr/" "https://api.trygravity.ai/proxy/"
RequestHeader set Host "api.trygravity.ai"
RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"
Using http-proxy-middleware:
const { createProxyMiddleware } = require("http-proxy-middleware");

app.use(
  "/gr",
  createProxyMiddleware({
    target: "https://api.trygravity.ai",
    changeOrigin: true,
    pathRewrite: { "^/gr": "/proxy" },
  })
);
You can use any path you like instead of /gr/.

Configure the pixel

Add the proxy endpoint to your pixel install snippet, before the main pixel script tag:
<script>
  window.GRAVITY_PIXEL_CONFIG = {
    proxyEndpoint: "/gr/"
  };
</script>
Replace /gr/ with whatever path you chose in your forwarding rule.

Verify it’s working

  1. Load a page on your site with the pixel installed
  2. Open DevTools → Network tab
  3. Look for requests going to your domain at /gr/init — not to api.trygravity.ai
If you see requests hitting your own domain, you’re all set. Don’t fire the pixel or send conversions before the user accepts your cookie/consent banner (where one applies in your jurisdiction). Standard integration patterns — conditional script load behind a consent manager — work as expected.

Next

Conversions API

Full CAPI setup guide with examples.

App installs

Track iOS / Android installs as conversions.