PHPackages                             foothing/laravel-simple-pageviews - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. foothing/laravel-simple-pageviews

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

foothing/laravel-simple-pageviews
=================================

1.0.0(8y ago)281.5k7[1 issues](https://github.com/foothing/laravel-simple-pageviews/issues)[4 PRs](https://github.com/foothing/laravel-simple-pageviews/pulls)MITPHP

Since Oct 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/foothing/laravel-simple-pageviews)[ Packagist](https://packagist.org/packages/foothing/laravel-simple-pageviews)[ RSS](/packages/foothing-laravel-simple-pageviews/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (9)Versions (10)Used By (0)

Laravel Simple Pageviews
========================

[](#laravel-simple-pageviews)

[![Code Climate](https://camo.githubusercontent.com/9958c3cbf9b460a30683970da9b8d0fca527ed76a4ed9bfdb1493dcb2e237e25/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f666f6f7468696e672f6c61726176656c2d73696d706c652d7061676576696577732f6261646765732f6770612e737667)](https://codeclimate.com/github/foothing/laravel-simple-pageviews)[![Test Coverage](https://camo.githubusercontent.com/635c31883ba9783b1832d933f753b667230fce9814df165333ff41c86f12eb56/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f666f6f7468696e672f6c61726176656c2d73696d706c652d7061676576696577732f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/foothing/laravel-simple-pageviews/coverage)[![Build Status](https://camo.githubusercontent.com/a6bf160a6677f4fa1c383e12f8c55c562175e796a007e31289a61daad8e7e074/68747470733a2f2f7472617669732d63692e6f72672f666f6f7468696e672f6c61726176656c2d73696d706c652d7061676576696577732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/foothing/laravel-simple-pageviews)

Tracks page views of your Laravel 5.x app for traffic monitoring.

To date, it has been tested with Laravel up to 5.5 and PHP 7.

> **IMPORTANT** If you are upgrading from previous 0.x version please [read the release notes](https://github.com/foothing/laravel-simple-pageviews/releases/tag/1.0.0).

This package is meant for simple request tracking and not for in-depth traffic analysis. Features:

- track page views
- track unique page views
- customizable whitelist rules
- url filter and crawler filter
- fetch data for reports

Each log record keeps track of the user session, user ip and date.

Setup
-----

[](#setup)

Install module:

`composer require foothing/laravel-simple-pageviews`

Add the service provider in `config/app.php`:

```
'providers' => [
	Foothing\Laravel\Visits\ServiceProvider::class,
]
```

Publish migration and configuration files:

`php artisan vendor:publish provider="Foothing\Laravel\Visits\ServiceProvider --tag="config"`

`php artisan vendor:publish provider="Foothing\Laravel\Visits\ServiceProvider --tag="migrations"`

Run the migration:

`php artisan migrate`

Finally, add the middleware in your `app/Http/Kernel.php`:

```
protected $middleware = [
	'Foothing\Laravel\Visits\Middlewares\CountPageView',
];
```

Configure
---------

[](#configure)

In `config/visits.php`

```
// Enable or disable tracking.
"enabled" => true,

// Add patterns to be blacklisted (ignored and not tracked).
// These patterns will apply if the UrlWhitelist rule is
// enabled in the chain.
"blacklist" => [
    // i.e. '/^(admin|api|auth).*/'
],

// Rules chain.
"rules" => [
    "Foothing\Laravel\Visits\Rules\Crawler",
    "Foothing\Laravel\Visits\Rules\UrlWhitelist",
],
```

Rules are meant to filter requests that you don't want to track. Default ones will filter out **crawlers** (thanks to ) and **blacklisted urls**.

Query methods
-------------

[](#query-methods)

```
$manager = app()->make("Foothing\Laravel\Visits\Reports\ReportManager");

// Get visits with url and hits. This should be used to
// get an overview of the best performer urls.
$manager->getVisits();

[
	{
		"url": "foo/bar",
		"hits": 129
	},
	{
		"url": "baz",
		"hits": 40
	}
]

// Return int
$manager->countOverallVisits();
$manager->countOverallVisits('today', 'tomorrow', 'foo/bar');

// Return int
$manager->countUniqueVisits('currentWeek');
$manager->countUniqueVisits('currentWeek', null, 'foo/bar');

// Return a data collection meant for chart plotting.
$manager->getVisitsTrendDaily();

[
	{
		"day": "2016-10-08"
		"hits": 129
	},
	{
		"day": "2016-10-09"
		"hits": 40
	}
]
```

Each query method allows for date filtering and will accept up to 3 arguments.

- first argument can be a *string preset*, a string that `Carbon` can parse or a `Carbon` date
- second argument as the first one
- third argument can be an url

Only exception is the `aggregate()` method, which will accept a `limit` argument.

Examples:

```
// Triggers default filter
$manager->getVisits();

// String presets
$manager->getVisits('today');
$manager->getVisits('currentWeek');
$manager->getVisits('currentMonth');
$manager->getVisits('currentYear');

// Single day
$manager->getVisits(\Carbon::now());

// Period
$manager->getVisits(\Carbon::now(), Carbon::tomorrow());
```

The input buffer
----------------

[](#the-input-buffer)

This package has been tested in a moderate traffic website, like ~20k pageviews / day which makes about 17k database records per day. The visits table will grow up pretty quick and the database might suffer performance issues when it comes to execute an `insert or update` statement on a table which count hundred thousands (or millions) rows.

For this reason an insert/update buffer has been added. Basically, each visit is tracked in a temporary table that is only used on write operations, while the report and read operations are performed on a separate table.

An `artisan` command has been added to handle the periodic data dump from the write table to the read table. A good practice might be dumping data each day.

TL;DR configure as follows in your `app/Console/Kernel.php` (please refer to Laravel docs for scheduling info):

```
/**
 * The Artisan commands provided by your application.
 *
 * @var array
 */
protected $commands = [
	'Foothing\Laravel\Visits\Commands\DumpVisitsBuffer',
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
	// Adjust this with your needs.
	$schedule->command('visits:buffer')->dailyAt("00:00");
}
```

Performances
------------

[](#performances)

Performances have been tested in a ~5 million records database with good results. However, i recommend to partition your database tables if size grows nasty, i.e. 1 milion record per partition. Also, a good practice would be to tune your partition to be consistent with date periods (i.e. full year in single partition, single quarter in single partition, etc.) according to your traffic and report type.

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~111 days

Total

8

Last Release

3051d ago

Major Versions

0.4.1 → 1.0.02018-01-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ebf3a4938226620036760ed05bf0d6801b7bc2c383a1fd7dd1a4c48ba84145d?d=identicon)[brazorf](/maintainers/brazorf)

---

Top Contributors

[![brazorf](https://avatars.githubusercontent.com/u/3330031?v=4)](https://github.com/brazorf "brazorf (48 commits)")

---

Tags

laraveltrackingpage viewspage hits

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/foothing-laravel-simple-pageviews/health.svg)

```
[![Health](https://phpackages.com/badges/foothing-laravel-simple-pageviews/health.svg)](https://phpackages.com/packages/foothing-laravel-simple-pageviews)
```

###  Alternatives

[yajra/laravel-datatables-oracle

jQuery DataTables API for Laravel

4.9k33.8M339](/packages/yajra-laravel-datatables-oracle)[ashallendesign/short-url

A Laravel package for creating shortened URLs for your web apps.

1.4k1.9M4](/packages/ashallendesign-short-url)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[yajra/laravel-datatables-editor

Laravel DataTables Editor plugin for Laravel 5.5+.

1186.1M2](/packages/yajra-laravel-datatables-editor)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
