Pourquoi tu ne fais pas : 
if ($e->getRequest()->getCookie() && $e->getRequest()->getCookie()->offsetExists('pg_anonymous')) {
    $anonymousId = $e->getRequest()->getCookie()->offsetGet('pg_anonymous');
} else {
     $anonymousId = uniqid('pg_', true);
}