Report Multiple Categories with Custom Metrics in Google Analytics

/

ga-custom-metrics-reports
In an earlier blog post I covered how to report multiple categories with a custom dimension in Google Analytics – you string together all of your categories in a single value, and then separate them using GA dashboards, Google sheets, or Excel.

You should stick with the custom dimension solution if you have more than 20 categories. This is especially true if the number of categories is unknown (in the case where new ones may appear at any time).

If you have fewer than 20 categories and you know exactly what they are, there’s another option: custom metrics!

Let’s say you have a Request Info form where prospective students can indicate their interest in one or more programs. You want to count the number of times each program is selected, but you only want to track one form submission no matter how many programs a student is interested in.

As long as you don’t have too many choices on the form, custom metrics are a good solution. With custom metrics, you can create an amazing report like the one below.

Custom metrics in a custom report in Google Analytics

You can set up this custom report in Google Analytics and see which campaigns are driving interest in each program on your Request Info form.

Step 1: Create a Custom Metric for Each Category

In the Admin panel in Google Analytics, go to Property Settings, Custom Definitions, Custom Metrics. Click the red button to create a new custom metric with hit scope and integer format. Enter the name of the category, e.g. “B.S. in Engineering” and then click Create and Done to save.

Repeat this process for each category. When complete, you’ll see a list of all your metrics and their index numbers.

Create custom metrics in Google Analytics

Keep the index numbers handy – you’ll need them when you add tracking code for custom metrics to your Request Info form.

Step 2: Add Tracking Code for Custom Metrics

Just like custom dimensions, custom metrics need to be set before or at the same time you send an event or pageview. Custom dimensions and metrics never get sent to GA by themselves. Instead, they need to be sent with an event or pageview hit.

In the case of a Request Info form, you’ll need to determine what boxes were checked when the form was submitted. This can be part of the form validation script. Set the custom metrics and send a Google Analytics event when the form is successfully validated.

In your form validation script, you’ll add either Universal Analytics tracking code OR data layer pushes (to be used by Google Tag Manager) to send custom metrics with events.

Universal Analytics Tracking Code – Note that you want to set all the values to 1, which will simply count every time a student indicated interest in each program. In your custom report GA will sum each custom metric for you, the same way it sums most metrics in the standard reports.

Of course, you would only set the value to 1 if the checkbox for that program was checked. Use conditions in your script. If all five programs were checked, the resulting code would look like this:

I’ve sent an event category of ‘Request Info Form’ and an event action of ‘Submit’ but you could add an event label or other parameters if you wanted them.

Data Layer Pushes for Google Tag Manager

If you’re using Google Tag Manager, then you’ll want to push info to the data layer in your script as shown below. Remember to set values to 1 only on the condition that those boxes were checked when the student submitted the form.

You can then tell Google Tag Manager to listen for the event ‘submitRFI’ and trigger your Google Analytics event tag, where you’ve added custom metrics.

Add custom metrics to GTM event tag

The value of each custom metric comes from a variable you define in Google Tag Manager to read the corresponding value from the data layer. {{dlv metric 1}} refers to the value of ‘metric1’ in your data layer push. It will be 1 or 0, depending on whether or not the student checked the box for B.S. in Engineering.

Step 3: Create a Custom Report

Custom metrics don’t appear in GA unless you create a custom report or dashboard with them. You have the same options for reporting as with custom dimensions.

To create a report like the one at the top of this post, go to the Customization tab at the top of the Google Analytics interface, between Reporting and Admin, and click the button for New Custom Report. Give your report a name (“New Custom Report” is a lame name, like “All Web Site Data” – you can do better).

Click the blue button to add metrics. Pro Tip: Use the search box, don’t scroll to find them. Add some dimensions like Campaign, Medium, Source, and Landing Page. Then save the report in the view(s) where you need it.

Create custom report with custom metrics in Google Analytics

Other Examples of Categories and Custom Metrics

It’s easy to extend the form submission example to other situations where you might track a limited number of categories with custom metrics.

  • other forms with multiple checkboxes checked, e.g. selecting one or more newsletters
  • video play events, where the video belongs to one or more categories
  • blog posts or articles that can belong to a small number of topics
  • product pages where the same item is related to more than one category

