Skip to content

Commit

Permalink
Allow access to the current tracker visitor or session id
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Jun 20, 2019
1 parent 3dcea81 commit 00680fc
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/module-elasticsuite-tracker/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,29 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
private $sessionManager;

/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/
private $cookieManager;

/**
* PHP Constructor
*
* @param \Magento\Framework\App\Helper\Context $context The current context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager The Store Manager
* @param \Magento\Framework\Session\SessionManagerInterface $sessionManager Session Manager
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager Cookie manager
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Session\SessionManagerInterface $sessionManager
\Magento\Framework\Session\SessionManagerInterface $sessionManager,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->storeManager = $storeManager;
$this->sessionManager = $sessionManager;
$this->cookieManager = $cookieManager;
parent::__construct($context);
}

Expand Down Expand Up @@ -168,4 +176,40 @@ public function getRetentionDelay()
{
return (int) $this->scopeConfig->getValue(self::CONFIG_RETENTION_DELAY_XPATH);
}

/**
* Return the current tracker visitor id
*
* @return null|string
*/
public function getCurrentVisitorId()
{
$visitorId = null;

$cookieConfig = $this->getCookieConfig();
if (array_key_exists('visitor_cookie_name', $cookieConfig)) {
$visitorCookieName = $cookieConfig['visitor_cookie_name'];
$visitorId = $this->cookieManager->getCookie($visitorCookieName);
}

return $visitorId;
}

/**
* Return the current tracker session id
*
* @return null|string
*/
public function getCurrentSessionId()
{
$visitorId = null;

$cookieConfig = $this->getCookieConfig();
if (array_key_exists('visit_cookie_name', $cookieConfig)) {
$sessionCookieName = $cookieConfig['visit_cookie_name'];
$visitorId = $this->cookieManager->getCookie($sessionCookieName);
}

return $visitorId;
}
}

0 comments on commit 00680fc

Please sign in to comment.