[UA] Content Groups with gtag.js [Legacy]

You are viewing a legacy article about Universal Analytics. Learn more about Google Analytics 4 replacing Universal Analytics.
You must have the Editor role for the view in which you want to create a Content Group.
In this article:

 

Overview

You first create a top-level Content Grouping, and then within that, create individual Content Groups by one of the following methods:

  • Modify gtag.js on each page you want to group
  • Extract pages with regex capture groups
  • Create rules to include pages in a group

Analytics processes gtag.js first, then the regex, and then the rules. As soon as it finds a match, the processing ends, and your content is grouped according to that first match.

Say, for example, that you have a site that sells clothing for men and women, and your general categories of clothing are:

  • Men
    • Shirts
    • Pants
    • Accessories
  • Women
    • Tops
    • Slacks
    • Skirts & Dresses
    • Accessories

Given those product lines, you may want to conduct the following types of analysis:

  • Compare overall sales between Men and Women
  • Compare sales among the product lines within Men and Women

Given the kind of analysis you want to conduct, you could create the following Content Groupings, and within those, the following groups:

Compare Men and Women:

  • Content Grouping: Clothing
  • Content Groups: Men and Women

Compare product lines within Men:

  • Content Grouping: Men
  • Content Groups: Shirts, Pants, Accessories

Compare product lines within Women:

  • Content Grouping: Women
  • Content Groups: Tops, Slacks, Skirts & Dresses, Accessories

With the configuration above:

  • Clothing, Men, and Women are options in the Primary Dimension > Content Grouping menu.
  • When you select Clothing as the primary dimension, Men and Women are the dimension values in the first column of the report table.
  • When you select Men as the primary dimension, Shirts, Pants, and Accessories are the dimension values in the first column of the table.
  • When you select Women as the primary dimension, Tops, Slacks, Skirts & Dresses, and Accessories are the dimension values in the first column of the table

For each dimension value (Content Group), you see behavioral metrics like Pageviews and Bounce Rate.

When you drill into a Content Group, you see behavioral metrics for each page in that group.

Create a Content Grouping

  1. Sign in to your Analytics account.
  2. Click Admin, and navigate to the view you want.
  3. In the VIEW column, click Content Grouping.
  4. Click Create New Content Grouping.
  5. Enter a name for the new grouping.
  6. Select the methods you want to use (measurement code, extraction, or rules) to create Content Groups.
     

Create a Content Group via gtag.js

  1. Under GROUP BY tracking code, click Enable tracking code.
  2. Make sure the Enable option is set to On.
  3. Select an index number (1-5) to identify your Content Grouping.
  4. Click Done.

When you modify gtag.js, you use an index number (1-5) to identify the Content Grouping, and you use a group name to identify your Content Group:

gtag('config', 'GA_MEASUREMENT_ID', {
  'content_group<Index Number>': '<Group Name>'
}

For example, if you’re configuring a Content Grouping for Clothing identified by the Index Number 1, and within that creating a Content Group called shoes, you would update your config to have the following:

gtag('config', 'GA_MEASUREMENT_ID', {
  'content_group1': 'shoes'
}

For each content_group call, you can identify only one Index Number - Group Name pair.

Once you have updated your pages with gtag.js, those pages are then grouped according to how you identified them by index number and group name.

If you call the same index number multiple times on the same page, then only the last call for that index number is sent to Analytics.

To learn more about how to use gtag.js, read the developer documentation.

Assign content via extraction

You can extract pages by Page URL, Page Title, or Screen Name. Identify each one with a regex capture group (Analytics uses the first capture group for each expression).

Click Add extraction, then select either Page URL, Page Title, or Screen Name.

In the field to the right, enter the value you want to match. For example:

  • Page > /Men/(.*)/
    • Creates a Content Group for each subdirectory of /Men/, and adds the pages in each subdirectory to the corresponding Content Group
  • Page Title > (.*shirts).*
    • Creates Content Groups for pages that contain the word shirts

      For example, if your site has the following directories with shirts pages:
      • /men/m_dress_shirts.html
      • /men/m_tshirts.html
      • /boys/b_dress_shirts.html
      • /boys/b_tshirts.htm.

      Then you would have the following Content Groups and pages within those:
      • men (m_dress_shirts.html, m_tshirts.html)
      • boys (b_dress_shirts.html, b_tshirts.html)
  • Screen Name > (.*pants).*
    • Creates Content Groups for screen names that contain the word pants

When you have configured the extraction, click Done.

See more examples of using regex capture groups to extract content.

Assign content via a rule set

If you use this option, you create rules to assign content.

To open the rules editor, click Create a rule set.

For each rule:

  1. Enter the name you want to use for the Content Group.
  2. Under Define rules, select either Page URL, Page Title, or Screen Name.
  3. Select a matching option and enter a value to match. For example:
    • Page > contains > /Pants/
      • Adds all pages that have /Pants/ in the URL to the Content Group
  4. Click OR or AND to add an OR or AND condition to the rule. Follow the instructions above to define the additional condition.
  5. When you have defined all the conditions you want to use, click Done.
  6. After you finish all your configuration for the group, click Save.

Naming: case sensitivity and effects on historical data

Case sensitivity

Content Group names are not case sensitive. For example, if your rule defines a content group as:

Page exactly matches /Google+Redesign/Apparel

then that rule will match any form of that page name. For example:

  • /Google+Redesign/Apparel
  • /Google+Redesign/apparel

Effects on historical data

If you change the name of a Content Grouping, there is no effect on historical data: all data will immediately appear under the new name of the Content Grouping.

If you change the name of the rule that defines a Content Group, then data from that point forward appears under the new Content-Group name, and data from before the name change appears under the old name.

Content Grouping name, Content Group rule name.

Was this helpful?

How can we improve it?
true
Choose your own learning path

Check out google.com/analytics/learn, a new resource to help you get the most out of Google Analytics 4. The new website includes videos, articles, and guided flows, and provides links to the Google Analytics Discord, Blog, YouTube channel, and GitHub repository.

Start learning today!

Search
Clear search
Close search
Google apps
Main menu
15348936727710852302
true
Search Help Center
true
true
true
true
true
69256
true
false