search
top

Online Visitors Magneto

You might have seen in Magento we have a section for seeing the online visitors at a given time.

I am describing here the method for getting the number of online visitors, for reference see the my webstore Decrypt Web Store, I am showing the online visitors in the left column.

<?php
//this code can be written directly in the template file
            $visitor_count = Mage::getModel('log/visitor_online')
            ->prepare()
            ->getCollection()->count();

        if(!empty($visitor_count) && $visitor_count > 0)
        {
        	$cnt =  $visitor_count;
                echo 'Visitors online :'.$cnt;
        }
?>

Here is another way for doing this

<?php
//this code can be written directly in the template file
            $visitor_collection = Mage::getResourceModel('log/visitor_collection')->useOnlineFilter();
	    $visitor_count = count($visitor_collection);
        if(!empty($visitor_count) && $visitor_count > 0)
        {
        	$cnt =  $visitor_count;
                echo 'Visitors online :'.$cnt;
        }  

?>

Hope this is helpful.



7 Responses to “Online Visitors Magneto”

  1. aheadWorks says:

    for the lazy magento devs we have out-of-the box extension http://ecommerce.aheadworks.com/free-stuff/visitors-online.html

  2. taly says:

    thanks a bout this article. And can you write an article about total of access website, amount of access in current day and current month?
    Thanks a lots.

    • DWRoot says:

      @taly – In Magento site, when you login in adminend, you can see number of times the product viewed, I have used this in my store DecryptWeb Store, you need to modify the code for filtering as per the date. Also you can use Google Analytics for tracking your site’s user access, it will be much useful.

  3. Budi says:

    Hi, can u please give more instruction which file at what folder need to be edited?

    And which part should be manipulated to make: if there’s no visitor, the visitor count show 5 instead of 0

    Thanks

    • DWRoot says:

      @Budi – There is no need to modify any of the default file, you can make a new block file and simply write above mentioned code or can write in any of the existing block file. The visitor counts depends on the customer logs generated in Magento, hope this helps you

  4. Avatarus says:

    Ok, works, but… it dont refresh if you have cache enabled, so It shows last counter before cache.
    How Can i Fix that?

    • DWRoot says:

      It depends on the visitors logs generated by Magento in a given time.

      I derived at this code from the default Magento code for Customers->Online Customers section found in the default Magento admin end.

Leave a Reply

top