bruin/baidu-tongji

lumen 百度统计集成包

v1.2.1 2018-07-24 13:02 UTC

This package is auto-updated.

Last update: 2024-11-12 18:15:33 UTC


README

请参考百度统计文档使用,本项目适用lumen和laravel集成包

安装

  1. 安装包文件
composer require Bruin/baidu-tongji

配置

lumen 应用

  1. 注册 AppServiceProvider:
$this->app->register(\Bruin\BaiduTongji\BaiduTongjiServiceProvider::class);
  1. 创建配置文件:
public function boot()
{
    $this->app->configure('baidu_tongji');
}
  1. 复制应用根目录下的 config/baidu_tongji.php

laravel 应用

  1. 注册 ServiceProvider:
Bruin\BaiduTongji\BaiduTongjiServiceProvider::class
  1. 创建配置文件:
php artisan vendor:publish
  1. 修改应用根目录下的 config/baidu_tongji.php

使用 lumen

<?php

namespace App\Http\Controllers;

use Bruin\BaiduTongji\BaiduTongji;

class SiteController extends Controller
{

    public function index()
    {
        $today=date('Ymd');
        $yesterday=date('Ymd',strtotime('yesterday'));
        $baiduTongji = new BaiduTongji(config('baidu_tongji'));
        $result=$baiduTongji->getData([
            'method' => 'trend/time/a',
            'start_date' => $today,
            'end_date' => $today,
            'start_date2' => $yesterday,
            'end_date2' => $yesterday,
            'metrics' => 'pv_count,visitor_count',
            'max_results' => 0,
            'gran' => 'day',
        ]);
        dd($result);
    }
}

使用 laravel

<?php

namespace App\Http\Controllers;

class SiteController extends Controller
{

    public function index()
    {
        $today=date('Ymd');
        $yesterday=date('Ymd',strtotime('yesterday'));
        $baiduTongji = resolve('BaiduTongji');
        $result=$baiduTongji->getData([
            'method' => 'trend/time/a',
            'start_date' => $today,
            'end_date' => $today,
            'start_date2' => $yesterday,
            'end_date2' => $yesterday,
            'metrics' => 'pv_count,visitor_count',
            'max_results' => 0,
            'gran' => 'day',
        ]);
        dd($result);
    }
}