Skip to content

Commit

Permalink
Change cookie name to _ga
Browse files Browse the repository at this point in the history
  • Loading branch information
morawskim committed Mar 2, 2019
1 parent 0d25899 commit c7aa81b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions MeasurementProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
}
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
],
],
```
Expand Down Expand Up @@ -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,
],
]
```

0 comments on commit c7aa81b

Please sign in to comment.