Google Analytics Sessions (60+ New Analytics Hacks 2019)

Google Analytics Sessions

Google Analytics Sessions: Add user to Google Analytics

Google Analytics typically counts users with the client ID, an identifier stored in a cookie that is particular to a specific browser and device. For sites where users log in or you can otherwise identify them, Google Analytics supports using a user ID instead for a more accurate count of users across devices.


Privacy concerns, policies, regulations, and appropriate disclosures to your site’s users are important considerations when collecting user ID data. Review them carefully.


User ID features are enabled in Google Analytics at the property level, choosing to use session unification (counting hits before the user logs in) or not. Within that property, user ID–enabled views can be created, which show only data with an associated user ID along with additional cross-device reports.


Google Analytics

In Google Tag Manager, the user ID is captured from the website, typically by inserting the user ID value into the data layer. Google Analytics tags in Google Tag Manager are altered to include this user ID variable.


Google Analytics reports a metric called Users, which sounds like it counts the number of people using the site. A “user” should represent a single person’s activity over time on the site, right?


Unfortunately, it’s a little more complicated than that. Google isn’t watching us all through our device’s cameras and using facial recognition to identify us (yet), and so “user” and “person” are not precisely the same thing.


Google Analytics uses a cookie that contains a client ID. This is a randomly generated identifier. Since it’s stored in a cookie, it’s particular to the specific browser and device. By default, this client ID is what Google Analytics uses to calculate the Users metric and user behavior across sessions.


So “user” truly corresponds to “browser/device,” rather than “person.” And as you know, people can and do delete their browser’s cookies (manually or using “private” browsing modes), as well as use multiple devices (they’ve visited your website on both their laptop and mobile phone, for example).

All of this means that counting users by client ID is inaccurate to some degree.


In some cases, that’s the best you can do, and it’s a limitation of website measurement that you have to live with. Sometimes, however, you have better ways of knowing who a person is when they interact with your site—a site where users log in.


Because they log in, you know exactly who they are regardless of what their cookie says or what device they are using.


 Google Analytics allows us to set an additional identifier, called the user ID, which can be used to arrive at a better approximation of “users” to “people,” and shows us the activity by the same person across devices and browsers.




One straightforward scenario for user ID tracking is simply to stitch together website sessions by the same user across devices, using a login, as described above. The user ID can also be useful to join up data between:


Website activity and mobile apps. If users log in to both your website and mobile apps, you can unify their activity across those interfaces and devices. Website activity and other online or offline marketing activity.


If users log in to your website, you may have a profile in your CRM or other systems that include information like an email address, social network usernames, or a loyalty card number (for in-store purchases).


Some of this data may be made available in Google Analytics through data import or by using the Measurement Protocol, or you may join up the data after exporting it, using tools such as using BigQuery for data warehousing and analysis or using the Google Analytics APIs to extract data.


Depending on the internal data you retain about your customers, you may be able to think of additional ways to use this data.

Google Analytics

Caution  When it comes to identifying users, what’s technically possible extends beyond what’s permitted under Google Analytics’s policies.


There are a number of techniques for more precise identification of individuals across browsers or when cookies are deleted that would not be permissible (such as re-creating cookies from the Flash shared object or browser fingerprinting, or using a mobile device identifier).


Google’s policies and the laws of the countries in which you operate are subject to change; check them carefully and seek legal advice if necessary to ensure that you’re playing by the rules. Remember that reputable websites always clearly inform users how their data will be collected, retained, and used.


There are three basic steps to setting up user ID tracking in Google Analytics:

  • Turn on the user ID feature in the Google Analytics property.
  • Create a view in the Google Analytics property to report on user ID data.
  • Alter your Google Analytics tags in Google Tag Manager to send the user ID value.


You’ll work through these processes in the rest of the blog. Google Analytics’s terms of service for your country can be found at

The additional user ID policy can be found at https://developers.


Set Up User ID in Google Analytics


User ID features in Google Analytics are enabled at the property level. Once the user ID is enabled for the property, you can create views within the property that unify users based on the user ID, and show special cross-device reports. All of our existing views will continue to use the old rules (users calculated by client ID).


You’ll need to create a new view to take advantage of the user ID. The user ID can only be enabled at the time the view is created; this setting cannot be changed later.


Views that use the user ID will contain data only for sessions where a user ID was set. This means that the user ID views won’t contain sessions for anyone who wasn’t logged in, for example.


