Fun With Variables - Creating Dimensions With Google Analytics & GTM

Fun With Variables - Creating Dimensions With Google Analytics & GTM

Google Analytics has become enormously powerful over the years.  When I first started using GA, it was little more than a basic web analytics tool.  Today, however, you can analyze shopping behavior and cohorts, use User IDs to track visitors across devices, conduct A/B testing, import external data, model multiple channels (multi-channel attribution) and analyze their true impact on site goals, and set up custom dimensions and metrics.  With the addition of Google Tag Manager (GTM), Google has really evolved a data-driven digital toolset that rivals some of the top analytics vendors (and it's all for free).

With all the features these days, it’s a little more complex then just placing a tag on each page on your website.  In this post I am going to concentrate on creating & capturing customs dimensions (I wrote a post earlier on data, in case your wondering about dimensions) between GA & GTM.  To do that, you must have a few things in place already.  First, you must have set up GTM for your GA account and using it on your website.  Second, you must be using Universal Analytics code for GA.  Then you will be ready to start creating your own data variables, with a caveat - you and your programmers must be aware of and willing to use the GTM Data Layer.  The Data Layer is how variables can be past from the website, into the GTM and then on to GA.

Let’s say, for example, you want to capture the answers clicked on the page from an on-site evaluation.  We’ll start with the first question - Age Group.  You want to capture that in GA.  Here’s how you would go about doing that between GTM & GA.        

Create a User-Defined Data Layer Type Variable

The first step is to create a variable in the GTM.  Go to the container in GTM for the website.  Click on Variables and under User-Defined Variables, click the big, red New button.  This variable will be a Data Layer Type Variable, so click that box.     Next, you will need to name this variable - maybe something like Age Group.  Then you will need to type a name in the Data Layer Variable Name box - this will be used by programmers to pass values into the Data Layer.  Maybe something like ageGroup.  Then click Create Variable:   

For the Programmers

On the webpage that holds the on-site evaluation, the Data Layer will have to be called in the header:

     <script> dataLayer = [ ]; ,script</>

Then when an age group category is clicked, the on-click event uses the Data Layer to record the click:

     onclick = “dataLayer.push({‘ageGroup’:’18-25’});"

Set Up Custom Definition in Google Analytics

In GA, under Property —> Custom Definitions —> Custom Dimensions create a new custom dimension called Age Group and click the big blue Create button:

Look at the Javascript example code, you will see the dimension1, customDimension(1), and customDimensionForIndex(1) - all letting you know that this new Custom Dimension has an index value of ‘1’, at least in this case:

Now that you have set-up the variable in GTM and in GA and sent the value to the Data Layer, you’ll need to create an event to capture that value and a trigger to pass it to GA.

GTM Event Tag & Trigger

Choose Triggers in GTM and create a new trigger called Eval Form - Age Group.  This trigger will fire on a click targeting Just Links and enabled when on the on-site eval page.  It will fire when the drop-down (for example) on the page is clicked.

Now that the trigger is set, go to Tags to create a new event tag that will be fired by the trigger.  Create a new Google Analytics tag of type Event.  Add the GA Tracking ID, Category (‘Age Group’), Action (‘click’), and Label.  Label will be the Data Layer variable we created earlier, Age Group, and can be accessed from the button to the right of the input box.  
From More settings, add the Custom Dimension that we created in GA, with an index of ‘1’ and Dimension Value of Age Group (just like Label above).  
Have this new event fire on Click and select the trigger we just created.

Conclusion

To review, here are the steps in creating a GA dimension with GTM:

  1. Create Data-Layer Type Variable in GTM
  2. Add Data Layer to Webpage
  3. Code page to pass variable name and value to the Data Layer
  4. Create Custom Dimension in GA
  5. Create Trigger in GTM to fire when selection is made
  6. Create Event Tag that passes the Data-Layer Type Variable value to GA


In the end, you will have created a new dimension that can be used in your digital analysis.  As you can see, there are a few steps to completing this and coding is not just left to implementing the GTM tag.  The use of the Data Layer is required.  That said, if your development team can get used to passing data to the Data Layer, that will allow Data Analysts to do the rest of the work and the GTM allows for all the website tags to be centrally located, instead of littered throughout your website.  

To view or add a comment, sign in

More articles by Daran Johnson

  • Time Series ARIMA Models

    The acronym ARIMA stands for auto-regressive (AR) integrated (I) moving-average (MA). ARIMA models can be broken down…

  • Replacing Excel With R

    Excel is great for spreadsheet use. I can remember taking accounting in college, when I was not aware of Excel (before…

  • Calculating Correlation of Data Attributes

    In optimizing email campaigns, it is best to segment your email list into smaller lists, based on the attributes of the…

    2 Comments
  • USING ONE-WAY ANOVA FOR EMAIL LIST SEGMENTATION

    A one-way ANOVA is used to test a null hypothesis by comparing three or more sample groups from a population (a t-test…

  • Steps for Social Media Success

    The first step in using social media channels successfully is to understand what you will be using them for. Is it for…

  • Strategies For Measuring Digital Branding Campaigns

    Digital branding campaigns are campaigns designed to boost positive awareness and recall of your brand. They are not…

  • 5 Tools Guaranteed to Boost Your Digital Marketing

    There are a lot of great tools out there to help you with digital marketing. Some help you update and upload new pages…

    1 Comment
  • Channel Attribution - Give Credit Where Credit is Due!

    Most analytics tools give credit to the last traffic channel (banner, search, etc.) through which a visitor arrived at…

  • Do You Know Your Data?

    Data-driven decision making is one of the most important factors in having a successful online presence, regardless of…

  • 6 Things You Must Do To Succeed in Digital Marketing

    There are so many things that need to be done when running an organization’s digital marketing. There are new…

Explore content categories