injic / laravel-statcounter
Laravel对StatCounter API的集成
2.0.3
2016-03-02 01:20 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.2.*
- myclabs/php-enum: ^1.4
Requires (Dev)
- fzaninotto/faker: ~1.4
- laravel/framework: 5.2.*
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
- symfony/css-selector: 2.8.*|3.0.*
- symfony/dom-crawler: 2.8.*|3.0.*
This package is not auto-updated.
Last update: 2024-09-28 16:31:02 UTC
README
该软件包支持与Laravel框架(v5)一起使用,提供了一个Stat
门面对StatCounter API。您可以在此处找到此软件包的文档。
###安装设置:为了安装,请在您的composer.json
文件中的require
块中添加以下内容
{ "require": { "injic/laravel-statcounter": "2.*", } }
现在,运行composer update
命令。
在Laravel中,定位到文件/config/app.php
。将以下内容添加到providers
数组中
Injic\LaravelStatcounter\LaravelStatcounterServiceProvider::class,
此外,将以下内容添加到aliases
数组中
'Stat' => Injic\LaravelStatcounter\Facades\Stat::class,
发布配置
$ php artisan vendor:publish --provider="Injic\LaravelStatcounter\LaravelStatcounterServiceProvider"
找到位于/config/statcounter.php
中的包配置。您需要填写StatCounter用户名、API密码和项目信息。由于配置文件包含有关各个值的进一步信息,以下是一些注意事项
username
是StatCounter的区分大小写的登录用户名password
指的是API密码,不是登录密码(见API密码)default
必须匹配projects
下项目名称之一your-project-name
是StatCounter未指定的唯一值。它是调用处理项目的函数时使用的别名projects
和security-codes
必须具有匹配的键(即项目名称)
###使用方法
Stat
类的方法简化了StatCounter API查询所需的步骤,如StatCounter API文档中所述。此外,Stat
类是根据Laravel数据库查询设计模式构建的,您可以期待类似的方法。
您可以在此处找到此软件包的文档。
###示例
// Retrieve an array of browser objects (http://api.statcounter.com/docs/v3#browsers) $stats = Stat::browsers()->get(); // Retrieve an array of summary objects (http://api.statcounter.com/docs/v3#summary-daily) $now = \Carbon\Carbon::now(); // http://carbon.nesbot.com/ $stats = Stat::summary()->setRange(Granularity::DAILY, $now->subWeek(), $now)->get(); // Paginate the recent visitor objects (http://api.statcounter.com/docs/v3#visitors) // https://laravel.net.cn/docs/5.2/pagination $stats = Stat::recentVisitors()->paginate(20); // Add new project to StatCounter with the project name, project url, and project timezone $project Stat::addProject('project-name','www.example.com','America/Chicago');
<html> <body> <!-- Prints the StatCounter tracker using Laravel Templates --> {!! Stat::tracker() !!} </body> </html>