As a result, you’ll never want to have only a user ID view for a property; you’ll want at least one with the option turned on (to view cross-device behavior using user ID) and another with it turned off (to show sessions for everyone, including non-identified users).


When setting up the user ID features, you have the option to control the session unification, which relates to whether data collected in a session before the user is identified is associated with the user. For example, consider this sequence of page views in a session.


If you turn session unification on (the default), all the pageviews in this session are associated with the user ID, even though you didn’t know the user ID yet on the first two page views. (Note that session unification only applies to track hits within a single session.


Non-logged-in sessions are never associated with a user ID or included in the user ID view.) For many websites, turning session unification on is probably the option you want.


However, sometimes you might want to consider only the pages where the user ID is set (the last three pageviews, in this example). This could be the case for policy reasons, or for a computer shared by multiple people who log in.

For example. Turning session unification off only includes data in user ID–enabled views where the user ID was set for the tracking hit.


[Note: You can free download the complete Office 365 and Office 2019 com setup Guide for here]



Google Analytics

  • First, you’ll enable user ID tracking in the Google Analytics property.
  • In the Admin section of Google Analytics, select the desired property (middle column).
  • In the Tracking Info section, select User-ID.
  • Review the policy and agree to the terms by toggling the switch to On. Select Next Step to continue.
  • Google Analytics will display instructions for setting the user ID in the tracking code; you can skip over this for now, as you’ll set it up in Google Tag Manager later in the blog.
  • Choose to keep session unification on or to turn it off by toggling the switch.
  • Select Next Step to continue.


The last step will prompt you to create a user ID–enabled view. You can select the Create button to start that process, or see the next section if you need to create a new user ID enabled view for this property at any time in the future.




In the Admin section of Google Analytics, select the View drop-down (third column) and choose to Create new view at the bottom of the list. (Alternatively, if you are following along from the previous steps, clicking the Create button at the end of that process gets you to the same place.)

  • Select Website for the type of view.
  • Enter a name for the view (such as “Logged In Users”, for example) and choose a time zone.
  • Change the User-ID view setting to On.
  • Select the Create View button to complete creating the view.


Once the view is created, don’t forget to change any additional settings you need to, such as applying filters or setting up conversions or Channel Groupings.


In your new user ID–enabled view, only sessions and hits where the user ID was specified will appear, and the Users metric will be based on the count of unique user IDs. Additionally, you’ll find some extra reports in Audience ➤ Cross-Device that show cross-device behavior by users.


Send User ID Data with Google Tag Manager

Now that you’ve enabled Google Analytics to receive and use user ID data, you need to set up your site and Google Tag Manager to send it.

Provide a User ID Value


Your site needs to provide a user ID value for Google Tag Manager to use. The most direct way to do this is to include an entry in the data layer declaration (the information included in the data layer before the Google Tag Manager code):dataLayer = [{ 'userId': 'alice0214' }];


Then you can simply use a data layer variable in Google Tag Manager to access this value.

Getting this value in the data layer typically involves some server-side website coding to insert the appropriate value Depending on your site, there may be other possible ways to find the user ID value: in a cookie, or even using an element on the page where it says “Welcome, Alice0214!”.


Using a data layer variable ensures that other changes to the site (e.g., changing the layout where the “Welcome, Alice0214!” element is placed on the page) don’t affect your tracking setup.


As with many other variables discussed in this book, using the data layer to organize information for Google Tag Manager is always safer and more reliable than relying on page content or other scripts (which are potentially out of your control).


Tip there isn’t a Google Analytics report where the user ID value is directly visible. In many cases, you’re interested in reporting on the user ID value to match up with data from other sources, so it’s a good idea to also send this variable in a custom dimension which you can use in reports and exported data.


Set Up Google Tag Manager to Send User ID to Google Analytics

Set Up Google Tag Manager to Send User ID to Google Analytics

Now that you have the user ID provided in the site’s data layer, you’ll need to set up Google Tag Manager with a variable to capture that value, and then alter the Google Analytics tag to send the variable as the user ID. Let’s walk through the process.


First, let’s create a variable to capture the user ID from the data layer.

  • In Google Tag Manager, in the Variables section, select the New button to create a new user-defined variable.
  • Choose Data Layer Variable as the variable type, and then select Continue.
  • As the data layer variable name, enter the name you used for the data layer entry
  • Select Create Variable to save the variable. Give it a name: “User ID”.
  • Now you’ll need to alter the Google Analytics tags in Google Tag Manager to pass the value of this variable.


