xcorch/tracker
最新稳定版本:v1.0.0
Composer 安装命令:
composer require xcorch/tracker
包简介
A PHP Composer package for tracking website views to your XCorch dashboard
README 文档
README
A PHP Composer package for tracking website views to your XCorch dashboard.
Installation
composer require xcorch/tracker
Configuration
Create a .env file in your project root with the following variables:
XCORCH_API=xcorch_your_api_key_here XCORCH_WEBSITE_CODE=ABC12345
Your API key and website code can be found in your XCorch app or website dashboard.
Usage
Basic Tracking
Simply call the track() method on each page to automatically track page views. The method returns JavaScript code that tracks scroll depth and end time:
<?php require 'vendor/autoload.php'; use xcorch\Tracker\Tracker; $tracker = new Tracker(); echo $tracker->track();
Or in a template/view:
<?php $tracker = new Tracker(); ?> <!-- Your page content --> <?php echo $tracker->track(); ?>
The track() method will:
- Check for an existing session in cookies
- Create a new session if one doesn't exist
- Record the page view with entry time and source URL (domain only, e.g.,
google.com) - Automatically detect device type (mobile/desktop)
- Return JavaScript that tracks scroll depth and sends end time when the user leaves the page
Excluding Pages from Tracking
You can exclude dynamic pages (like products, blogs, etc.) from being tracked:
$tracker = new Tracker(); // Exclude specific URL patterns $tracker->setExcludedPatterns([ '/products/', '/blogs/', '/admin/', '/\/api\/.*/' // Regex pattern to exclude all API routes ]); echo $tracker->track();
Pattern Types:
- String patterns: Simple string matching (e.g.,
/products/will exclude any URL containing/products/) - Regex patterns: Must start and end with
/(e.g.,/\/blogs\/.*/will exclude all blog URLs)
Note: Excluded pages will not create sessions or record views, but will still return empty JavaScript (no tracking code).
Validate Credentials
You can validate your API key and website code:
$tracker = new Tracker(); $result = $tracker->validateCredentials(); if ($result['valid']) { echo "Credentials are valid!"; // Access site and business data from $result['data'] } else { echo "Validation failed: " . $result['error']; }
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-09