PHP code example of rr-earring / baidu-tongji

1. Go to this page and download the library: Download rr-earring/baidu-tongji library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rr-earring / baidu-tongji example snippets




use RrEarring\BaiduTongji\Factory;

// 当前仅确定百度商业账号可用,百度账号暂无可测试账号

$config = [
    'is_business'   => true, // is business account
    'username'      => '', // business   'log'           => [
        'file' => './baidu-tongji.log', // logfile
    ],
];

$baiduApi = Factory::baiduApi($config);


// sitelist
$baiduApi->list->get();

// overview/getTimeTrendRpt
$baiduApi->time_trend_rpt->get(20220425, 20220426, 'pv_count,visitor_count,ip_count');

// overview/getDistrictRpt
$baiduApi->district_rpt->get(20220425, 20220426, 'pv_count');

// overview/getCommonTrackRpt
$baiduApi->common_track_rpt->get(20220425, 20220426);

// trend/time/a
$baiduApi->time->get(20220425, 20220426, 'pv_count,avg_visit_time', ['gran' => 'day', 'source' => 'through', 'clientDevice' => 'pc', 'area' => 'china']);

// trend/latest/a
$baiduApi->latest->get('area,searchword,visit_time,visit_pages', 'visit_pages,desc', 100, ['source' => 'through', 'area' => 'china']);

// pro/product/a
$baiduApi->product->get(20220425, 20220426, 'show_count,pv_count,bounce_ratio');

// pro/hour/a
$baiduApi->hour->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// source/all/a
$baiduApi->all->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// source/engine/a
$baiduApi->engine->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// source/searchword/a
$baiduApi->searchword->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// source/link/a
$baiduApi->link->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// custom/media/a
$baiduApi->media->get(20220425, 20220426, 'visit_count,visitor_count', 'plan');

// visit/toppage/a
$baiduApi->toppage->get(20220425, 20220426, 'pv_count,visitor_count');

// visit/topdomain/a
$baiduApi->topdomain->get(20220425, 20220426, 'visit_count,visitor_count');

// visit/landingpage/a
$baiduApi->landingpage->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// visit/district/a
$baiduApi->district->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');

// visit/world/a
$baiduApi->world->get(20220425, 20220426, 'pv_count,visit_count,visitor_count');