Let’s start with the basic pageview tag.

  • In Google Tag Manager, in the Tags section, choose the Google Analytics – Pageview tag and select it to edit.
  • Click Configure Tag to make changes to the tag configuration.
  • Under More Settings ➤ Fields to Set, choose userId as the field name.
  • As the value, use the {{User ID}} variable that you created previously
  • Select Save Tag to save the changes to the tag.


You’ll want to make this change on all Google Analytics tags within the container so that you send the user ID value along with any tracking hit where it applies.


Of course, you’ll need to test and then publish the new version of the container before this data shows up in Google Analytics. Once these changes are published on the site, you will begin to see data for logged-in users in the user ID view in Google Analytics.


Providing Additional Data About Users

Google Analytics data

Previous blogs covered how to get information from your site into Google Analytics using Google Tag Manager.


 You’ve looked at ways to measure both the basics—user interactions like loading a page, which you track with pageviews—as well as more specific actions—for example, watching videos or downloading files, which you measured with events.


In this blog, you’ll learn how to include additional, customs data that pertains to these pageviews or events to give more information about your site’s content, the users who access it, and their actions.


In many cases, your website may know additional information about users and what they do—information that comes from your user registration database, content management system, or other sources you can capture with GTM—that you’d like to connect with the interaction behavior data in Google Analytics.


You’ll use Google Analytics’s ability to accept custom dimensions and metrics to layer in this additional data. This data, which will be unique to your orGoogle Analyticsnization and your website, can be valuable to have in Google Analytics to be used in more detailed analysis and segmentation.


Custom Dimensions and Metrics

Custom Dimensions and Metrics

Recall that Google Analytics’s reports are or Google organized into dimensions and metrics. Each hit you send to Google Analytics fills in certain built-in dimensions and metrics.


However, Google Analytics also gives you the ability to add custom dimensions and metrics to the hits you send. Let’s look at each of these and some of the reasons you might want to use them.



Dimensions are labels to bucket data into categories. Each type of hits, like pageviews and events, has predefined dimensions that you’re able to populate with different pieces of data.


For example, with page views, you have a dimension called Page, which is generally the path of the page that you’re on

With events, you have more generic dimensions to work with, such as Event Category, Event Action, and Event Label. You’re able to put anything you like in these fields;


For instance, you can use Downloads, PDF, and example.pdf respectively to tell Google Analytics that someone initiated a download, that the file type was PDF, and that the particular file they started to download was named example.pdf.


In addition to dimensions that are associated with each hit, there are others that may apply to the entire session, to the user, or even to a particular product (in e-commerce data).


All of these dimensions are predetermined and gathered in the Google Analytics tags in Google Tag Manager. Custom dimensions allow you to supply your own labels for additional ways of categorizing data that goes beyond these.


With custom dimensions, you have complete control: you get to name the dimension and then decide what to store in that dimension. If you know the author who published a blog article, or a user’s registration status, or a product’s weight, you can store that in Google Analytics.


 Google Analytics allows you to create 20 custom dimensions per property. (Google Analytics Premium subscribers get up to 200 custom dimensions per property.)


When you create a custom dimension, you need to specify a scope, which indicates what data in Google Analytics it relates to, or how long Google Analytics should “remember” the custom dimension. There are four possible scopes:


User: The information provided adds more information about a particular user and will be remembered every time that user comes back. User-level custom dimensions are used for qualities of the user that should apply to their current session and all future sessions (unless you change or update the value). Possible examples could include the following:


  • Demographic information such as age, gender, income, occupation, and so forth.
  • Customer information such as a user ID, status, subscription level, or renewal date.


  • Cumulative data on the user’s relationship with the site, such as lifetime value or total shares.
  • User cohort information, such as date of first purchase, date of registration, and so forth.


  • (Date of the first session is a built-in dimension in Google Analytics, so you won’t need a custom dimension for that, but other “firsts,” like product purchases, could be useful.)


  • Session: The information provided describes that particular session. Examples might include the following:
  • Behavior that occurred during the session, such as logged-in status or whether a particular type of content was viewed.


  • Engagement with a particular feature of the site, such as faceted navigation or whether anything was added to the shopping cart.
  • Hit: The information provided describes only this particular hit, like a pageview or an event. Examples might include the following:


  • Page level information such as author name, publication date, or page category.


  • Product: The information applies to a particular product, beyond the basic dimensions that you can use with Google Analytics’s e-commerce tracking. Examples could include the following:


  • Product weight, sourcing information, internal tracking IDs, and so forth.


