theiconic / php-ga-measurement-protocol

Send data to Google Analytics from the server using PHP. Implements GA measurement protocol.
MIT License
655 stars 135 forks source link

setUserAgentOverride() seems doesnt actually overrides a User_Agent #48

Open ashkart opened 7 years ago

ashkart commented 7 years ago

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'],
        ]);
jorgeborges commented 7 years ago

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

ashkart commented 7 years ago

@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.

jorgeborges commented 7 years ago

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