For articles and product pages, you’ll want to send your custom metrics with a pageview hit instead of an event hit. You’ll still need to set the custom metrics either in Universal Analytics tracking code or in a data layer push to be used by Google Tag Manager.

Have you used custom metrics to track multiple categories? Did you encounter any obstacles or find a novel solution? Please share in the comments.

Dorcas Alexander is a Manager for the Analytics & Insight department. Her path to LunaMetrics followed stints in ad agency creative, math, and computer science. Dorcas has a master's degree in language and information technologies from Carnegie Mellon University, where she helped build precursors to a Universal Translator. One of the top-rated tournament Scrabble players in Pennsylvania, Dorcas has an insatiable drive to compete and win.

  • Hi Dorcas,

    Multiple metrics and dimensions can be sent in datalayers/events. Can multiple values be sent in a single custom dimension? If so, how? An example of this use would be in sending multiple ecomm_prodid values for dynamic remarketing when multiple products are viewed on category pages, carts, and search results. For example (where dimension 1 is ecomm_prodid):

    ga(‘send’, ‘event’, ‘dynamic-remarketing’, ‘page view’, {
    ‘dimension1’, [‘1234’, ‘4444’, ‘5555’],
    ‘dimension2’, 14.67,
    ‘dimension3’, ‘cart’
    });

    I don’t yet know if that is valid. I’ve tested the following and AdWords reports this is not (possible though there is delayed reporting):
    ‘dimension1’, ‘1234, 4444, 5555’,

    • Dorcas Alexander

      Hi Joshua, I’m pretty sure the value of a custom dimension must be a string, not an array. So a value of [‘1234’, ‘4444’, ‘5555’] would not be processed, but a value of ‘1234, 4444, 5555’ would be processed because it is a single string. If the scope of the custom dimension is product-scoped, I don’t think GA will end up attaching the value ‘1234, 4444, 5555’ to anything unless you send it as part of a product array in an ecommerce object.

  • abhilash s t

    I am using GTM to send Pageview and using the following code to set dimensions to track categories.

    var category = ‘#Category-Name’;
    var subcategory= ‘#Sub -Category-Name’;

    ga(‘send’, ‘pageview’, { ‘dimension1’: category });
    ga(‘send’, ‘pageview’, { ‘dimension2’: subcategory });

    Will this duplicates my overall pageviews or it’ll just record a pageview to the specific dimension?
    Please help 🙂

    • Dorcas Alexander

      Hi Abhilash, If you send a pageview twice, then yes, it will duplicate your pageviews. Instead, you should add dimension2 to the list with dimension1, and send the pageview once only. As in: ga(‘send’, ‘pageview’, { ‘dimension1’: category, ‘dimension2’: subcategory });

      • abhilash s t

        Thanks Dorcas 🙂

        So if I am firing Pageview using GTM tag and also using ga(‘send’, ‘pageview’, { ‘dimension1’: category, ‘dimension2’: subcategory }); inside code will duplicate Pageview right?

        • Dorcas Alexander

          Yes, you should not do both of those at the same time or you will have duplicate pageviews. Either send the pageview+dimensions using a GTM tag, or send the pageview+dimensions using GA code placed directly on the page.

  • Eric Böhme

    Hi Dorcas,

    thank you for this article. I have a question regarding the combination of custom dimensions and custom metrics.
    Can I send multiple custom dimensions and multiple custom metrics within one event hit?

    dataLayer.push({
    ‘dimension1’: 1,
    ‘metric1’: 1,
    ‘dimension1’: 1,
    ‘metric2’: 1,

    ‘metric4’: 1,
    ‘metric5’: 1,
    ‘event’: ‘submitevent’,
    });

    • Dorcas Alexander

      Hi Eric, Yes, you can send multiple custom dimensions and custom metrics with a single hit. See my blog post on how to view this data in Google Analytics, specifically Example 2-B. You can create a custom report to show multiple custom metrics per row, and that will aggregate data for different metrics that occur on the same hits, as well as hits with the same dimensions. https://www.lunametrics.com/blog/2015/08/10/custom-dimensions-google-analytics/

Contact Us.

LunaMetrics

24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.