2017 © Pedro Peláez
 

library counter

Hit counter for your pages.

image

kryptonit3/counter

Hit counter for your pages.

  • Sunday, January 21, 2018
  • by Kryptonit3
  • Repository
  • 7 Watchers
  • 72 Stars
  • 7,071 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 31 Forks
  • 14 Open issues
  • 14 Versions
  • 15 % Grown

The README.md

Hit Counter for Laravel 5.*

Installation

Run the following command:, (*1)

composer require kryptonit3/counter:5.2.*

Add the following to your config\app.php Service Providers, (*2)

Kryptonit3\Counter\CounterServiceProvider::class,

Add the following to your config\app.php Facades, (*3)

'Counter' => Kryptonit3\Counter\Facades\CounterFacade::class,

Then run the following:, (*4)

php artisan vendor:publish --provider="Kryptonit3\Counter\CounterServiceProvider" --tag="migrations"

php artisan migrate

Set Cookie Name in Laravel env Config file, (*5)

    COUNTER_COOKIE="Name of your cookie"

How to Use

Regular pages

Just add Counter::showAndCount('home') ( for blades uses {{ Counter::showAndCount('home') }} ). Change home to a unique name for the page you are working with., (*6)

Dynamic pages

For dynamic pages, such as user profiles, or job listings etc you may provide a dynamic element like this Counter::showAndCount('user-profile', $user->id) ( for blades use {{ Counter::showAndCount('user-profile', $user->id) }} ), (*7)

Change user-profile to a unique name for the page you are working with., (*8)

Number output is already formatted. So 3000 visitors will render as 3,000, (*9)

If you have records on a page but do not want to count visiting the page displaying the records as a hit on the record itself then change showAndCount to just show. Example Counter::show('job-listings', $job->id) ( for blades use {{ Counter::show('job-listings', $job->id) }} ), (*10)

You may get all hits for every page on the entire site with Counter::allHits() ( for blades use {{ Counter::allHits() }} ). To specify a day constraint, like only all hits for the past 30 days then do Counter::allHits(30) (for blades use {{ Counter::allHits(30) }} )., (*11)

If you would just like to process a hit for a page without displaying anything then just use Counter::count('user-profile', $user->id). Works the same as all previous examples for both static and dynamic pages, blade is the same syntax. Useful for counting hits for a page without letting everyone see., (*12)

Enjoy!, (*13)

Extra

This package lets you see hit counts for specific pages/objects as well as an overall site hit count. It also uses a uniquely generated cookie (fallback to IP) to give a more accurate reading. Nice package for the pro-anonymous people :), (*14)

mysql> select * from kryptonit3_counter_page;
+----+--------------------------------------+
| id | page                                 |
+----+--------------------------------------+
|  2 | 24d83c12-a1e0-598b-93ee-df05ae3f87e7 |
|  1 | 597e0526-152f-5fc0-9d44-b51fd9e45b8f |
+----+--------------------------------------+
2 rows in set (0.00 sec)

mysql> select * from kryptonit3_counter_visitor;
+----+------------------------------------------------------------------+
| id | visitor                                                          |
+----+------------------------------------------------------------------+
|  1 | 88a5f67524a1bc75da5ea8b7250e8280c78d60dce59b129dc37123b137ce6199 |
+----+------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from kryptonit3_counter_page_visitor;
+---------+------------+---------------------+
| page_id | visitor_id | created_at          |
+---------+------------+---------------------+
|       1 |          1 | 2015-06-22 17:52:43 |
|       2 |          1 | 2015-06-22 17:52:43 |
+---------+------------+---------------------+
2 rows in set (0.00 sec)

Pull requests are welcome.

The Versions

21/01 2018

dev-master

9999999-dev

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

21/01 2018

5.2.9

5.2.9.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

29/10 2017

5.2.8

5.2.8.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

29/10 2017

5.2.7

5.2.7.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

29/10 2017

dev-Kryptonit3-patch-1

dev-Kryptonit3-patch-1

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

27/04 2017

5.2.6

5.2.6.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

26/09 2016

5.2.5

5.2.5.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

18/09 2016

5.2.4

5.2.4.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

26/01 2016

5.1.x-dev

5.1.9999999.9999999-dev

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

26/01 2016

5.2.x-dev

5.2.9999999.9999999-dev

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

26/01 2016

5.2.3

5.2.3.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

26/01 2016

5.2.2

5.2.2.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

26/01 2016

5.2.1

5.2.1.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski

18/07 2015

5.1

5.1.0.0

Hit counter for your pages.

  Sources   Download

MIT

The Requires

 

by Jesse Szypulski