---
title: Setting Up the ProfitMetrics Profit Variable in Server-Side GTM
description: Setting Up the ProfitMetrics Profit Variable in Server-Side GTM
---

[Skip to content](https://knowledge.profitmetrics.io/profitmetrics-profit-variable-in-server-side-gtm#main-content)

[![ProfitMetrics logo black version](https://knowledge.profitmetrics.io/hs-fs/hubfs/pm_logotype_blue.png?width=193&height=28&name=pm_logotype_blue.png)](https://knowledge.profitmetrics.io/?hsLang=en)

Open main navigation

Close main navigation

- [Contact Support](https://knowledge.profitmetrics.io/kb-ticket/new)

[Contact Support](https://knowledge.profitmetrics.io/kb-ticket/new?hsLang=en)

 How can we help you?

- There are no suggestions because the search field is empty.

1. [Knowledge base](https://knowledge.profitmetrics.io/?hsLang=en)
2. [E-commerce Platforms](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en)
3. [Universal Integration (Server-side Hybrid)](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#universal-integration-server-side-hybrid)

# 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](mailto: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.

1. Download the template file from [this Google Drive link](https://drive.google.com/file/d/1yKHBm5a-Cq4JXpsj5Gq2393TSRG3g6f2/view?usp=sharing).
2. In server-side GTM, go to **Templates** → **Variable Templates** → **New**.
3. In the template editor, open the menu (three dots, top right) and choose **Import**. Select the downloaded `.tpl` file.
4. Save the template and close the editor.
5. 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 |

---

#### **Currency**

By default, the variable uses the currency code from the purchase event. If you need to override it — for example, when your store reports values in one currency but you want ProfitMetrics to treat them as another — enter a three-letter currency code in the **Output currency** field (e.g. `USD`, `EUR`, `GBP`). Leave the field blank if the event's currency is correct.

---

### Set up an Estimated profit fallback variable

The Profit variable returns a live value from ProfitMetrics. For tags where you want a backup value available — for example, during initial setup, or as an approximate value if the live calculation is unavailable — create an Estimated profit variable based on your store's average margin.

1. In server-side GTM, go to **Templates** → **Variable Templates** and import the **Deduct percentage** template from the **Community Template Gallery**.
2. Go to **Variables** → **New** → **User-Defined Variable** and select **Deduct percentage**. Name it **Estimated profit**.
3. Set **Input number** to your order value variable.
4. Set **Percentage** to your store's average margin. For a 35% margin, enter `35`.
5. Leave **Input includes percentage** unchecked.

You can now reference `{{Estimated profit}}` anywhere a backup profit value is useful.

### Create a value transformation

A server-side transformation runs before the affected tags fire and rewrites fields on the incoming event. This avoids hard-coding the variable reference into each conversion tag.

1. In server-side GTM, go to **Transformations** → **New** → **Augment Event**.
2. Name the transformation **Gross profit value transformation**.
3. Under **Parameters to augment**, add a row with **Name** set to `value` and **Value** set to `{{ProfitMetrics - Profit}}{% endraw}`.
4. Under **Affected tags**, select only the tags that should report profit as the conversion value — for example, a dedicated Google Ads Gross Profit conversion tag. Do not apply it to tags that should still receive revenue.
5. Save the transformation.

### Configure the destination tag

In the conversion tag that should use profit as its value (e.g. the Google Ads Gross Profit conversion tag):

- Leave **Conversion value** and **Transaction ID** blank.
- Make sure the tag is set to read these fields from the incoming event data automatically (they normally do this by default with a standard Google Analytics event stream format).

By the time the tag fires, the transformation has already replaced the event's `value` with the calculated profit, so the tag reports profit instead of revenue. The Profit variable resolves once per request, so multiple tags reading it in the same request receive the same value without triggering a second calculation.

The setup above assumes the standard event stream — purchase events with `value`, `items`, `currency`, and `user_data` sent in the standard GA4 format. Custom dataLayers or non-standard items arrays may require remapping via the **Overwrite event data** section in the Profit variable.

---

**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](mailto:support@profitmetrics.io).

 

### **TIP: Isolating your own browser when testing Shopify checkout tracking** Step 1: Set a debug flag in your browser

In the browser you're using to test, open the developer console on your storefront and run the following command:

```
localStorage.setItem('debug', '1');
```

This stores a flag called `debug` with the value `1` in that browser only. It has no effect on any other visitor and won't be sent anywhere on its own — it just sits in your browser's storage until something reads it.

**NOTE:** This flag is specific to the browser and device you set it in. If you switch browsers or devices, or clear your browser storage, you'll need to set it again.

---

### Step 2: Read the flag in your tag manager container

In your web tag manager container, create a Custom JavaScript variable to read the flag back out of storage. Name it `localStorage getItem - debug` and use this code:

```
function() {  try {    return localStorage.getItem('debug');  } catch(e) {    return undefined;  }}
```

Wrapping the read in a `try/catch` means the variable safely returns `undefined` instead of causing an error for visitors whose browser blocks access to storage.

Next, create a second variable named `dbg`. Make this a Constant variable holding the literal text `_dbg`. This will be used as the parameter name in the next step.

---

### Step 3: Forward the flag as an event parameter

In your Google Analytics purchase tag — the one that sends events on to your server-side container — add an event parameter using the two variables you just created:

| Field | Value |
| --- | --- |
| Name | The `dbg` variable (resolves to the literal text `_dbg`) |
| Value | The `localStorage getItem - debug` variable (resolves to `1` when your flag is set) |

**NOTE:** You need to set the parameter name using the `dbg` variable rather than typing `_dbg` directly, because Google Analytics doesn't allow parameter names starting with an underscore to be entered as free text.

---

### Step 4: Gate your tags in server-side tracking

In your server-side container, add a trigger condition to the tags you're testing so they only fire when the `_dbg` event parameter equals `1`. Any tag with this condition will now only trigger for traffic carrying your debug flag, leaving every other visitor's data untouched.

---

### Testing and cleaning up

With `localStorage.debug` set to `1` in your browser, your checkout activity flows through to the gated server-side tags, letting you verify they're working correctly without mixing your test events into real customer data.

Once you're done testing, clear the flag by running the following in the same browser's developer console:

```
localStorage.removeItem('debug');
```

This stops the flag being forwarded, and your gated tags will no longer fire for this browser.

 

For anything not covered here, contact [support@profitmetrics.io](mailto:support@profitmetrics.io).

- [Getting Started](https://knowledge.profitmetrics.io/getting-started?hsLang=en#main-content)

    - [Learn the Basics](https://knowledge.profitmetrics.io/getting-started?hsLang=en#learn-the-basics)
    - [Prepare for Onboarding](https://knowledge.profitmetrics.io/getting-started?hsLang=en#prepare-for-onboarding)
    - [Account Setup](https://knowledge.profitmetrics.io/getting-started?hsLang=en#account-setup)
- [E-commerce Platforms](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#main-content)

    - [Shopify](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#shopify)
    - [WooCommerce](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#woocommerce)
    - [Magento](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#magento)
    - [PrestaShop](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#prestashop)
    - [BigCommerce](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#bigcommerce)
    - [Shopware](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#shopware)
    - [DanDomain & Related](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#dandomain-related)
    - [Universal Integration (Clientside)](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#universal-integration-clientside)
    - [Universal Integration (Server-side Hybrid)](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#universal-integration-server-side-hybrid)
    - [Other Platforms](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#other-platforms)
    - [Developer Documentation](https://knowledge.profitmetrics.io/e-commerce-platforms?hsLang=en#developer-documentation)
- [Ad Channels](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#main-content)

    - [Google Ads](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#google-ads)
    - [Meta (Facebook/Instagram)](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#meta-facebook-instagram)
    - [Microsoft Bing Ads](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#microsoft-bing-ads)
    - [Google Analytics 4](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#google-analytics-4)
    - [Partner-ads](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#partner-ads)
    - [Other Channel Configuration](https://knowledge.profitmetrics.io/ad-channels?hsLang=en#other-channel-configuration)
- [Tracking & Conversion Setup](https://knowledge.profitmetrics.io/tracking-conversion-setup?hsLang=en#main-content)

    - [Overview](https://knowledge.profitmetrics.io/tracking-conversion-setup?hsLang=en#overview)
    - [Conversion Booster for Google Ads](https://knowledge.profitmetrics.io/tracking-conversion-setup?hsLang=en#conversion-booster-for-google-ads)
    - [Conversion Booster for Meta](https://knowledge.profitmetrics.io/tracking-conversion-setup?hsLang=en#conversion-booster-for-meta)
    - [Conversion Booster Custom Pixels](https://knowledge.profitmetrics.io/tracking-conversion-setup?hsLang=en#conversion-booster-custom-pixels)
    - [Enhanced Conversions](https://knowledge.profitmetrics.io/tracking-conversion-setup?hsLang=en#enhanced-conversions)
- [Shopping Booster](https://knowledge.profitmetrics.io/shopping-booster?hsLang=en#main-content)

    - [Overview & Setup](https://knowledge.profitmetrics.io/shopping-booster?hsLang=en#overview-setup)
    - [Supplemental Feeds](https://knowledge.profitmetrics.io/shopping-booster?hsLang=en#supplemental-feeds)
    - [Campaigns & Labels](https://knowledge.profitmetrics.io/shopping-booster?hsLang=en#campaigns-labels)
    - [Troubleshooting](https://knowledge.profitmetrics.io/shopping-booster?hsLang=en#troubleshooting)
- [Product Feed & Costs](https://knowledge.profitmetrics.io/product-feed-costs?hsLang=en#main-content)

    - [Product Feed](https://knowledge.profitmetrics.io/product-feed-costs?hsLang=en#product-feed)
    - [Shipping & Payment Costs](https://knowledge.profitmetrics.io/product-feed-costs?hsLang=en#shipping-payment-costs)
    - [Expenses](https://knowledge.profitmetrics.io/product-feed-costs?hsLang=en#expenses)
- [Dashboard, Orders & Reporting](https://knowledge.profitmetrics.io/dashboard-orders-reporting?hsLang=en#main-content)

    - [Dashboard & Orders](https://knowledge.profitmetrics.io/dashboard-orders-reporting?hsLang=en#dashboard-orders)
    - [Looker Studio](https://knowledge.profitmetrics.io/dashboard-orders-reporting?hsLang=en#looker-studio)
    - [Google BigQuery](https://knowledge.profitmetrics.io/dashboard-orders-reporting?hsLang=en#google-bigquery)
- [Account & Billing](https://knowledge.profitmetrics.io/account-billing?hsLang=en#main-content)

    - [Users & Access](https://knowledge.profitmetrics.io/account-billing?hsLang=en#users-access)
    - [Billing & Invoices](https://knowledge.profitmetrics.io/account-billing?hsLang=en#billing-invoices)
- [Privacy & Consent](https://knowledge.profitmetrics.io/privacy-consent?hsLang=en#main-content)

    - [GDPR](https://knowledge.profitmetrics.io/privacy-consent?hsLang=en#gdpr)
    - [Consent Management Platforms](https://knowledge.profitmetrics.io/privacy-consent?hsLang=en#consent-management-platforms)
    - [Google Consent Mode](https://knowledge.profitmetrics.io/privacy-consent?hsLang=en#google-consent-mode)
- [For Agencies](https://knowledge.profitmetrics.io/for-agencies?hsLang=en#main-content)

    - [Getting Started as an Agency](https://knowledge.profitmetrics.io/for-agencies?hsLang=en#getting-started-as-an-agency)
    - [Agency Certification](https://knowledge.profitmetrics.io/for-agencies?hsLang=en#agency-certification)
- [Shopify](https://knowledge.profitmetrics.io/shopify?hsLang=en)
- [PrestaShop](https://knowledge.profitmetrics.io/prestashop?hsLang=en)
- [Google Ads](https://knowledge.profitmetrics.io/google-ads?hsLang=en)
- [Meta (Facebook / Instagram)](https://knowledge.profitmetrics.io/meta-facebook-instagram?hsLang=en)
- [Uncategorized](https://knowledge.profitmetrics.io/uncategorized?hsLang=en)
- [Billing](https://knowledge.profitmetrics.io/billing?hsLang=en)
- [Google Sheets](https://knowledge.profitmetrics.io/google-sheets?hsLang=en)
- [Account](https://knowledge.profitmetrics.io/account?hsLang=en)
- [Ideal Shop](https://knowledge.profitmetrics.io/ideal-shop?hsLang=en)

[![ProfitMetrics logo black version](https://knowledge.profitmetrics.io/hs-fs/hubfs/pm_logotype_blue.png?width=193&height=28&name=pm_logotype_blue.png "ProfitMetrics logo black version")](https://profitmetrics.io)

<https://www.facebook.com/ProfitMetrics/> <https://podcasts.apple.com/> [mailto:support@profitmetrics.io](mailto:support@profitmetrics.io)

Copyright © 2026, ProfitMetrics ApS