combindma/laravel-trail
Composer 安装命令:
composer require combindma/laravel-trail
包简介
A simple package for tracking user activities on your Laravel website.
README 文档
README
Laravel Trail is a powerful and easy-to-use package for tracking user activities on your Laravel website. Developed by Combind, this package automatically logs important information such as UTM tags, referrers, user actions, and more, giving you valuable insights into your users behavior and their journey through your website.
But WHY ?
The Laravel Trail is designed to help developers effortlessly capture and store user activity data on their websites. This package enables you to track vital information such as UTM tags, referrers, and user actions, which can be used to gain valuable insights into user behavior and website performance.
By storing this information, developers can easily integrate it with their preferred tracking tools, such as Google Analytics or other analytics platforms, to further analyze user interactions and optimize their websites for improved user experience, conversion rates and improve their marketing targeting.
Features
- Effortless Tracking: Automatically track user activities without any additional code
- Capture Important Data: Log UTM tags, referrers, and user actions for valuable insights
- Cookies Integration: Store tracked data in cookies
- Customizability: Easily extend and modify the package to track additional data or events
- Documentation & Support: Benefit from comprehensive documentation and support
About Combind Agency
Combine Agency is a leading web development agency specializing in building innovative and high-performance web applications using modern technologies. Our experienced team of developers, designers, and project managers is dedicated to providing top-notch services tailored to the unique needs of our clients.
If you need assistance with your next project or would like to discuss a custom solution, please feel free to contact us or visit our website for more information about our services. Let's build something amazing together!
Installation
You can install the package via composer:
composer require combindma/laravel-trail
You can publish the config file with:
php artisan vendor:publish --tag="laravel-trail-config"
This is the contents of the published config file:
return [ /* * The prefix key under which data is saved to the cookies. */ 'prefix' => env('TAIL_COOKIE_PREFIX', config('app.name', 'laravel')).'_', /* * The cookie duration in seconds used to store data. By default, we use 180 days. */ 'cookie_duration' => env('TAIL_COOKIE_DURATION', 60 * 24 * 180), /* * Enable or disable script rendering. Useful for local development. */ 'enabled' => env('TAIL_ENABLED', false), ];
Monitored Tags
Laravel Trail automatically tracks and stores the following tags, providing valuable insights into user behavior, traffic sources, and user demographics:
-
UTM Tags
utm_source: Identifies the traffic source (e.g., google, newsletter, referral_website).utm_medium: Describes the marketing medium (e.g., cpc, email, social).utm_campaign: Provides details about the specific marketing campaign or promotion (e.g., spring_sale, newsletter_april).utm_term: Captures the keywords used for paid search campaigns (e.g., running+shoes, digital+marketing).utm_content: Differentiates between multiple links within the same ad or content piece (e.g., logo_link, text_link).
-
Additional Tags
anonymous_id: A unique identifier for tracking anonymous users on your website.user_id: A unique identifier for registered or logged-in users on your website.email: A unique email for registered or logged-in users on your website.name: Full name for registered or logged-in users on your website.landing_page: The first page the user visits on your website during a session.exit_page: The last page the user visits before leaving your website.ip_address: The user's IP address, which can provide insights into their location and network.last_activity: The date and time of the user's most recent activity on your website.user_agent: The user agent string, which provides detailed information about the user's browser, operating system, and device.language: The user's preferred language, as specified in their browser settings.referrer: The URL of the referring website that sent the user to your website.referrer_code: A unique code or ID associated with the referrer (e.g., an affiliate partner or referral program).
-
Expected Tags for the futur
device: The type of device used by the user (e.g., desktop, tablet, mobile).browser: The user's web browser (e.g., Chrome, Firefox, Safari).operating_system: The user's operating system (e.g., Windows, macOS, Android, iOS).screen_resolution: The user's screen resolution.page_views: The number of pages viewed by the user during a single session.conversion_date: The date when a user completes a desired action or goal (e.g., making a purchase or signing up for a newsletter).
These tags can help you optimize your website for better user experience and higher conversion rates by giving you a deeper understanding of user interactions and traffic patterns.
Usage
Add the setup middleware
This middleware is responsable for setting: anonymous_id, user_id, exit_page, landing_page, last_activity, user_agent, ip_address, language
// app/Http/Kernel.php protected $middleware = [ ... \Illuminate\Session\Middleware\StartSession::class, \Combindma\Trail\Middleware\TrailSetupMiddleware::class, ... ];
Save UTM tags
You have 2 options to save the utm tags:
1. In your controller
public function index(Request $request) { \Combindma\Trail\Facades\Trail::setUtmCookies($request); //... }
2. Using a middleware in your route
Route::group([ 'middleware' => ['web', \Combindma\Trail\Middleware\HandleUtmTagsMiddleware::class]], function () { Route::get('/test-trail', function (Request $request) { //... }); }); //... }
Save Referrer
You have 2 options to save the utm tags:
1. In your controller
public function index(Request $request) { \Combindma\Trail\Facades\Trail::setReferrerCookies($request); //... }
2. Using a middleware in your route
Route::group([ 'middleware' => ['web', \Combindma\Trail\Middleware\CaptureReferrerMiddleware::class]], function () { Route::get('/test-trail', function (Request $request) { //... }); }); //... }
Save User ID or Email
You can capture a user id or email using an url with those parameters: user_id or email.
For exemple: domaine.com?user_id=123456&email=email@email.com
You have 2 options to save the user:
1. In your controller
public function index(Request $request) { \Combindma\Trail\Facades\Trail::setUserCookie($request); //... }
2. Using a middleware in your route
Route::group([ 'middleware' => ['web', \Combindma\Trail\Middleware\CaptureUserMiddleware::class]], function () { Route::get('/test-trail', function (Request $request) { //... }); }); //... }
Identify a user
The only required parameter is userId:
\Combindma\Trail\Facades\Trail::identify($userId);//User id can be an email if you don't offer a sign-up in your website \Combindma\Trail\Facades\Trail::identify($userId, 'email@domain.com', 'full name'); //you may also save an email with a name
Get the cookies data
In order to get the saved data you can request it using:
\Combindma\Trail\Facades\Trail::data($request); \Combindma\Trail\Facades\Trail::data(); //Behind the scene uses request() helper
This will return a formatted data object:
readonly class TrailDto { public function __construct( public string $anonymousId, public ?string $userId, public ?string $email, public ?string $name, public ?string $landingPage, public ?string $exitPage, public ?string $lastActivity, public ?string $ipAddress, public ?string $language, public ?string $userAgent, public ?string $referrer, public ?string $referrerCode, public ?string $utmSource, public ?string $utmMedium, public ?string $utmCampaign, public ?string $utmTerm, public ?string $utmContent, ) { } }
Additional methods
\Combindma\Trail\Facades\Trail::disable(); //Disable in the fly \Combindma\Trail\Facades\Trail::enable(); //Enable in the fly \Combindma\Trail\Facades\Trail::getAnonymousId(); //Get anonymous id
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
combindma/laravel-trail 适用场景与选型建议
combindma/laravel-trail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 234 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 12 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「combindma」 「laravel-trail」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 combindma/laravel-trail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 combindma/laravel-trail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 combindma/laravel-trail 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Meta pixel integration for Laravel
Laravel package to communicate with the CMI payment plateform
A Laravel package for tracking popular entries(by Models) of a website in a certain time
Laravel Twillio SMS API Integration
A key-value storage for laravel
Alfabank REST API integration
统计信息
- 总下载量: 234
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-25