php-ga-measurement-protocol icon indicating copy to clipboard operation
php-ga-measurement-protocol copied to clipboard

setUserAgentOverride() seems doesnt actually overrides a User_Agent

Open ashkart opened this issue 7 years ago • 3 comments

user agent is always value of const PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT, which isnt informative for any analytics at all.

Its hardcoded in HttpClient class with no chanse to actually override without of library code changing:

$request = new Request(
            'GET',
            $url,
            ['User-Agent' => self::PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT]
        );

        $opts = $this->parseOptions($options);
        $response = $this->getClient()->sendAsync($request, [
            'synchronous' => !$opts['async'],
            'timeout' => $opts['timeout'],
            'connect_timeout' => $opts['timeout'],
        ]);

ashkart avatar Jun 13 '17 12:06 ashkart

@ashkart You can just call setUserAgentOverride method on the Analytics object.

jorgeborges avatar Jun 15 '17 23:06 jorgeborges

@jorgeborges, thats what i talking about - it seems dat setter doesnt affect on its target parameter in analytics. Even i set any value with setUserAgentOverride(), i always get 'THE ICONIC GA Measurement Protocol PHP Client (https://github.com/theiconic/php-ga-measurement-protocol)' in my analytics reports in "Browser" metric.

The reason may be google prefers to use header "User-Agent" value.

ashkart avatar Jun 16 '17 17:06 ashkart

This is the way Google provides to override the User-Agent. Other users reported this before and they used it successfully. See here: https://github.com/theiconic/php-ga-measurement-protocol/issues/4

$analytics->setUserAgentOverride('My Custom User-Agent');

More info from the official docs in: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ua

jorgeborges avatar Jun 17 '17 04:06 jorgeborges