Warning  With custom dimensions, you’re given free rein with the fields you create and populate. Keep in mind that Google Analytics’s terms of service prohibit collecting personally identifiable information—so custom dimensions that contain the user’s name, email address, and so forth, are definite no-nos. Make sure that you read and adhere to the policies.



Google Analytics metrices

Whereas dimensions are labels that sort hit, session, or user data into categories, metrics are measurements assembled from counting those hits. Metrics are numbers in various units, such as total page views or events, which simply count up from zero; or a time element, like session duration; or dollar amounts for e-commerce and goal values.


As with dimensions, you can also create your own custom metrics. When creating a custom metric, you can choose the format to be an integer, a decimal currency, or a time measurement.


Google Analytics formats the metric appropriately based on this type in reports. Google Analytics allows you to create 20 custom metrics per property. (Google Analytics Premium subscribers get 200 per property.)


You also must choose a scope. There are only two scopes for custom metrics:

Hit: The custom metric represents a measurement associated with the hit to which it is attached, such as a page view or event.

Product: The custom metric represents a measurement associated with a particular product in an e-commerce transaction.


Note  Custom metrics are always totaled across some dimension, which also has a scope. As a result, you’ll get the total for a custom metric for a given hit by using a hit-scoped dimension (like Page), for a session by using a session-scoped dimension (like Campaign), and so forth.


The terms of service may vary by the country in which you operate; find the terms in your country and language here:




When you have some piece of data from your website that you’d like to use in Google Analytics, you have to decide: Is this a dimension or a metric?


Sometimes, the choice is easy. If the value is text, it is certainly a dimension. Metrics are always numbers. So anything you’d use text for—a category for pages or other hits, a label or identifier for users or sessions—must be a dimension.


So, you might wonder, is the inverse true: If it’s a number, it must be a metric? This requires a little more thought. Metrics are always numbers (an integer, currency value, or length of time), but not all numbers have to be metrics.


To find examples, look at the list of built-in dimensions in Google Analytics. You’ll find that some of them are numbered: Page Depth (the number of page views that occurred during the session), Day of Week (0 to 6 for Sunday to Saturday), and many others. What’s going on here?


In some cases, a number is just a label for something. This is the case in the Day of Week dimension, for example, the numbers 0 to 6 are simply labels for Sunday to Saturday, not measurements of any kind, and it would be nonsense to total them up.


In other cases, like Page Depth, those numbers are based on measurements. There are already metrics that measure “how many page views?”—that metric is just Pageviews! Why would you ever need a dimension for this when you already have a metric?


To find the reasoning behind this choice, remember that dimensions are used to categorize or bucket together hits, sessions, users, or products.


The Page Depth dimension, then, gives you a way to say “Show me metrics for all the sessions that had exactly 1 pageview” (or 2, or 3, etc.). Dimensions are used as the rows of reports, whereas metrics fill out the columns. If you want to be able to see metrics across some list of categories, that category is a dimension.


Additionally, remember that metrics get totaled up across hits, sessions, users, and so forth, whereas dimensions are simply labels. 


When thinking about the custom dimensions and metrics that you desire for your own site, think about what you’d want the report to look like. The row labels are dimensions; the column values are metrics.


Accessing Custom Dimensions and Metrics in Google Analytics

Accessing Custom Dimensions and Metrics in Google Analytics

Once you’ve sent data into custom dimensions or metrics, there are a few different ways to access this information in Google Analytics’s reports.

 Custom dimensions are available in most standard reports as a secondary dimension. You can also use custom dimensions and metrics in custom reports and dashboards.


Custom reports are the most flexible and useful way to access this custom data. (Custom dimensions and metrics are also available in Google Analytics data in BigQuery and the reporting APIs; )


Setting Up Custom Dimensions and Metrics

Now that you have an understanding of why you might want to use custom dimensions and metrics, let’s look at the process to implement them in Google Analytics and Google Tag Manager.


There are three steps to begin sending data in custom dimensions or metrics: First, you need to create and label the custom dimension or metric to store the data in Google Analytics.


