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

# Browser conversion tag

> Send conversions from a web page or Google Tag Manager with conversion.js and your advertiser ID.

The browser conversion tag sends a conversion to Gravity from a web page. Use it when you can record the conversion only in the browser, for example on an order confirmation page or with Google Tag Manager (GTM).

If your backend confirms the conversion, use [server-side conversions (CAPI)](https://docs.trygravity.com/advertisers/server-conversions.md). A Conversions or CPA campaign needs server-side proof of its conversion event. See [Conversion event check](https://docs.trygravity.com/advertisers/campaigns.md#conversion-event-check).

The tag identifies your account with your advertiser ID. The advertiser ID is public and can only record conversions. Do not use your API key in the tag. The API key is for server use only.

## Before you start

* Your advertiser ID. In **Events Manager**, open **Setup**, select **Or set up manually**, and find the **Browser conversion tag** card. The card shows the tag with your advertiser ID.
* The [Gravity Pixel](https://docs.trygravity.com/advertisers/pixel.md) on your website. The tag reads the attribution context that the Pixel stores, so Gravity can connect the conversion to the ad click.

## Add the tag to a page

1. Copy the tag from the **Browser conversion tag** card in Events Manager, or copy this tag:

   ```html theme={null}
   <script src="https://code.trygravity.com/conversion.js"
     data-advertiser-id="YOUR_ADVERTISER_ID"
     data-type="purchase"
     data-value="49.99"
     data-currency="USD"
     async></script>
   ```

2. Replace `YOUR_ADVERTISER_ID` with your advertiser ID.

3. Set `data-type` to the event. See [Event types](#event-types).

4. Set `data-value` to the conversion value, or remove `data-value` and `data-currency` if the conversion has no value.

5. Put the tag on the page that confirms the conversion, for example the order confirmation page.

The tag sends one conversion each time the page loads.

| Attribute | Required | Description |
| - | - | - |
| `data-advertiser-id` | Yes | Your advertiser ID. |
| `data-type` | No | The event type. Default: `purchase`. |
| `data-value` | No | The conversion value in USD. Default: `0`. |
| `data-currency` | No | A currency code that Gravity stores with the conversion. Gravity reports the value in USD. Default: `USD`. |
| `data-order-id` | No | Your order or transaction ID. Use the real ID. Gravity treats placeholder IDs such as `ORDER_ID` as test data and sets the value to 0. |

## Event types

Set the event type to the conversion event of your campaign.

| Event | `data-type` | Value |
| - | - | - |
| Purchase | `purchase` | Usually the order total |
| Sign up | `signup` | Usually none |
| Lead | `lead` | Optional |
| Booking | `booking` | Optional |
| Add to cart | `add_to_cart` | Optional |

For a custom conversion event, use the same event name as in your campaign, in lowercase with underscores. For example, use `demo_request` for a campaign with the custom event `Demo request`.

A signup without a value:

```html theme={null}
<script src="https://code.trygravity.com/conversion.js"
  data-advertiser-id="YOUR_ADVERTISER_ID"
  data-type="signup"
  async></script>
```

A lead with a value:

```html theme={null}
<script src="https://code.trygravity.com/conversion.js"
  data-advertiser-id="YOUR_ADVERTISER_ID"
  data-type="lead"
  data-value="25"
  data-currency="USD"
  async></script>
```

## Add the tag with Google Tag Manager

1. In GTM, create a **Custom HTML** tag.
2. Paste the tag. To send the value from your data layer, use a GTM variable, for example `data-value="{{Conversion Value}}"`.
3. Set the trigger to the page view or the event that confirms the conversion, for example a page view on `/thank-you` or a `purchase` data layer event.
4. Publish the container.

## Send a conversion from JavaScript

Use JavaScript when the conversion does not load a new page, for example when a form shows a success message.

1. Load `conversion.js` once on the page:

   ```html theme={null}
   <script src="https://code.trygravity.com/conversion.js" async></script>
   ```

2. When the action is confirmed, call `window.gravityConversion`:

   ```js theme={null}
   window.gravityConversion({
     advertiserId: 'YOUR_ADVERTISER_ID',
     type: 'lead',
     value: 25,
     currency: 'USD',
   });
   ```

   The options are `advertiserId` (required), `type`, `value`, `currency`, `orderId`, and `metadata`. They work like the attributes in the table above.

## Verify the tag

1. Open the page with the tag in a browser.
2. Open the developer tools and select the **Network** tab.
3. Find a request to `api.trygravity.com/generic/conversions`. Make sure that the response contains `"status": "ok"`.

## Update an older tag

Older versions of the tag used `data-api-key` or the `apiKey` option. These tags still work. To update an older tag:

1. Replace `data-api-key="..."` with `data-advertiser-id="YOUR_ADVERTISER_ID"`. In JavaScript, replace `apiKey` with `advertiserId`.
2. Publish the change, including a new version of each GTM container.
3. [Rotate your API key](https://docs.trygravity.com/advertisers/dashboard-api.md#authentication) in **Settings → Organization**, and update your server integrations with the new key.


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