Set up Custom Dimensions using GA, GTM, and the Data Layer

Comments:13

  1. I followed your guide to set-up a pages topic – with the topic itself being auto-generated in the datalayer based upon the category selected when creating the WordPress page/post.

    However when I view the secondary dimension within Google Analytics the homepage (and other pages) seems to be picking up sessions against multiple topics which is incorrect as core can only be selected for it (and is confirmed in the HTML).

    Any idea what’s going on?

    Thanks,

    Sam

    1. Hi Sam, is your dimension in GA set to hit-scoped? Session and user-scoped dimensions will take on the final value in a session so could lead to some unexpected results. If that’s not the issue and you’d like me to take a closer look, please email me your URL, a screenshot of your tag setup, and your custom dimension page in GA.

    1. You don’t need a data layer at all for custom dimensions, it’s an optional but (usually) recommended step. If you don’t have or don’t want to use a data layer, you can instead capture values by scraping them off the page. For example, say you want to pass in a custom dimension for login status. You might find that you can identify whether a user is logged in or out by checking the navigation bar, as they have different menu options (For example, the ‘logged out’ menu has an option to sign in, while the ‘logged in’ menu has an option to check your account). In that case you would alter the above steps as follows:
      1) skip step 1 entirely
      2) complete step 2 as written
      3) instead of setting up a Data Layer variable, set up a Custom Javascript variable, and write a function that returns ‘logged in’ or ‘logged out’ based on which version of the menu bar is visible (or whatever other way you’ve found to identify login status).
      4) complete step 4 as written
      5) since you no longer have a data layer event, you’ll need to instead use the built-in triggers like DOM Ready or Window Loaded to make sure your new JS Variable is resolved and available at the time you send it over to GA.

  2. Hi Ana! Thanks a lot for the detailed step-by-step explanation. I’m stuck at step 5 as I’m not sure what my best option is. I already have a GA page view tag that fires with the trigger type page view (but also the trigger type history change because of the way the website is coded). I’m worried that adding the custom event trigger might:
    – not count all page views since we’re waiting for the datalayer push to be completed
    – not mix well with the history change trigger
    To mitigate this issue, I was thinking of creating a separate GA page view tag just for the custom dimensions but then I guess GA will be counting the page views twice?
    Thanks a ton for your feedback!

    1. Hi Solal, the reason I suggest doing it with an event instead of pageview trigger is exactly to avoid the kind of issues you’re mentioning. It won’t affect your pageviews or history change trigger since it’s a totally different tag & trigger, whereas if you create a new page view tag, you’ll be double-counting page views unless you set up blocking triggers to avoid that. I usually just recommend sending this data in a pageview for sites that need to reduce their hit counts (due to GA’s 10 million hits / month limit). If you’re not in that category, I’d stick to the event method described in this post.
      Hope that helps clarify!

  3. Hi Ana, thank you for this guide! If my page is slow to load and the user exits before it is loaded correctly (due to heavy adv or other causes), with the trigger that you suggest the risk that the pageview is not counted in Google Analytics?

    1. There’s a small risk with any tag that the user will navigate away before the page loads (or a larger risk that the user will block the tag altogether with a script blocker). This setup isn’t inherently slow, though, and in fact it could be faster if you push the ‘pageview’ event before GTM’s built in ‘Page View’ trigger fires. The difference is unlikely to be noticeable either way, though.

Leave a Reply

Your email address will not be published.