php-ga-measurement-protocol
php-ga-measurement-protocol copied to clipboard
User agent
We use this lib and have founded some interesting thing:
As you see, Google Analitycs sees Guzzle like a browser. And this fact breaks our statistics.
We talked with google analytics evangelist and he said that it is likely because of user agent parameter in http request.
Alternatively we can send ni=1 parameter in request https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ni But what if hit is interaction, but we dont't want see guzzle in statictics.
Maybe it better not to send user agent info or do some bool flag (to send or not to send user agent)? What do you think?
P.S. It's a bad thing because it ruins statistics not only for browsers but also in different reports like for example visits of the landing pages and so on.
Hello @ansiv
I think this is normal behaviour and boolean parameter not needed. By default Guzzle sending own user agent. This is normal for Guzzle and this is normal for client, because it uses guzzle. However you can extend client by symfony events. Check an example:
$client->getEventDispatcher()->addListener('command.before_prepare', function (\Guzzle\Common\Event $e) use($config) {
if (false === $e['command']->hasKey('ua')) {
$e['command']->set('ua', $_SERVER['HTTP_USER_AGENT']);
}
});
Add this code to client initialization step and it will set ua
param to actual user agent value and GA reports will be ok.
Thanks a lot. I added this thing in code. We will look into the dynamics of our reports :)