---
title: "How to Add Website Total Visitor on Admin Dashboard in Magento 2?"
url: "https://magecomp.com/blog/add-website-total-visitor-on-admin-dashboard-magento-2/"
date: "2023-09-11T15:20:04+00:00"
modified: "2025-02-13T06:06:46+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 432
reading_time: "3 min read"
summary: "Hello Magento Friends,"
description: "Learn step-by-step tutorial on How to Add Website Total Visitor on Admin Dashboard in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to add Checkout Custom Form Validation using knockout JS in Magento 2?"
    url: "https://magecomp.com/blog/add-checkout-custom-form-validation-using-knockout-js-magento-2/"
  - title: "What is Localization in Laravel and How to Use it?"
    url: "https://magecomp.com/blog/laravel-localization/"
  - title: "How to Set and Get Cookie in Magento 2?"
    url: "https://magecomp.com/blog/set-and-get-cookie-magento-2/"
---

# How to Add Website Total Visitor on Admin Dashboard in Magento 2?

_Published: September 11, 2023_  
_Author: Dhiren Vasoya_  

![How to Add Website Total Visitor on Admin Dashboard in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/09/How-to-Add-Website-Total-Visitor-on-Admin-Dashboard-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In this Magento 2 blog tutorial, we will learn How to Add Website Total Visitor on Admin Dashboard in Magento 2.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

Knowing the total number of visitors to your Magento 2 store is an essential part of website analytics. It provides valuable data that can help you understand your audience, assess the effectiveness of your strategies, and make informed decisions to improve your store’s performance and user experience.
Let’s find out How to Add Total Visitors on the Admin Dashboard in Magento 2.
## Steps to Add Website Total Visitor on Admin Dashboard in Magento 2:
**Step 1:** First, we need to create a **di.xml** file inside the extension at the following path.
**app\code\Vendor\Extension\etc\adminhtml\**

Then add the code as follows
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="MagentoBackendBlockDashboardSales" type="VendorExtensionBlockDashboardSales"/>
</config>
```

**Step 2:** After that, we need to create a **Sales.php** file inside the extension at the following path.
**app\code\Vendor\Extension\Block\Dashboard\**

And add the following code-snippet
```
<?php
namespace VendorExtensionBlockDashboard;

use MagentoBackendBlockTemplateContext;
use MagentoFrameworkModuleManager;
use MagentoReportsModelResourceModelOrderCollectionFactory;
use MagentoCustomerModelVisitor;

class Sales extends MagentoBackendBlockDashboardSales
{
    protected $visitors;
    protected $vendorCollectionFactory;

    public function __construct(
        Context $context,
        CollectionFactory $collectionFactory,
        Manager $moduleManager,
        Visitor $visitors,
        array $data = []
    ) {
        $this->_moduleManager = $moduleManager;
        $this->visitors = $visitors;
        parent::__construct($context, $collectionFactory,$moduleManager, $data);
    }

    protected function _prepareLayout()
    {
        parent::_prepareLayout();
        $collection = $this->visitors->getCollection();

        $this->addCustomerVisitor(__('Total Visitors :'), count($collection));
    }
    public function addCustomerVisitor($label, $value, $isQuantity = false)
    {
        $decimals = '';
        $this->_totals[] = ['label' => $label, 'value' => "".$value."",'decimals' => $decimals];
        return $this;
    }
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 3:** Once all files are created in your Magento, you need to run Magento upgrade, compile and deploy commands as follows.
```
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento setup:di:compile
php bin/magento cache:clean
php bin/magento cache:flush
```

**Output:**

![Total Visitors](https://magecomp.com/blog/wp-content/uploads/2023/09/Total-Visitors.png)

## Conclusion:
Hence, this way, you can add the total visitors count in the Magento 2 admin dashboard. If you have any doubts regarding the above steps, feel free to get in touch with me through the comment box. If you need further customization, contact [**experienced Magento Developers**](https://magecomp.com/hire-magento-developer.html). Share the tutorial with your friends and stay in touch with us for more such useful solutions.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/add-website-total-visitor-on-admin-dashboard-magento-2/](https://magecomp.com/blog/add-website-total-visitor-on-admin-dashboard-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-15 22:05:21 UTC_  
