Custom Metrics Part 2: Dynamic Values

Last week you discovered the ins and outs of custom metrics within Google Analytics. Today we will take that knowledge one step further and uncover how you can populate custom metrics with dynamic values using Google Tag Manager.

After reading the introduction to custom metrics, you now understand how to implement a custom metric on a one to one basis. That is to say that if an action or event happens, you can increment the custom metric by 1 (or 2 or 10, but a static number). While that is how most cases of custom metrics would be handled for Google Analytics, there are the times when you’ll need to incorporate dynamic values for your metrics.

Today we are going to discuss two distinct areas where dynamic values of custom metrics can come into play. There are many other ways of incorporating custom metrics, but for today’s task we will stick with these two, more common approaches.

Dynamic Value Stored in Query Parameter

The most common areas where we see query parameters implemented is for search and campaign tracking. You would see a parameter set in the url for most searches on site, something like ?q=searchterm. One thing that some companies do is store discount prices or sale prices into a query parameter.

So if you went to and made a purchase (there currently isn’t anything actually for sale here), after checkout the URL may read:

Let’s check out how we could capture that as a custom metric using Google Tag Manager.

First let’s assume that your custom mertic is already set up through the Google Analytics admin panel. Now let’s head into Google Tag Manager.

1. Locate Your Purchase Event

First, find the tag that you have set up to fire an event or transaction upon completing the sale. For our example our tag is called Course Purchase.

2. Find the Custom Metric Input

From there you will want to go down to the More Settings area just as we did in the previous post. Select Custom Metrics and put in the index number from your Google Analytics account (for our example we’ll use 1).

Everything up to here is in-line with the standard implementation of a custom metric. Now let’s get into the dynamic value from our Query Parameter.

Start by clicking the lego-like block next to the value field. That will open up a new pop-up as shown below to create a new variable. This is where you will capture the value of the query parameter.

course purchase tag gtm

3. Create Your Dynamic Variable

Create a name for your variable, then select URL from the options of variable types presented.

Once that is selected use the drop-down menu to choose query and then enter the name of the query parameter in use (saleprice for this example) into the input box. Your setup will look like the image below.

gtm purchase price variable creation

Once you save your tag again, test and publish and you will now be capturing the total price of your sale into the custom metric you specified in Google Analytics.

Nesting Variables to Trigger or Block Custom Metrics

While pushing a dynamic value from a query parameter is a great option for many, sometimes you can run into a different problem. I have come across this a lot lately and wanted to make sure to include it to the readers here.

In my real-world example, I was working on a client website where we were tracking the submission of a form for users to sign up for a email newsletter.

I hate having a lot of tags in GTM and I try to cut down on them as best I can. With this thought in mind, I was able to create one tag for two actions; the initial click to bring up the form and then the submission of the form.

This worked great until I wanted to capture a custom metric for the submission on the form, but not during the initial click.

The way that GTM is setup you set a custom metric on the firing of a tag, so in this instance it would have fired a “1” to the custom metric when a user clicked the initial button and again once the submission occurred. Since the custom metric was just “Form Submissions” this wasn’t a great setup.

So how can you use variables to create an way around this issue? It is rather easily solved, but involves a few steps and some thought process. Let’s dive right in.

1. Locate Your Variable which Differentiates the Actions

This must exist for this type of implementation to work. Basically this is the variable that is already in use in your current tag, which differentiates between the two actions. For my example here, I had to create a variable which differentiated whether the click action was an initial click or a submission click.

That variable was then inserted into the event tag as the action. So when I am reading through my Google Analytics reports, I would see an action of either Initial Click or Submission.

Once you have located this variable, don’t do anything with it, other than remember what the variables name is (i.e. eNewsFormChoice).

2. Create a New Nested Variable

Once you know have located your current variable it is time to create a new variable. Head over to the variable section of your container and select the red “New” button to create a new variable.

gtm lookup table variable

From here, name your variable (i.e. eNewsSubCM), and then you will select Lookup Table for the variable type.

If you aren’t familiar with Lookup tables, the basic concept is to lookup the value of one variable, and based off of what that input is, send different values to another variable of your choosing.

For your course of action here, you would select your prior used variable (i.e. eNewsFormChoice) as the input variable. From there we would need to add two rows as we have two different actions that could happen from this variable.

First we know that the two possible returned values of our variable are Initial Click or Submission. Go ahead and start by placing each of those in the Input column, one for each row.

One thing to remember here is that Lookup Tables are very strict. If there is a slight misspelling or a capitalization that shouldn’t be, they won’t work.

lookup table input in google tag manager

Once that is complete we can choose the output for each. For this example I want the custom metric to fire a value of “1” when there is a submission, but I don’t want it to fire at all for the initial click. Within the output areas, I will place a “0” in the initial click row, and a “1” in the submission row.

lookup table values in google tag manager

Go ahead and save your variable and then head over and open the tag that will allow these events to fire.

3. Insert the Nested Variable into Custom Metric

As you head back over to your tag, go down to the custom metrics entry area in the “more settings” of the tag.

Once you open up the space and click the plus button to create a new custom metric, enter the number of the index pushed to your from Google Analytics. For this one we will enter “2” as an example.

Now here is the fun part, you can click the lego-like block in the metric value area and now select the nested variable (i.e. eNewsSubCM).

eNews custom metric gtm

After saving and publishing this enhanced tag, the custom metric will now fire along with the event. So every time this event fires it will look for the value of the event action, either Initial Click or Submission and either fire “0” into the custom metric, or “1” upon submission. Now your custom metric will accurately tally the number of eNewsletter Signup Submissions occurring on site.


I hope this guide has given you some new and interesting ideas on what custom metrics can accomplish. Be thinking about what you want to incorporate on your site and how Google Tag Manager can simplify this process.

Please let me know in the comments below how you have used custom metrics and any successes you have come across.

Come back again next week for the final post in this series on Google Analytics custom metrics. There I will share a list of the top custom metrics I think you should be tracking and some added goodies.

0 responses on "Custom Metrics Part 2: Dynamic Values"

Leave a Message

Copyright 2017 by Chris Kujawski Privacy Policy