kwxs/counter

页面点击计数器。

维护者

详细信息

github.com/KWXS/Counter

源代码

安装: 271

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 33

6.0.2 2019-11-12 08:49 UTC

README

安装

运行以下命令

composer require kryptonit3/counter:5.2.*

将以下内容添加到您的 config\app.php 服务提供者

Kryptonit3\Counter\CounterServiceProvider::class,

将以下内容添加到您的 config\app.php 门面

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

然后运行以下命令

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

php artisan migrate

在Laravel环境配置文件中设置Cookie名称

    COUNTER_COOKIE="Name of your cookie"

如何使用

常规页面

只需添加 Counter::showAndCount('home')(对于Blade使用{{ Counter::showAndCount('home') }})。将 home 替换为您正在处理的页面的唯一名称。

动态页面

对于动态页面,例如用户资料或职位列表等,您可能需要提供以下动态元素:Counter::showAndCount('user-profile', $user->id)(对于Blade使用{{ Counter::showAndCount('user-profile', $user->id) }}

user-profile 替换为您正在处理的页面的唯一名称。

数字输出已格式化。因此,3000位访客将显示为3,000。

如果您在页面上有记录,但不想将显示记录的页面视为对记录本身的点击,则将 showAndCount 更改为仅 show。例如:Counter::show('job-listings', $job->id)(对于Blade使用{{ Counter::show('job-listings', $job->id) }}

您可以使用 Counter::allHits() 获取整个网站上每个页面的所有点击(对于Blade使用{{ Counter::allHits() }})。要指定日期约束,例如仅过去30天的所有点击,请执行 Counter::allHits(30)(对于Blade使用{{ Counter::allHits(30) }})。

如果您只想对页面进行处理而不显示任何内容,则只需使用 Counter::count('user-profile', $user->id)。它与所有之前的示例在静态和动态页面上的功能相同,Blade语法相同。这对于在不让每个人看到的情况下统计页面点击非常有用。

祝您享受!

额外信息

此包允许您查看特定页面/对象的点击次数以及整个网站的点击次数。它还使用唯一生成的cookie(回退到IP)以提供更准确的读取。对于喜欢匿名的人的好包 :)

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)

欢迎拉取请求。