> For the complete documentation index, see [llms.txt](https://docs.adpage.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adpage.io/optimize-your-setup/profit-on-ad-spend.md).

# Profit on Ad Spend

Optimize your advertising platforms based on your profit margin instead of your revenue.

Welcome to our guide on optimizing advertising platforms using Profit on Ad Spend! In this article we explain how you can use your profit margin to make your ads more effective. This can lead to higher profitability. Let's get started!

## What is Profit on Ad Spend?

Profit on Ad Spend is an innovative way to optimize advertising platforms based on your profit margin instead of your revenue. This approach shifts the focus of your ads, which increases the likelihood that your profitability will grow.

{% hint style="warning" %}
**Important note.** This feature lets you add purchase prices from an XML feed to your purchase events. Keep in mind that we can only add the purchase price at item level when using webhooks, without webhooks we calculate it only for the entire order. The feed is matched against products once per hour, meaning product cost prices are matched to purchases every hour.
{% endhint %}

There are five key steps you need to take to successfully set up Profit on Ad Spend:

1. Generate an XML feed
2. Connect the XML feed to your AdPage Server Container
3. Test whether the purchase price arrives in your GTM server container preview
4. Make the required changes in your Google Tag Manager server container
5. Add dimensions to your GA4 property and marketing platforms

### Set up the Profit on Ad Spend feed&#x20;

{% stepper %}
{% step %}

#### Generate an XML feed

An XML feed is a file type that contains information about a webshop's products.&#x20;

The file uses the Extensible Markup Language format, which allows different systems to automatically read and process the information. With an XML feed, webshops can share their product data with platforms like Google Shopping and Facebook Ads, or with other partners. \
\
The big advantage is that this exchange happens automatically. If you change a price or product description in your webshop, that change is automatically passed on to all connected systems, so you don't have to manually update the same information everywhere.

You can generate an XML feed using tools such as Channable, a WooCommerce plugin, or another tool.
{% endstep %}

{% step %}

#### Load the XML feed into your AdPage Server Container

Open the settings in your AdPage server container on and navigate to the Profit Margin settings.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FjuqoiSTsP1DnOfMsmuSV%2Fimage.png?alt=media&amp;token=2e3100f2-9ea9-4306-8a8f-06efddbd3386" alt=""><figcaption></figcaption></figure>

* In the first field, add your XML feed URL.
* In the second field, add the name of the label within your XML feed from which the product's purchase price can be read (for example, "g:custom\_label\_2").
* In the third field, add the name of the label within your XML feed from which the product ID can be read. This product ID must match the `item_id` from the incoming request in your GA4 event requests. If you have not altered the `item_id` parameter in your GA4 event tags, you'll use the `item_id` paramter from the dataLayer. Below we explain below how to find that `item_id` in your dataLayer.

**Finding the item\_id in the dataLayer**\
**O**pen your webshop and go to a product page. Check the dataLayer by inspecting element and going over to the **Console** tab. Here you can type `window.dataLayer` to call on the dataLayer, find the view\_item event to find the `item_id` of the product you're viewing.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FLGgKUgd6Xu3YIIwr9g3d%2Fimage.png?alt=media&amp;token=e134c0de-b898-493d-ada3-ae77fdaa7c7f" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### Set up the Google Tag Manager server container

{% stepper %}
{% step %}

#### Add the total purchase price variable

1. Download this variable template: [template](https://drive.google.com/file/d/1ksyCJc4jv2W7ldNGOPinSHIfMhKPCYSE/view).
2. Open your GTM server container and go to **Templates**. Click **New** under Variable Templates.
3. Click the three dots in the top right, then click **Import**. Import the template you just downloaded and save it.
4. Create a new variable. Choose the variable template you just imported as the variable configuration and save this variable.
   {% endstep %}

{% step %}

#### Add the profit margin variable

1. Go to **Templates** and add a new Variable Template by searching the template gallery. Look for the **Number & String Operations** template and add it to your workspace.\ <br>

   <figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2Fknywtmg8vdlU9HC64qTK%2Fimage.png?alt=media&amp;token=ea3b2b22-b650-49e9-97dd-7012f07696f4" alt=""><figcaption></figcaption></figure>

2. Create a new variable with **Number & String Operations** as the variable configuration. Set the operation type to **Calculate** and the operation to **Subtract**. Parameter 1 is the eCommerce value (event data variable for `value`) and Parameter 2 is your total purchase price variable from the previous step. Save this variable as `profit_margin`.\ <br>

   <figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FbZMV2cWOpe0KvGL4Y39T%2Fimage.png?alt=media&amp;token=15f2600f-88d5-4210-879e-41a5ff5c2ad1" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

#### Add the variables to your GA4 (purchase) event tag

* `purchase_price`: value set to your total purchase price variable
* `profit_margin`: value set to your profit margin variable<br>

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FX3G9T79Mdd1gDshatnpV%2Fimage.png?alt=media&amp;token=b3f75e74-a9f0-4d3c-a3b3-975e9ed68bc1" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Validate setup in Google Tag Manager server container

Open your Google Tag Manager server container and activate **preview mode.**

If you use a webhook to measure purchases, run a webhook replay. Replay a webhook from the Webhook Logs using the Webhook Replay functionality. When you replay this webhook, a `trytagging_purchase` request will appear in preview mode. Check whether the `purchase_price` parameter is present on the **Event Data** tab.

If you measure purchases from the Google Tag Manager web container via a GA4 event tag, complete a test purchase (this doesn't apply to Shopify). After completing a test purchase, a purchase request will come in on your preview mode. Check whether the `purchase_price` parameter is present on the **Event Data** tab and in the GA4 tag parameters.

{% hint style="info" %}
Not present? Then a setting in step 1, 2, or 3 of this article was configured incorrectly. Is it present? Continue with the steps below.
{% endhint %}
{% endstep %}
{% endstepper %}

### Set up integration with Google Analytics 4

In GA4, make sure you can receive and display these extra parameters. Add the custom parameters `profit_margin` and `purchase_price` to GA4 by going to **Admin** and creating new **Custom Definitions**.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FkoV6vBN3SY5CyxRwfFD0%2Fimage.png?alt=media&amp;token=24874f6a-6f60-44ef-9a52-676614bb1c22" alt=""><figcaption></figcaption></figure>

Within the custom definitions settings, add two new **Custom Metrics** with `profit_margin` and `purchase_price` as the metric name and parameter name. Ensure you select the correct **Unit of measurement** and **Data Type** to differentiate between Cost Data and Revenue Data.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FbU7p1edlifLPPlQUuh0p%2Fimage.png?alt=media&amp;token=4e901546-0836-4ca4-a68d-98291c10a324" alt=""><figcaption></figcaption></figure>

### Setup integration with Google Ads

To add Profit on Ad Spend in Google Ads, create a new conversion tag containing the profit margin variable to replace the conversion value. Do this for a new conversion action that you'll need to create within Google Ads.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FDctBiSX7ootPCWjMKKkS%2Fimage.png?alt=media&amp;token=3ae79d44-6224-4cb1-a5f3-1d634990d183" alt=""><figcaption></figcaption></figure>

## What's next?

In short: you've generated an XML feed, connected it to your AdPage Server Container, configured your GTM server container, tested that the purchase price and profit margin arrive correctly, and added the corresponding dimensions in GA4. From here you're ready to connect Profit on Ad Spend to your ad platforms.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.adpage.io/optimize-your-setup/profit-on-ad-spend.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