Next, you’ll need to actually generate the data that you’re going to use from the content of your site or other metadata (most often by placing it in GTM’s data layer).


Finally, you need to send this data to Google Analytics by including the custom metric or dimension with a Google Analytics tag in Google Tag Manager.


The following sections walk through this process, beginning with a relatively simple example. Suppose users of your site can register for the Alice’s Wonderland Resorts Mad Hatter Club, which signs them up for special offers and discounted park admissions.


When they sign up, they specify their preferred park location, which helps you target the offers that you send to them. You want to record this information in Google Analytics.


You need to ask yourself several questions before you begin:

Is this a dimension or a metric? This is a dimension, as it’s a label for various categories (park locations for the Mad Hatter Club membership). What’s the scope? 


Since the Mad Hatter Club Location applies to the same user every time they return, you’ll want the scope to be used. Google Analytics applies the value to every session in which they return with the same cookie.


Where will the data come from? You have to already have this data somewhere! There’s some database or application connected to the website where users sign up for the Mad Hatter club, and when they sign up or log in, you’ll look up that information. 


You’ll explore this in more detail shortly, but the answer to this question is always specific to your site’s platform and tools since the data ultimately comes from some existing information.


Creating a Custom Dimension or Metric in Google Analytics

Creating a Custom Dimension or Metric in Google Analytics

When creating a custom dimension or metric, you get to choose the name that will appear as the label of the dimension or metric in Google Analytics’s reports. You’ll want the name to be something descriptive that makes sense to those who will be using the data. 


Since all other field names in Google Analytics have the first letter of each word capitalized, it is recommended to do the same. For this example, you’ll name the dimension “Mad Hatter Club Location”.


You’ll add a custom dimension in Google Analytics, using the Mad Hatter Club Location example.


In the Admin area of Google Analytics, with the appropriate account, property, and view selected, choose Custom Definitions ➤ Custom Dimensions (or Custom Metrics) in the middle column to see the custom dimensions for the property. Select the New button to add a new custom dimension.


  • Enter a name for the custom dimension (or metric): “Mad Hatter Club Location”.
  • Choose a scope from the drop-down menu appropriate to the dimension or metric. For Mad Hatter Club Location, you’d choose User scope (as discussed earlier).


  • (Metrics Only) Choose the formatting type for custom metrics: integer, currency, or time.


  • (Metrics Only) Enter the optional minimum and maximum values. Google Analytics will ignore values outside this range. This is useful to prevent accidental nonsense values (like a miscalculated currency value of $100 billion) from overwhelming the total for a custom metric.


  • Check the box to activate the dimension or metric. (Unchecking this box deactivates the dimension or metric and ceases collecting data.)
  • Select the Create button to create the custom dimension or metric.


Each custom dimension or metric is assigned to a specific index number from 1 to 20. Keep a note of the index number for the dimension or metric that you’ve created, as you’ll need it later in the process to fill in its values.


Just like with goals, custom dimensions and metrics cannot be deleted, just turned on or off. You can, however, rename them if you need to reuse a specific slot.


Generating Custom Data

Generating Custom Data

Now that you’ve set up the name of the custom dimension and the scope where you’re going to send the data, you need to tackle the more difficult part: finding the data to send.


You need to already be gathering the information that you want to send to Google Analytics, and then make it available in some way.


For instance, if you wanted to send in information that describes users’ gender and age, logically you need to first know their gender and age—Google Analytics and Google Tag Manager can’t automatically create this data for you! There are several ways that you can gather such data, but they all fall into two general categories:


Surfacing information from an internal database, such as a content management system with information about pages and content, a user database for information about users who log in to the site, or e-commerce system with product data. 

Collecting information from a user, either directly through a form or indirectly through their behavior on the website.


Note  In this blog, you are considering how custom dimensions and metrics are filled directly from a website.


It’s also possible to fill in values for certain dimensions and metrics (including custom ones) using the data import features of Google Analytics, taking a bulk set of values and associating it with Google Analytics fields.


Using existing information in a system connected to the website is the more common option, so let’s consider that situation first. (You can use GTM’s form trigger to capture form field values; more on that in a later example.)


Whatever the source of the data, you need to figure out how to get it to the web site's codewhere it can be read by Google Tag Manager. Sometimes it may be readily available on the site.


For instance, imagine a blog or news site that would like to pass in content metadata such as publication date, author, or tags with every article. Usually, this information is already present in a content management system and can be inserted into the site’s template.


