定制 allenkhoury/user-activity 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

allenkhoury/user-activity

Composer 安装命令:

composer require allenkhoury/user-activity

包简介

Dashboard that will track user activity and online users.

README 文档

README

This package provides real-time tracking of active users on your website and logs their activity. It can be installed on any Laravel project version 9 or 10.

The real-time tracking is powered by websockets, so you will need to set up a Pusher account. Alternatively, laravel-websocket can also be used.

Dashboard

Requirement

  • PHP 8.1+
  • Laravel 9|10
  • Pusher (For real-time tracking)

Installing

Install this package through composer:

composer require allenkhoury/user-activity

Once installed, it will be auto discovered by laravel.

Next, we need to publish the necessary data for this package: migrations, config and assets.

  • migrations: tables required to log user activity.
  • config: a set of options to tweak the plugin.
  • assets: these are required to load the user activity dashboard panel.

Run the code below to publish all package necessary data:

php artisan vendor:publish --tag=al-user-activity.package

We can then run migrate to create the package's tables in the database.

php artisan migrate

Real time tracking

This package provides real-time tracking of active users on your website using websockets. Pusher is the preferred websockets provider for this package.

Installing Pusher

To install Pusher, you can follow the instructions in the Laravel broadcasting documentation.

Adding the tracking script to your layout file

Once you have installed Pusher, you need to add the following code to your layout blade file, at the bottom of the file after scripts:

@tracking_script

This custom blade directive will inject some scripts in your layout file so Laravel Echo can start tracking properly.

Enabling real-time tracking

Finally, you need to enable real-time tracking by setting the following environment variable:

AL_TRACKING_ENABLED=true

Setting the user identifier

The package needs to know which column in your database contains the user's name. By default, the package assumes that the column is called name. However, you can change this by setting the user_identifier option in the package configuration file.

Activity log

This package can also log user activity on the website. This can be useful for tracking how users are interacting with your website and identifying potential problems.

Enabling activity logging

To enable activity logging, you need to set the following environment variable to true:

AL_ACTIVITY_LOG_ENABLED=true

Configuration

By default, this package will track the following HTTP requests:

  • POST
  • PUT
  • PATCH
  • DELETE

However, you can change this configuration by editing the allowed_methods option in the package's published configuration file. For example, to only track POST and PUT requests, you would change the configuration to the following:

'activity_log' => [
    'enabled' => env('AL_ACTIVITY_LOG_ENABLED', false),
    'allowed_methods' => [
        'POST', 'PUT'
    ],
]

You can check the supported HTTP methods in the Laravel route documentation

Exceptions

You can exclude some routes from being tracked by adding the no-logging middleware to your routes.

Note: This package will only log activity of authenticated users. Guests will not be tracked.

Dashboard

The package comes with a dashboard that allows you to track active users and check all activity logs.

Enabling the dashboard

The dashboard is enabled by default. To disable it, set the following environment variable to false:

AL_DASHBOARD_ENABLED=false

Dashboard URL

The dashboard is available on the URL /al-user-activity. You can change the URL by adding a prefix using the option url_prefix in the package configuration file. For example, to add the prefix admin (/admin/al-user-activity), you would change url_prefix as follows:

'dashboard' => [
    'enabled' => env('AL_DASHBOARD_ENABLED', true),
    'url_prefix' => 'admin',
    'extra_middlewares' => [],
],

Dashboard access

By default, any authenticated user can access the dashboard. To restrict access, for example to just admins, you can add your custom middleware alias to the option extra_middlewares in the package configuration file. For example:

'dashboard' => [
    'enabled' => env('AL_DASHBOARD_ENABLED', true),
    'url_prefix' => 'admin',
    'extra_middlewares' => ['admin-middleware-alias'],
],

Note: You can add as many middlewares as needed.

General notes

The package will use the model set in config('auth.provider.users.model') as the users model.

The dashboard UI is built using the free template Sneat by ThemeSelection

License

The MIT License (MIT). Please see License File for more information.

allenkhoury/user-activity 适用场景与选型建议

allenkhoury/user-activity 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 allenkhoury/user-activity 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 allenkhoury/user-activity 我们能提供哪些服务?
定制开发 / 二次开发

基于 allenkhoury/user-activity 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-08-27