Ok. So try this. But this wont save your data in customer_visitor
table at least not the fields i added.
public function initByRequest($observer) //Magento\Customer\Model\Visitor - PATH
{
if ($this->skipRequestLogging || $this->isModuleIgnored($observer)) {
return $this;
}
if ($this->session->getVisitorData()) {
$this->setData($this->session->getVisitorData());
}
$this->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
$this->setHttpUserAgent($_SERVER['HTTP_USER_AGENT']); // setting user browser to object
$this->setUserRemoteAddr($_SERVER['REMOTE_ADDR']); //setting user ip to object
if (!$this->getId()) {
$this->setSessionId($this->session->getSessionId());
$this->save();
$this->_eventManager->dispatch('visitor_init', ['visitor' => $this]);
$this->session->setVisitorData($this->getData());
}
return $this;
}
Now remove your cookies from browser and try to get the value like this
$this->session->getVisitorData(); // Or where you want to get the data by initializing session object and get it.
Now you will get something like this Array ( [last_visit_at] =>
2017-04-06 07:35:44 [http_user_agent] => Mozilla/5.0 (Windows NT 6.1;
WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133
Safari/537.36 [user_remote_addr] => 127.0.0.1 [session_id] =>
9c2uc36v01is5mn30q890o1ih2 [visitor_id] => 22 )
customer_visitor
table in admin panel. But it doesnt have all the data you want. That you need to code differently.getVisitorData()
to get Data from session object. Check what you can get. If not... try to get data from request header likehttp_user_agent
to get the browser,remote_addr
to get the IP address etc etc.Magento\Customer\Model\Visitor
is the class where Magento is setting visitors information by usingsetVisitorData
insideinitByRequest()
function.