Stape
Search
Try for free

Math variable for Google Tag Manager server container

Updated
Oct 14, 2024
Published
Sep 11, 2024

Math variable helps you perform basic mathematical operations between two values. It’s particularly useful when working with dynamic values such as calculating percentages, applying formulas, or adjusting numeric values based on other variables.

The initial development of this template was done by Lars Friis, and it is now maintained by Stape.

Use cases:

  • Ad spend calculations: if you’re setting up something like Profit Over Ad Spend (POAS), you might use the Math Variable to dynamically calculate the ratio between revenue and ad spend.
  • Conversion adjustments: you can use this to adjust conversion values based on a given factor or percentage.
  • Custom metrics: in analytics, you may need to calculate new metrics by multiplying or adding various values from the data you collect.

How it works

Math variable for Google Tag Manager server container

This variable offers a simple configuration where you can:

  • Multiply: multiply two values.
  • Divide: divide the first value by the second value.
  • Add: add two values together.
  • Subtract: subtract the second value from the first value.

How to set up Math variable

Before implementation, make sure you have set up server Google Tag Manager container.

1. Download Math variable from GitHub or get it from the Template Gallery.

Download Math variable

2. Import the variable to server Google Tag Manager by clicking TemplatesNew Variable Template

Click three dots in the top right corner → Click import → Add template that you’ve recently downloaded → Click Save.

Download Math variable

3. Select the operation you want to perform (Multiply, Divide, Add, or Subtract).

For Value 1 and Value 2, you can either enter static values or reference other variables by clicking on the icon. 

Click Save.

4. Once the variable is set up, you can reference it in your tags (e.g., Google Ads conversion tracking, analytics, etc.). Simply use the Math Variable in the relevant field of the tag configuration.

To sum up

You can easily perform real-time calculations based on dynamic values within the GTM environment, without needing to implement external scripts. Math variable is to the rescue :) If you need help with your Stape account, please don’t hesitate to leave a ticket.

Tagged with:gtm server

Try Stape for all things server-sideright now!