aleksa/laravel-visitors-statistics

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple visitor tracker and statistics package for Laravel 5 that can be used for dashboard graphs.

v7.0.0 2020-03-15 20:53 UTC

This package is auto-updated.

Last update: 2022-01-06 20:38:01 UTC


README

Packagist Packagist Packagist

Simple visitor tracker and statistics package for Laravel 5 that can be used for dashboard graphs. Includes controller and routes to fetch visitor statistics (all and unique visits) for a certain month or year. You can also get total number of visits per country.

Installation

  1. Install package using composer:
composer require aleksa/laravel-visitors-statistics
  1. Since the package automatically adds it's middleware to web group you will have to register service provider manually
...
'providers' => [
    ...
    Aleksa\LaravelVisitorsStatistics\Providers\VisitorStatisticsProvider::class,
    ...
],
...
  1. Run migrations:
php artisan migrate
  1. Publish configuration:
php artisan vendor:publish

and choose Aleksa\LaravelVisitorsStatistics\Providers\VisitorStatisticsProvider from the list

  1. Download MaxMind database
php artisan maxmind:update

GeoIP

Since fetching data from external API (eg: ipstack, ipdata etc...) takes time and slows down your application and can also produce monthly costs the package uses local MaxMind database and maxmind-db/reader package for reading it's contents and locating the visitors.

For more sophisticated tracking you should use something like Google Analytics.

Configuration

Name Description Default
track_authenticated_users Should the tracker track authenticated users false
track_ajax_request Should the tracker track ajax requests false
login_route_path Admin login path so that login attempts don't track as visits 'admin'
prefix Prefix to apply to all statistics fetching routes 'admin'
middleware Middlewares to be applied to all statistics fetching routes '['web', 'auth']'
database_location Location where to store MaxMind database storage_path('app/maxmind.mmdb')
database_download_url MaxMind database download url MAXMIND_URL
auto_update Should laravel automatically update MaxMind database true

NOTE: If you set auto_update to true make sure to add Laravel cron entry that is needed for Task Scheduling.

Fetching statistics

The package comes with a controller and a bunch of routes to fetch statistics. The idea is to fetch statistics on your dashboard with AJAX request and parse data to some JavaScript graph library like Highcharts.

Route name Route URI Description
visitorstatistics.all_statistics /statistics/{year}/{month?} Get statistics for the given year or month.
visitorstatistics.unique_statistics /statistics/unique/{year}/{month?} Get unique statistics for the given year or month.
visitorstatistics.total_statistics /statistics/total/{year}/{month?} Get both all and unique statistics for a given year or month.
visitorstatistics.countries /statistics/countries Get visits count and percentage for each country.
visitorstatistics.available_dates /statistics/available/{year?} Get years or months that have statistics tracked.

NOTE: All routes are prefixed with value set in configuration and return response in JSON format.

Example responses

/admin/statistics/2019

{
    "data": {
        "1": 712,
        "2": 1379,
        "3": 1095,
        "4": 624,
        "5": 1181,
        "6": 271,
        "7": 0,
        "8": 0,
        "9": 0,
        "10": 0,
        "11": 0
    }
}

/admin/statistics/2019/6

{
    "data": {
        "1": 76,
        "2": 33,
        "3": 35,
        "4": 54,
        "5": 73,
        "6": 0,
        "7-26": "...",
        "27": 0,
        "28": 0,
        "29": 0
    }
}

/admin/statistics/total/2019

{
    "all": {
        "1": 0,
        "2": 0,
        "3": 0,
        "4": 0,
        "5": 0,
        "6": 271,
        "7": 0,
        "8": 0,
        "9": 0,
        "10": 0,
        "11": 0
    },
    "unique": {
        "1": 0,
        "2": 0,
        "3": 0,
        "4": 0,
        "5": 0,
        "6": 42,
        "7": 0,
        "8": 0,
        "9": 0,
        "10": 0,
        "11": 0
    }
}

/admin/statistics/countries

{
    "data": [
        {
            "country": "Germany",
            "count": 6,
            "percentage": 40
        },
        {
            "country": "United States",
            "count": 4,
            "percentage": 26.67
        },
        {
            "country": "Unknown",
            "count": 2,
            "percentage": 13.33
        },
        {
            "country": "Thailand",
            "count": 1,
            "percentage": 6.67
        },
        {
            "country": "Russia",
            "count": 1,
            "percentage": 6.67
        },
        {
            "country": "Serbia",
            "count": 1,
            "percentage": 6.67
        }
    ]
}

/admin/statistics/available

{
    "data": [
        2019
    ]
}

Information being collected

This is the data that is being tracked for each visitor.

Name Description
ip e.g. '127.0.0.1'
country e.g. 'Serbia'
city e.g. 'Belgrade'
device e.g. 'desktop'
browser e.g. 'Chrome'

License

This is open-sourced software licensed under the MIT license.