How can you push user agent information to Google Analytics and Google Analytics 4 for use in reporting?
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.
- Create a variable in Google Tag Manager that captures the User Agent. This can be done by going to 'Variables' section on the left side and clicking 'New'.
- Fill the 'Global Variable Name' field with window.navigator.userAgent and press save. This will pull the value into the data layer.
Now that you have user agent in the data layer you can choose to send it to Google Analytics, Google Analytics 4 or both.
Google Analytics 4 works slightly differently than Google Analytics.
- First we'll need to create the dimension in the Google Analytics 4 interface. Go to Google Analytics 4 and click Configure, then Custom Definition then 'Create Custom Dimensions'.
- Fill out the indicated fields shown below and click save.
- To send this variable to Google Analytics 4 you'll need to open your Google Analytics 4 Configuration variable. This should be referenced in all of your Google Analytics 4 event tags. In the Elevar prebuilt GA4 container this variable will be called GA4 Base Tag Configuration. Under 'User Properties' add a new row with property name set to user_agent and value set to variable 'User Agent', make sure to include the brackets.
- You'll now be sending the dimension to GA4 on every tag hit
Updated 1 day ago