PHP code example of monishroy / visitor-tracking

1. Go to this page and download the library: Download monishroy/visitor-tracking library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

monishroy / visitor-tracking example snippets


Route::get('/home', [HomeController::class, 'index'])->middleware('visitor_tracking');

Route::middleware(['visitor_tracking'])->group(function () {
    Route::get('/home', [HomeController::class, 'index']);
    Route::get('/about', [AboutController::class, 'index']);
});

use Monishroy\VisitorTracking\Helpers\Visitor;

Visitor::totalVisitors(),     // Returns the total number of visitors
Visitor::uniqueVisitors(),    // Returns the count of unique visitors
Visitor::topVisitedPages($limit),   // Returns the most visited pages $limit = 5 default
Visitor::countries(),         // Returns visitor countries
Visitor::os(),                // Returns operating systems used by visitors
Visitor::devices()            // Returns devices used by visitors

[
    "totalVisitors" => 1000,
    "uniqueVisitors" => 750,
    "topVisitedPages" => [
        [
            'page_title' => 'Home',
            'url' => 'https://example.com'
        ],[
            'page_title' => 'About',
            'url' => 'https://example.com/about'
        ],[
            'page_title' => 'Contact',
            'url' => 'https://example.com/contact'
        ],
    ],
    "countries" => [
        "US" => 400,
        "IN" => 300,
        "BD" => 100
    ],
    "os" => [
        "Windows" => 600,
        "MacOS" => 300,
        "Linux" => 100
    ],
    "devices" => [
        "Desktop" => 700,
        "Mobile" => 250,
        "Tablet" => 50
    ]
]

use Monishroy\VisitorTracking\Models\VisitorTable;

$visitors = VisitorTable::where('country', 'US')->get();
foreach ($visitors as $visitor) {
    echo $visitor->page . ' visited from ' . $visitor->country;
}
bash
   php artisan migrate