2

Google analytics beginner here.

I'm developing a new way to capture custom dimensions for my team's site, and I want to know if there's anything that looks wrong with my setup.

In Google Tag Manager, I have two Google Analytic Tags

  • Custom HTML with a Google Analytic HTML+JavaScript code. Triggered by "All pages" (page view).
  • Universal Analytics Tag. It's linked to a Google Analytics variable which contains the UA and some custom dimensions. I created this new tag because I can't use dataLayer with the Custom HTML tag that was already added. The tracking type is event, and I want to know if I have to change it to page view. Also the trigger is a custom event that I trigger from the page with Javascript using dataLayer.

I'm concerned about a few things.

  • Is the tracking type correct as event for the second tag?
  • Will having two tags somehow mess up my data?
  • Will having two tags make the custom dimensions data be stored separately? I want somehow to store the custom dimensions as if they were associated with the page view (although this way of thinking might not make sense, I'm not sure, after all I can create reports and they represent the views statistics).

I'm using this code in the HTML page.

var dataLayer = window.dataLayer || [];
dataLayer.push({
  "event": "details-analytics",    
  ga_author_id: 4858,
  ga_profile_type: 2,
  ga_post_id: 830906
});

I already verified that the second tag isn't triggering additional pageviews, as they are counted as 1 in the real time widget.

To summarize, I'd have preferred that the first tag was a Universal Analytics tag that could be configured with custom dimensions, so I could use the same tag for both page views and adding custom dimensions only for the page I need them to have them. But since it was a custom HTML tag I decided to add a new one. Is my setup of 2 tags equivalent to having 1 as I just described? or is there something that would be a bit off?

There are many things I don't understand about Google Analytics and I prefer to get a quick opinion rather than learn by myself (I don't have time at all).

  • In the custom html tag, is it just the analytics tracking code snippet? Seems a little odd that the tracking would be in a custom html tag rather than having used a native GTM GA tag – Bronwyn V Oct 4 at 7:56
3

When Google Tag Manager is installed on a site (a script tag beginning function(w,d,s,l,i) and ending with your GTM container ID), it is not necessary to separately add Google Analytics tracking code to the site. If the Custom HTML tag you describe is only sending pageview hits to GA, you can replace it with a Universal Analytics tag of type Pageview, with your GA Property ID as the tracking ID (the ID starting UA-). Set All Pages as the trigger, and GTM will take care of any needed GA code automatically.

I would recommend making that change if the first tag is really only for pageview purposes, because as you want to add more kinds of tracking it will be more efficient to use GTM's automatic inclusion of the code - rather than reimplementing a non-GTM installation via Custom HTML, or having GA code load twice on the pages. You're correct that with your current setup, your custom data is not truly connected to the pageviews, but also that for practical purposes it might not matter too much.

If you change to the Pageview tag setup, and your dataLayer push code is in the HTML on page load (not added by JS afterward), you can connect your additional data to the pageview hit. You won't need the event part of the dataLayer push or your event tag (aside: if you were keeping the other tag as Custom HTML, "event" was the right choice for your additional data, I think).

There are a few additional pieces, however, which you may have some of already.

  1. GTM dataLayer variables for each additional dimension: click "Variables" in the GTM sidebar and then "new" beside "user-defined variables" in the lower section. Set the variable type to Data Layer Variable and the name to one of your object keys. Give the variable itself a name that corresponds, like GA Author ID; that is how you'll pull it into the tag to send to GA.

Screenshot of GTM dataLayer variable definition screen

  1. Custom dimensions in GA for each of your additional data points: in GA, go to Admin > Property > Custom Definitions > Custom Dimensions. Click "new custom dimension", give it a human-friendly name like "Author ID", keep the scope at "hit", and save. Note what index number each dimension is assigned - the dataLayer names live only in GTM and the human-friendly names live only in GA; the number is how they are connected.

  2. Back in GTM, in your Pageview tag, enable overriding settings and open the More Settings accordion and then the Custom Dimensions accordion. For each dimension, enter the GA index in the left column and the GTM variable name in double curly braces (e.g. {{GA Author ID}}) in the right column.

Screenshot of sending a custom dimension to GA from GTM

  1. In GA, to see one additional dimension along with Page, you can add it as a Secondary Dimension to Behavior > Site Content > All Pages or other reports. To see all of your custom dimensions along with Page, you'll need to go to Customization > Custom Report and create a custom report of type Flat Table, which is the only reporting option if you want columns for more than two dimensions. In either place your custom dimensions will show up under the human-friendly names you chose in step 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.