diff --git a/MeasurementProtocol.php b/MeasurementProtocol.php index 57d8143..9d5e140 100644 --- a/MeasurementProtocol.php +++ b/MeasurementProtocol.php @@ -29,7 +29,7 @@ class MeasurementProtocol extends BaseObject /** @var bool Use asynchronous requests (not waiting for a response) */ public $asyncMode = false; - /** @var bool Try to set ClientId automatically from `ga_` cookie */ + /** @var bool Try to set ClientId automatically from `_ga` cookie */ public $autoSetClientId = false; /** @@ -65,9 +65,9 @@ public function request() */ protected function extractClientIdFromCookie() { - $cookie = \Yii::$app->request->cookies->getValue('ga_', ''); + $cookie = \Yii::$app->request->cookies->getValue('_ga', ''); $cookieParts = explode('.', $cookie); $clientIdParts = array_slice($cookieParts, -2); return implode('.', $clientIdParts); } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 71ab732..838bbf5 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Versions in 1.* range are incompatible with PHP 7.2, use 2.* with Yii 2.0.13+ in 'overrideIp' => false, // By default, IP is overridden by the user’s one, but you can disable this 'anonymizeIp' => true, // If you want to anonymize the sender’s IP address 'asyncMode' => true, // Enables the asynchronous mode (see below) - 'autoSetClientId' => true, // Try to set ClientId automatically from the “ga_” cookie (disabled by default) + 'autoSetClientId' => true, // Try to set ClientId automatically from the “_ga” cookie (disabled by default) ], ], ``` @@ -146,3 +146,16 @@ before sending the hit: ->setAsyncRequest(true) ->sendPageview(); ``` + +Auto set clientId from cookie +----------------------------- +If you set `autoSetClientId` to `true` durning component configuration you must disable `enableCookieValidation`. +You can do this by configuring `request` component. Otherwise, the auto set clientId will not work. + +```php +'components' => [ + 'request' => [ + 'enableCookieValidation' => false, + ], +] +```