G-Bruin / lumen-baidutongji by G-Bruin

lumen 百度统计集成包
259
0
1
Package Data
Maintainer Username: G-Bruin
Package Create Date: 2018-06-29
Package Last Update: 2018-07-25
Language: PHP
License: MIT
Last Refreshed: 2024-11-08 03:09:49
Package Statistics
Total Downloads: 259
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

lumen-baidutongji

请参考百度统计文档使用,本项目适用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);
    }
}