2

I was curious how many of my visitors were using the Tor browser and wrote a script to detect it. Since that browser sets the user agent as Windows/Firefox, it means the data (however small) in Google Analytics is incorrect.

Is it possible to override the Browser name (and OS name) in Google Analytics? Perhaps by sending a custom string as user agent?

I've used the measurement protocol before which is the only way I could think to do this, but it would conflict once the JS tracker sent data via the pageview. I wouldn't want to forego the analytics.js JavaScript library just to override a single dimension.

I do have custom tasks written and thought maybe I could override the data there, but I haven't been able to find what field I would use in the model object (or the tracker object for that matter).

If I really was adamant about this I know I could just use a custom dimension, but again this was just a curiosity and not something I would want to devote an entire custom dimension to- especially since I'm sure the actual usage on my website is <1%.

  • 1
    I'm not sure how they parse the user-agent. It appears JavaScript can't set it in any case: stackoverflow.com/questions/18960908/… Not sure if there is a way to pass something other the the user-agent through to GA. – Stephen Ostermiller Jun 22 '17 at 9:23
  • My detection is actually done on the server side and passed to JavaScript, so that could be a viable option for me to actually change the user agent itself before GA is even invoked. Didn't think about that- thanks for the idea. – GreatBlakes Jun 22 '17 at 13:10
  • 1
    I don't think you can set the user agent that Google Analytics sees from server side either. Google Analytics runs in client side JavaScript code. The user agent that JavaScript sees is controlled by the browser. If you find a way to pass it to GA, it will have to involve some sort of JavaScript, even if that is just passing your server side value to GA through JavaScript written into the page. – Stephen Ostermiller Jun 22 '17 at 13:13
  • Ah, yeah that makes sense. – GreatBlakes Jun 22 '17 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.