Sometimes this information is a little trickier to retrieve. Maybe you have a user database available with all sorts of information about users when they log in, like the user’s contact information, their Mad Hatter Club status and preferred city, their hat size, and whatever else you know about them.


This information is only accessible when a user logs in and you’re able to match them to their personal information.


Tip  Consider ways to incentivize users to sign in to your website! This gives more information about the site’s audience and allows passing in custom information more frequently. Additionally, signed-in users enable cross-device tracking if you’ve configured your User ID View correctly


If you know the information, then there’s a relatively easy way to pass this information to Google Tag Manager: the data layer. Accessing the value and inserting it into the data layer will be specific to your site’s tools and platforms, of course.


Using the Data Layer

You’ve used the data layer declaration (before the Google Tag Manager container in the page) a number of times in this book to provide information to Google Tag Manager.

You can do the same for the Mad Hatter Club Location information: dataLayer = [{'hatterClub': 'Schenectady, NY'}];


The value (Schenectady, NY, in this example) is inserted based on the location chosen by that particular user as their favorite park location. 


You can continue to add to the data layer with any piece of information that you’d want to pass to Google Analytics as a custom dimension or metric. In Google Tag Manager, you’ll be able to simply use a data layer variable to retrieve these values.


Depending on your site, there may be other possible ways to find the values you’re looking for, such as by using a DOM element variable if the data appears in the content of a page.


However, using a data layer variable ensures that other changes to the site don’t affect your tracking setup and that the value is available as soon as Google Tag Manager loads.


As with many other variables discussed in this blog, using the data layer to organize information for Google Tag Manager is always safer and more reliable than relying on page content.


Note  For product-scoped dimensions or metrics, include the metric in the product object in the e-commerce data you’ve already included in the data layer, using a name like dimension or metrics, where XX is the number of the index for the dimension: for example, 'dimension2': 'blue'.


Since you’ve already set up Google Tag Manager to use the data layer to fill in e-commerce values, it will automatically capture these


Sending Custom Information to Google Analytics

Google Analytics send

Once you have the desired values in your data layer, it’s relatively simple to pass these to Google Analytics using the tags you’ve set up in Google Tag Manager.


Custom dimensions and metrics get sent with an existing hit, so you can add them to an existing tag, such as a page view or event tag. You just need to find a hit that is already going to Google Analytics and then you’ll hitch a ride.


Depending on the scope of the dimension or metric, you might want to include it with all hits (tags) or just some. For a hit-scoped dimension or metric, you’d only want to include it with the appropriate kinds of hits, and thus possible only with certain tags.

For example, a custom dimension for an article’s publication date might only apply to pageviews (the articles), not to events.


For session- or user-scoped dimensions, you only absolutely need to send the value once during the session, or once for the user. For the Mad Hatter Club Location variable, for example, you would only need to set this value when the user first signs up for the Mad Hatter Club.


However, in many instances, you want to send the value again (say, every time the user logs in, or even on every page). This helps reinforce the value if the user switches devices or browsers, clear their cookies, or if the value changes.


 If you specify values more than once for the session- or user-scoped dimensions, the last value wins for that session. (Previous sessions’ values remain unchanged.)



Google Analytics

Let’s take the Mad Hatter Club Status information from the data layer and insert it into a Google Analytics tag in Google Tag Manager.

First, you’ll create the variable to capture the value from the data layer.

  • In Google Tag Manager, in the Variables section, select the New button to create a new user-defined variable.
  • Choose Data Layer Variable as the variable type, then select Continue.
  • As the data layer variable name, enter the name you used for the data layer entry
  • Select Create Variable to save the variable. Give it a name: “Mad Hatter Club Location”.


Now you’ll need to alter the Google Analytics tags in Google Tag Manager to pass the value of this variable. In this case, you’ll simply include the value in the basic pageview tag. Any time the data layer value is present on a page, you’ll send the custom dimension along with that pageview.


In Google Tag Manager, in the Tags section, choose the Google Analytics – Pageview tag and select it to edit.

  • Click Configure Tag to make changes to the tag configuration.
  • Under More Settings, ➤ Custom Dimensions, click the Add Custom Dimension button to add a new custom dimension.


  • Fill in the index number of the custom dimension that corresponds to the custom dimension that you created in Google Analytics earlier.


  • For the Dimension Value field, use the {{Mad Hatter Club Location}} variable you created in steps 1–4.
  • Select Save Tag to save the changes to the tag.


