Sunday, May 8

How to Track Visitor´s Information in Magento

now we will see how to track the visitors information in magento. visitors in formations means we can track visitors ip address,browser, visit time and visitor id, etc.

The following scriptfetches the vistor data

$visitorData = Mage::getSingleton('core/session')->getVisitorData();
 
// printing visitor information data
echo "
"; print_r($visitorData); echo "
";

now we will get an array of visitor information data

Array
(
[] =>
[server_addr] => 154784124
[remote_addr] => 258974125
[http_secure] =>
[http_host] => 127.0.0.1
[http_user_agent] => Mozilla/4.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
[http_accept_language] => en-US,en;q=0.8
[http_accept_charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
[request_uri] => /magentotalks/index.php/contacts/
[session_id] => 13qm5u80238vb15lupqcac97r5
[http_referer] => http://127.0.0.1/magentotalks/
[first_visit_at] => 2011-06-14 10:12:03
[is_new_visitor] =>
[last_visit_at] => 2011-06-17 11:54:18
[visitor_id] => 51
[last_url_id] => 149
)

In the above array, the server_addr and remote_addr are in different form than usual. The (IPv4) Internet Protocol dotted address has been converted into a proper address using ip2long PHP function. You can get the same kind of value from the following code:-

// 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);
 
Ref : http://blog.chapagain.com.np/magento-track-visitors-information/ 

No comments:

Post a Comment