asci / track
track 是一个基于事件的跟踪系统,支持多种数据库后端。
v1.0.1
2014-03-25 00:01 UTC
Requires
- php: >=5.3.3
- ircmaxell/random-lib: 1.0.*@dev
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
- symfony/http-foundation: 2.4.*@dev
Suggests
- ext-mongo: for using mongodb backend
- ext-pdo_pgsql: for using postgresql backend
This package is not auto-updated.
Last update: 2024-09-24 06:34:52 UTC
README
track 是一个基于事件的跟踪系统,帮助您收集和查询基于客户、用户或访客行为的统计数据。
使用 track 您可以;
- 收集网页浏览量、点击、转化或任何类型的用户行为。
- 使用复杂过滤器查询收集的数据(目前仅支持原生查询)。
- 创建漏斗(进行中)
特性
- 使用无限定制的参数收集数据。
new Event( 'Purchase', array( 'Affiliate' => 'Amazon.de', 'Category' => 'Smartphones', 'Product Name' => 'iPhone 5s Black 64GB', 'Price' => 549.99, //... ) );
- 查询收集的数据并创建分析。
- 创建漏斗(进行中)
- 重复/唯一过滤(进行中)
- 多种数据库后端选项(目前仅支持 mongodb 和 postgresql with hstore)
- 易于扩展的架构。
- 使用 phpspec 实现全面测试覆盖。
事件
一个 event 基本上定义了与名称相同的东西。客户、用户或应用程序执行的任何类型的操作都可以描述为一个事件。例如;'页面浏览', '按钮点击', '购买', 'API 请求', '异常' 等。
Track 在特殊的 Event 对象中定义事件。一个 Event 对象可以携带许多特殊信息,包括自定义信息。例如,一个事件对象可以具有;
- IP 地址,
- 一个唯一键来区分您的用户,
- 事件的时刻,
- 请求的 URL,
- 产品类别,
- 产品名称,
- 客户来源,
- 以及您定义的许多其他信息。
Track 随带一些针对不同目的的内置事件。所有内置事件都可以在 Track\Event 命名空间下找到。您也可以根据自己的需求定义自定义事件。
内置事件
Track 随带一些针对不同目的的内置事件。所有内置事件都可以在 Track\Event 命名空间下找到。
1. Track\Event
这是 Track 的基本事件,提供对事件非常基本的要求。所有其他事件都必须扩展它,这意味着每个事件至少要有 name、timestamp 和唯一的 id。如果您在初始化事件对象时没有提供这些值,它们将由 Track 自动生成。
$event = new Track\Event( 'Page View', // Event name array( 'utm_source' => 'partner_x', 'utml_medium' => 'affiliate', ) ); print_r($event->toArray()); /* will give you like the following array( 'timestamp' => 'timestamp', 'id' => 'random_string', 'utm_source' => 'partner_x', 'utml_medium' => 'affiliate' ) */
示例
存储事件
use Track\Client; use Track\Storage\MongoDBStorage; use Track\Event\Event; // Configure your mongodb connection $mongoClient = new \MongoClient(); $mongoDB = $mongoClient->selectDB('stats'); // Initialize the storage $storage = new MongoDBStorage($mongoDB); $client = new Client($storage); // Create an event for your needs $event = new Event( 'Purchase', array( 'Affiliate' => 'Amazon.de', 'Category' => 'Smartphones', 'Product Name' => 'iPhone 5s Black', 'Price' => 549.99, ) ); // Store the event $client->track($event);
查询事件
use Track\Query; use Track\Storage\MongoDBStorage; // Configure your mongodb connection $mongoClient = new \MongoClient(); $mongoDB = $mongoClient->selectDB('stats'); // Initialize the storage $storage = new MongoDBStorage($mongoDB); $query = new Query($storage); $results = $query->native(array('name' => 'Purchase')); /* will return array( array( 'Affiliate' => 'Amazon.de', 'Category' => 'Smartphones', 'Product Name' => 'iPhone 5s Black', 'Price' => 549.99, ... ), ... ) */
PostgreSQL hstore 设置
CREATE EXTENSION IF NOT EXISTS hstore; CREATE TABLE IF NOT EXISTS events ( id serial PRIMARY KEY, data hstore ); -- Some hstore raw query examples SELECT data FROM events WHERE (data->'timestamp')::int > 12345678; SELECT data FROM events WHERE data->'name'= 'Purchase';