injic/laravel-statcounter

Laravel对StatCounter API的集成

2.0.3 2016-03-02 01:20 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:31:02 UTC


README

Latest Stable Version License

该软件包支持与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未指定的唯一值。它是调用处理项目的函数时使用的别名
  • projectssecurity-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>