Override User Agent in Google Analytics (analytics.js)

Bronze Contributor
Bronze Contributor

Hi there,

I try to map my own user agent parameter to the Google Analytics tag (analytics.js). But I cannot get it to include the ua parameter in the request.

The Measurement Protocol states "ua" = override user agent, so it should be available at least.
The toolbox of analytics.js doesn't provide it as a dedicated selection. And simply map it to "ua" doesn't work.
I also tried the set command with different names (ua, useragent, userAgent). Since the referrer has to be setup as "set.referrer" although the Measurement Protocol parameter is named "dr".

Does someone have success with it or knows what I am doing wrong?
It try to avoid editing the template by any means.

Thank you!


Override User Agent in Google Analytics (analytics.js)

Gold Contributor
Gold Contributor

Hi Martin

You should be able to make the overide directly in Chrome.

1. Open DevTools
2. Next to the "Elements" tab in DevTools, toggle on the Device Toolbar (it will turn blue when selected and likely resize the page)
3. At the top of the page, you should see "Default" with a drop down arrow, select the dropdown and "Edit"
4. Select "Add Custom Device"

    a. Add a Device Name - "MyUserDevice"
    b. Add a Custom User Agent String
    c. Select "Add"

5. Return to the dropdown at the top of the page and select the device you just added.

This should insert the new user agent string, until you set it back or change it to something else.



UPDATE: Sorry, I missread the issue.  When I inspect the GA call I don't see my variable in the request although I do see it in the "Inspect Headers" section when inspecting the call.

Kevin Allen SAS-DCX-UXD
User Experience & Data Analytics
DevOps Engineer III
Swisscom (Schweiz) AG

Override User Agent in Google Analytics (analytics.js)

Bronze Contributor
Bronze Contributor

Hi @kevin_allen,

Thank you for your thoughts. Unfortunately that is not what I meant.
I don't want to test fire requests with my spoofed user agent sting.
I want to permanently map a custom data layer parameter to the GA tag as a user agent. In some cases I want to slightly change the default value from navigator.userAgent and sent the updated string instead.
So this should affect a worldwide customer basis requests and not only my test cases.


Override User Agent in Google Analytics (analytics.js)

Tealium Expert
Tealium Expert
Firstly you need to decalre the variable, which i am pretty sure you have.

It does seem to be possible according to the docs in GA
It appears from here you can, ua=xxxxx but i don't see it as an option in the Tealium setup to override, your best bet would be to modify the template.

You could create a custom dimension for your own User Agent and then use that in a View when doing your analytics via the filters?

And one last radical change i think you can do IF you have eventstream, you can actually determine what passes through to GA and select Useragent along with other custom/standard dimensions.
Damian Savvides