How to Track Visitor’s Data on Magento?

Magento is one of the most powerful open source e-commerce platform based on PHP. One of its powerful features is user activity logging system. By using user’s data we can analyze the customers/visitors behaviour which ultimately helps in business. For example, if we know that the customers are frequently visiting a particular section of a category then you can run the campaign to increase the conversion rate in terms of an order placed on your Magento store.

Magento has a dedicated module Mage_Log to store the log of the customer/visitor.

It mainly stores the following data

1.Customers who logged in
2.Current Visitors
3.Past Visitors
4.Details like IP, First visit, Last visit etc

Two main tables in which data is stored are


Every time a user visits the store the Magento generates a visitor_id and store it in a log_visitor table. When a registered customer visits the store using their credentials then a log_customer table is updated.

One can enable or disable logging option from Magento admin panel. Steps to do so are

Go to

System -> Configuration -> System -> Log

Magento Admin Panel

Magento System

Magento Configuration

We can get visitor’s data using the following code

$visitor_data = Mage::getSingleton(‘core/session’)->getVisitorData();

Here $visitor_data will return an array of the customer/visitor information which is stored in the session

[] =>
[server_addr] => 197777237
[remote_addr] => 197777237
[http_secure] =>
[http_host] =>
[http_user_agent] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
[http_accept_language] => en-US,en;q=0.9
[http_accept_charset] =>
[request_uri] => /test
[session_id] => njt3e2cc4g5c85o8gccnjs1ep3
[http_referer] =>
[first_visit_at] => 2018-11-22 14:42:15
[is_new_visitor] =>
[last_visit_at] => 2018-11-22 14:42:20
[visitor_id] => 19

If you need some specific data like the first visitor last visit time then you can use its model too

echo $firstVisitAt = Mage::getModel('log/visitor')->getFirstVisitAt();
echo $lastVisitAt = Mage::getModel('log/visitor')->getLastVisitAt();

Hope this will help you in tracking visitor’s data on your Magento store. Happy Coding:)

Prashant Kumar

Prashant Kumar

Prashant is a passionate Magento developer. He loves exploring e-commerce and reading books.

Leave a Reply

Your email address will not be published. Required fields are marked *