Last update at :2024-06-01,Edit by888u
Baidu webmaster statistics are still the mainstream website statistics in mainland China. Many webmasters look at their website data every day to check their traffic direction, visitor origin, popular website keywords, popular website pages, etc. What I look at the most is the number of page views, the number of visitors, and the number of IPs.
In this way, you can see the general data of Baidu statistics as long as you log in to the backend of your WordPress site. Isn't it much more convenient?
Add Baidu statistics module
WordPress Baidu statistics can be implemented through the function function. You only need to add the following code to the functions.php
file in the current theme directory:
//Add Baidu statistical data display module to WordPress dashboard - https://wpexp.cn/?p=86
function wpexp_add_dashboard_widgets() {
wp_add_dashboard_widget('custom_help_widget', 'Baidu statistics', 'bdtj_dashboard_wpexp');
}
add_action('wp_dashboard_setup', 'wpexp_add_dashboard_widgets' );
function bdtj_dashboard_wpexp() {
$body = array('header'=>array(
'username' => 'Baidu statistics account',
'password' => 'Baidu statistics password',
'token'=>'Baidu statistics token',
'account_type'=>1
),'body'=>array(
'site_id'=>'Baidu statistics site ID',
'start_date'=>date("Y-m-d",strtotime("-1 day")),
'end_date'=>date("Y-m-d"),
'metrics'=>'pv_count,visitor_count,ip_count',
'method'=>'overview/getTimeTrendRpt'
));
$url='https://api.baidu.com/json/tongji/v1/ReportService/getData';//Baidu business account request address
$request = new WP_Http;
$result = $request->request( $url, array( 'method' => 'POST', 'body' => json_encode($body)) );
$rst=json_decode($result['body']);
$yest=$rst->body->data[0]->result->items[1][0];
$nowt=$rst->body->data[0]->result->items[1][1];
echo 'Date    Views    Number of visitors    IP number';
echo '';
echo 'Today:    ';
for($i=0;$i';
echo 'Yesterday:    ';
for($i=0;$i
The HTTP request class that comes with WordPress is used, and Curl is not used to submit the Post request.
Get code related parameters
You can apply to activate the Token value of Baidu Statistics by yourself: select the corresponding site in the upper right corner of Baidu Statistics, click Management
on the top navigation menu, and then find Other Settings
at the bottom of the left menu code>→Data Export Service
, choose to activate it to get the Baidu Statistics Token value. See the figure below for details:
For Baidu statistics site ID, you can click Website Profile
, and then there will be a siteId=1234567
at the end of the address bar. This string of corresponding numbers is the site ID.
Recommended site searches: domain name value evaluation, Zhejiang server, personal domain name registration, Singapore server, buying space network, com domain name registration, public welfare free virtual host, Jiangsu high defense server, domain name registration network, website registration system,
发表评论