You’ll need to test and then publish the new version of the container before this data shows up in Google Analytics. As always, you can verify that it’s working properly using the Google Tag Manager Debug Panel or the Google Analytics Debug mode in the console.


Once these changes are published on the site, you’ll begin to be able to see data for the custom dimension or metric in custom reports or by using a secondary dimension in the standard reports. (Remember, there’s no built-in standard report that automatically includes custom dimensions or metrics, so you’ll have to create one to see the values.)


Additional Examples

The previous section looked at a basic example of a custom dimension. Now let’s look at a couple of additional examples to explore the possibilities: a custom dimension based on form input, and a custom metric based on interaction.


Custom Dimensions from Form Input

Besides using data from another system in the data layer, another way to collect data for a custom dimension would be to scrape some information from a form that a user fills out. This might be information that is given only once and is not available to you later after the form is submitted.


Suppose you have a contact form on your website. You might ask for a user’s gender or perhaps ask them to identify themselves in a certain bucket, like TeacherStudent, or Parent.


If you can intercept that data from the form as its being submitted, you may be able to take those fields that they filled out and store them as a user-scoped custom dimension.


Capturing a custom dimension from a form is another great application for the form trigger but requires you to dig in a bit deeper.


Like the click trigger, the form trigger adds information about the form submitted to the data layer. It looks something like the following:

{ event: "Google Tag Manager.formSubmit",

Google Tag Manager.element: form#contact-form,

Google Tag Manager.elementClasses: "",

Google Tag Manager.elementId: "contact-form",

Google Tag Manager.elementTarget: "",

Google Tag Manager.elementUrl: ""



You’ve already learned about how to grab the ID and classes of the form, which work exactly the same way as clicks. The really exciting part here is that Google Tag Manager adds the entire DOM object to the data layer as Google Tag Manager.element.


That means that everything about that form is now accessible inside of Google Tag Manager, including all the form fields and their current values at the time of submission.


Accessing the various parts simply involve navigating the DOM object for the form to find the field that you want. For form fields, the DOM structure is actually quite simple: each form field is nested under Google Tag Manager element in the order that it appears in the form, listed by number, starting with 0.


Under each form field, there’s an attribute called value that will be the value of the form field at the time it was submitted.


To get this information into Google Tag Manager, you’ll find the specific form field that you care about, then grab its value from the data layer using a data layer variable. The data layer uses periods to indicate nested values, so the preceding path would look like the following in the data layer variable:


Google Tag Manager.element.0.value


This data layer variable, when coupled with a form trigger, will return the value of the first field in the form that was just submitted. (Use a different number for a field other than the first one.) Now you can use that variable to fill in a custom dimension, just like the earlier scenario using an explicitly provided value in the data layer.


Custom Metrics from Interactions

Google Analytics custom

You can also create custom metrics based on the count of some other interaction you’re measuring with a page view or an event.


Why would you duplicate an event or page view count with a custom metric? Again, simply to make reporting easy. Although there are metrics in Google Analytics such as the total number of page views or events, you’d need to employ creative filtering or segmentation to get just the number of page views or events of a certain kind.


What if you’d just like a column with the count of a certain kind of pageview or event? A custom metric is a perfect solution. For example, suppose you’re using events to track downloads on your site. You could create a custom metric for Downloads and easily see that as a column in reports.



You’ll first need to create a custom metric in Google Analytics according to the instructions earlier in the blog.


Name it “Downloads” and choose Integer as the formatting type. Make a note of the index of the custom metric; you’ll need it in the steps that follow. You’ll also already need a tag in Google Tag Manager with an event to track downloads.


In Google Tag Manager, in the Tags section, choose the Google Analytics event tracking tag for downloads and select it to edit.

  • Click Configure Tag to make changes to the tag configuration.
  • Under More Settings ➤ Custom Metrics, click the Add Custom Metric button to add new custom metric
  • Fill in the index number of the custom metric that corresponds to Downloads.
  • For the Metric Value field, simply use the value 1.
  • Select Save Tag to save the changes to the tag.
  • Of course, you’ll need to test and publish in Google Tag Manager before the changes take effect.
  • Once published, every time a file is downloaded and the event is sent to Google Analytics, the count of the Downloads metric will be incremented by 1.