If scope is 'visit', it will attempt to read the value set in the first party cookie created by Piwik Tracker
($_COOKIE array).
public getCustomVariable ( integer $id, string $scope = 'visit' ) : mixed | ||
$id | integer | Custom Variable integer index to fetch from cookie. Should be a value from 1 to 5 |
$scope | string | Custom variable scope. Possible values: visit, page, event |
return | mixed | An array with this format: array( 0 => CustomVariableName, 1 => CustomVariableValue ) or false |
/** * Test setting/getting the first party cookie via the PHP Tracking Client * @param $t */ private function testFirstPartyCookies(PiwikTracker $t) { $domainHash = $this->getFirstPartyCookieDomainHash(); $idCookieName = '_pk_id_1_' . $domainHash; $refCookieName = '_pk_ref_1_' . $domainHash; $customVarCookieName = '_pk_cvar_1_' . $domainHash; $viewts = '1302307497'; $uuid = 'ca0afe7b6b692ff5'; $_COOKIE[$idCookieName] = $uuid . '.1302307497.1.' . $viewts . '.1302307497'; $_COOKIE[$refCookieName] = '["YEAH","RIGHT!",1302307497,"http://referrer.example.org/page/sub?query=test&test2=test3"]'; $_COOKIE[$customVarCookieName] = '{"1":["VAR 1 set, var 2 not set","yes"],"3":["var 3 set","yes!!!!"]}'; // test loading 'id' cookie self::assertContains("_viewts=" . $viewts, $t->getUrlTrackPageView()); self::assertEquals($uuid, $t->getVisitorId()); self::assertEquals($t->getAttributionInfo(), $_COOKIE[$refCookieName]); self::assertEquals(array("VAR 1 set, var 2 not set", "yes"), $t->getCustomVariable(1)); self::assertFalse($t->getCustomVariable(2)); self::assertEquals(array("var 3 set", "yes!!!!"), $t->getCustomVariable(3)); self::assertFalse($t->getCustomVariable(4)); self::assertFalse($t->getCustomVariable(5)); self::assertFalse($t->getCustomVariable(6)); self::assertFalse($t->getCustomVariable(-1)); unset($_COOKIE[$idCookieName]); unset($_COOKIE[$refCookieName]); unset($_COOKIE[$customVarCookieName]); }