Embedding User Agent in Google Analytics 4 Reports

Learn how you can push user agent information to Google Analytics and Google Analytics 4 for use in reporting

Overview

Blink SEO, an Elevar partner, came to us with a request, how can we get user agent information along with other reporting in Google Analytics and Google Analytics 4?

We put our heads together and came up with the setup below, and a Google Data Studio report for analysis.


Add User Agent Into Google Tag Manager as a Data Layer Variable

Creating a User-Defined Variable:

  • Begin on the homepage of your Google Tag Manager and use the left hand menu to click on the tab titled "Variables".
    • Locate and click the box labeled "User-Defined Variables".
    • Click on the button labeled "New" in the upper right-hand corner of the box to create a new User-Defined Variable.
      • (See Figure 1)

Step 1 screenshot

Figure 1

Creating User-Defined Variable:

  • You will be brought to a new window where you can create a new User-Defined Variable.
  • Locate the box titled "Variable Configuration" and click on it.
  • A new pop-up window will appear, in which you can select the variable type.
    • Navigate to the section titled "Page Variables" and click on the tab labeled "JavaScript Variable".
      • (See Figure 2)

Step 3 screenshot

Figure 2

  • After choosing the variable type, locate the box labeled "Global Variable Name".
    • Within the text box of this section, type "window.navigator.userAgent". This will pull the value into the data layer.
    • Be sure to name this new User-Defined Variable by typing "User Agent" into the upper left-hand text box.
  • After filling in the required custom information, click on the button labeled "Save" in the upper right-hand corner of the page.
    • (See Figure 3)

Step 4 screenshot

Figure 3

Send User Agent to Google Analytics 4

Create Custom Dimension:

  • Begin on your Google Analytics 4 homepage.
    • Locate and click on the "Admin" settings or the gear icon in the lower left-hand corner of the page.
    • Using the settings menu, locate and click the tab labeled "Data Display".
    • Use the additional drop-down menu and click on the tab labeled "Custom Definitions".
  • Once in the "Custom Definitions" section of your Google Analytics 4 settings, click on the box labeled "Create custom dimension".
    • (See Figure 4)

Step 8 screenshot

Figure 4

Edit Custom Dimension:

  • After clicking on the "Create custom dimension" button, an additional pop-up window will appear titled "Edit custom dimension".
    • Locate the section titled "Dimension name" and use the text box to type "User Agent".
    • Locate the section titled "Event parameter" and use the text box to type "user_agent".
    • Locate the section titled "Scope" and use the drop-down menu to select "Event".
  • After completing the customizations for your new dimension, be sure to save your changes and click on the button labeled "Save" in the upper right-hand corner.
    • (See Figure 5)

Step 9 screenshot

Figure 5

Send Variable to Google Analytics 4

Access User Properties:

  • Begin on the homepage of your Google Tag Manager and use the left hand menu to click on the tab labeled "Tags".
  • Locate and click the Elevar prebuilt GA4 container variable titled "GA4 Base Tag Configuration".
    • Once in the GA4 Base Tag Configuration, click on the box titled "Tag Configuration".
    • Navigate to the "User Properties" section and create a new row.
      • Use the text box to type "user_agent" into the Property name section.
      • Use the text box to type "{{User Agent}}" into the Value section.
    • After editing the User Properties, be sure to save your changes by clicking on the button labeled "Save" in the upper right-hand corner of the page.
      • (See Figure 6)

Step 1 screenshot

Figure 6