Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Set up the server container

Add the variables to your Google Tag Manager server container and check, in preview, that they carry real cost prices.

Two routes. The first works with either cost source and does the maths for you; the second is the older setup, still supported, feed only.

1

Create a lookup token

In your AdPage dashboard, go to Webhook Matching → Settings → Send Profit on Ad Spend and click Create token.

The Lookup token on the Profit on Ad Spend card

Each container has its own token and it unlocks that container's cost prices, so it belongs in your server container only. Never in a web container, never on your site.

2

Import the template

Download adpage-profit-on-adspend.tpl — the same download sits next to the token in the dashboard.

In your server container, go to Templates, click New under Variable Templates, then the three dots in the top right → Import. Import the file and save.

3

Create the variable

Create a new variable with the imported template as its configuration. Two fields to fill in:

  • Container ID — your AdPage container UUID, the same one as on the Event Notifier tag. Not the GTM container id.

  • Lookup token — the token from step 1.

The AdPage Profit on Ad Spend variable configuration

Everything else has a working default. Return decides which field the variable gives back; Where the number comes from can stay on Auto.

4

Add it to your GA4 purchase tag

Add the variable as an event parameter on the tag you want the profit on. Use the parameter name that matches what you selected under Return — profit_value for net profit, gross_profit for gross.

Existing setup: total purchase price and profit margin

Still supported and unchanged. Requires an XML feed.

1

Add the total purchase price variable

  1. Download this variable template: template.

  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.

2

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.

  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.

3

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

Validate in preview

Open your server container and turn on preview mode.

If you measure purchases through a webhook, replay one from the Webhook Logs. If you measure them from your web container through a GA4 event tag, complete a test purchase (this does not apply to Shopify).

For the AdPage variable, set Return to all for the duration of the test. You then see the whole object instead of a single number:

The variable in preview, returning the full object

Look at coverage.matched before you look at the amount. It says how many order lines had a real cost price. If it is 0 while an amount still comes out, you are looking at the fallback margin rather than at your cost prices — an amount that looks right and is not. Set Return back afterwards.

For the existing setup, check that the purchase_price parameter is present on the Event Data tab and in the GA4 tag parameters.

Nothing there? Work through Troubleshooting.

Was this helpful?