Setting Up the ProfitMetrics Profit Variable in Server-Side GTM
The ProfitMetrics Profit variable calculates the gross profit of an order in real time and returns the value into your server-side GTM container. You can then use that profit value in any tag — for example, to send profit to a Google Campaign Manager Floodlight or a Google Analytics purchase event.
What You Need
Before configuring the variable, make sure you have the following ready.
| Requirement | Details |
|---|---|
| ProfitMetrics account | An active ProfitMetrics website with product cost data configured |
| Public ID | Found on the Websites page in ProfitMetrics, under the Public ID column |
| API key | Request one from support@profitmetrics.io |
| Server-side GTM | A working server container that receives a purchase event with order data |
| Fallback costs | Configured under Expenses > Fallback costs in ProfitMetrics |
To request your API key from the ProfitMetrics support team, please feel free to use the following template:
Hi ProfitMetrics,
Please create a server-side GTM variable API key for the website below:
Public ID:
URL: https://example.com
Installing the Template
The variable ships as a custom template file (.tpl) which you import into your server-side GTM workspace.
- Download the template file from this Google Drive link.
- In server-side GTM, go to Templates → Variable Templates → New.
- In the template editor, open the menu (three dots, top right) and choose Import. Select the downloaded
.tplfile. - Save the template and close the editor.
- Go to Variables → New → User-Defined Variable, then select ProfitMetrics - Profit from the custom variable types.
Profitmetrics data
This is the main configuration block. It connects the variable to your ProfitMetrics account and provides the order-level fields used in the profit calculation.
| Field | Description |
|---|---|
| Profitmetrics Public ID | Your website's Public ID from the Websites page in ProfitMetrics (Required) |
| Profitmetrics API key | The API key issued to your account (Required) |
| Shipping weight (grams) | Order shipping weight, in grams (Optional) |
| Shipping method | Shipping method name, e.g. "Express", "Standard" (Optional) |
| Payment method | Payment method name, e.g. "Credit card", "PayPal" (Optional) |
If Shipping weight, Shipping method, or Payment method are not available on a given order, ProfitMetrics uses the fallback values configured under Expenses > Fallback costs for that website. Leave these fields empty if you want the fallbacks to apply.
VAT information
These checkboxes describe whether the values in your purchase event already include VAT. The variable strips VAT before sending values to ProfitMetrics, so the settings need to match what your platform actually sends.
| Setting | What it means |
|---|---|
| Total value is tracked including VAT | The value field on your event already has VAT included |
| Shipping is tracked including VAT | The shipping field on your event already has VAT included |
| Product value is tracked including VAT | Product price values inside items already have VAT included |
| Vat rate (%) | Your VAT percentage as a number — for 25% VAT, enter 25 |
The Vat rate (%) field only appears when at least one of the three checkboxes above is enabled. If your VAT settings are wrong, ProfitMetrics will calculate incorrect profit. If you are unsure, check a sample order against your platform admin.
Event data the variable reads automatically
The variable reads the following fields directly from the purchase event in your server container. You do not need to map them manually unless you want to override one of them.
| Event field | Used as |
|---|---|
transaction_id |
Order ID |
value |
Total order value |
currency |
Currency code |
shipping |
Shipping cost |
coupon |
Voucher code |
user_data.email |
Customer email |
user_data.phone_number |
Customer phone |
user_data.address[0].country |
Shipping country |
user_data.address[0].postal_code |
Shipping zipcode |
items[].item_id |
Product SKU |
items[].quantity |
Product quantity |
items[].price |
Product price |
If transaction_id is missing from the event, the variable returns nothing and the calling tag does not receive a value.
Overwrite event data (optional)
Use this section if you need to replace any of the standard fields before they are sent to ProfitMetrics — for example, if your event uses a different identifier as the order ID, or if you want to hash an email before sending.
Each row has two columns: Field (a dropdown of supported field names) and Value (a literal string or a GTM variable reference). Values set here always take priority over the auto-read event data.
| Group | Available fields |
|---|---|
| Order | id, ts, currency, voucherCode |
| Customer | orderEmail, orderEmailMD5, orderEmailSHA256, customerPhone, customerPhoneMD5, customerPhoneSHA256 |
| Shipping | shippingMethod, shippingCountry, shippingZipcode, shippingWeight |
| Payment | paymentMethod |
| Pricing | priceShippingExVat, priceTotalExVat, priceTotalInclVat |
| Products | products |
Profit metrics Order overrides (optional)
Use this section to manually override individual cost fields or the calculated profit on a per-order basis. This is useful when you have known costs that ProfitMetrics cannot derive from the order itself.
| Field | Use case |
|---|---|
shippingCostExVat |
Override the calculated shipping cost |
paymentCostExVat |
Override the calculated payment processing cost |
extraCostExVat |
Add an additional one-off cost to the order |
grossProfitExVat |
Override the calculated gross profit value entirely |
Output
The variable returns one of two values per order. Pick the one you need in the tag that consumes this variable.
| Output type | Returned value |
|---|---|
| Profit | The calculated gross profit, returned as a number |
| Currency code | The currency code of the order, e.g. USD, EUR, GBP |
If you need both values in the same tag, create two instances of the variable — one set to Profit and another set to Currency code.
Using the variable in a tag
Once the variable is configured, reference it from any server-side tag that needs the profit value. Common use cases:
- Send profit as the revenue value for your 'PM Gross Profit - Browser' conversion action.
- Send profit as the purchase value to a Google Analytics property, or add it as a custom metric to an existing property purchase event.
The variable resolves once per request, so multiple tags that read it within the same request all receive the same value without triggering a second calculation.
Troubleshooting
If the variable returns no value or an unexpected value, enable Log to console in the variable settings and run the request again in the server-side GTM Preview mode. The console output shows the data being sent and the response received.
| Symptom | Likely cause |
|---|---|
| Variable returns nothing | The event has no transaction_id, or the call to ProfitMetrics failed |
| Wrong profit value | VAT settings do not match the actual event data, or fallback costs are missing in ProfitMetrics |
| Authentication error in console | Wrong Profitmetrics Public ID or Profitmetrics API key |
| Same value across different orders in preview | Result cached for a repeat transaction_id within the same request — preview a new request with a different order |
| Profit is reasonable but missing shipping or payment cost | Fallback costs not configured under Expenses > Fallback costs |
| Profit calculated as if the order had no products | The items array is malformed — the variable expects each item to have item_id, quantity, and price. If those fields are missing or named differently (e.g. id or sku), products cannot be matched to their costs in ProfitMetrics |
For anything not covered here, contact support@profitmetrics.io.