Visitor Tracking with magento based website

Visitor tracking and URL Tracking for visitor is an important aspect of any website through which we can keep track on our visitors . I have come through enormous request when client want to know what are the URLs on which customers are coming more often. Although visitor tracking can be very easily done through Google Analytics itself that is free as well. But if you are looking it into magento then magneto already store these kind of information for you.

Below are the few important code snippet that will help you in keep track of your visitor information.

// user’s ip address (visitor’s ip address)

$remoteAddr = Mage::helper('core/http')->getRemoteAddr(true);

// server’s ip address (where the current script is)

$serverAddr = Mage::helper('core/http')->getServerAddr(true);

The following code fetches the vistor data:-

$visitorData = Mage::getSingleton('core/session')->getVisitorData();

// printing visitor information data

echo "<pre>"; print_r($visitorData); echo "</pre>";

Array
(
[] =>
[server_addr] => 2130706433
[remote_addr] => 2130706433
[http_secure] =>
[http_host] => 127.0.0.1
[http_user_agent] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0
[http_accept_language] => en-US,en;q=0.5
[http_accept_charset] =>
[request_uri] => /magento2/
[session_id] => cuh9d2s54gqerqqa08go9tfng7
[http_referer] =>
[first_visit_at] => 2013-02-20 12:44:24
[is_new_visitor] =>
[last_visit_at] => 2013-02-20 12:44:25
[visitor_id] => 11
[last_url_id] => 211
)

You can see here server_addr and remote_addr is not directly the IP address. You can get actual IP address by using ip2long PHP function .

 

These visitor relate information stored into following tables of magento
`log_url_info`
`log_visitor_info`
`log_visitor`

Related posts:

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)