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.
Recommended: the AdPage Profit on Ad Spend variable
Create a lookup token
In your AdPage dashboard, go to Webhook Matching → Settings → Send Profit on Ad Spend and click Create token.

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.
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.
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.

Everything else has a working default. Return decides which field the variable gives back; Where the number comes from can stay on Auto.
Existing setup: total purchase price and profit margin
Still supported and unchanged. Requires an XML feed.
Add the total purchase price variable
Download this variable template: template.
Open your GTM server container and go to Templates. Click New under Variable Templates.
Click the three dots in the top right, then click Import. Import the template you just downloaded and save it.
Create a new variable. Choose the variable template you just imported as the variable configuration and save this variable.
Add the profit margin variable
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.

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 asprofit_margin.
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:

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.
Was this helpful?


