Slimstat Analytics 是 WordPress 的一款强大的网站访问分析工具,但是该插件对于国内的环境有点水土不服。

下面教大家如何改造 Slimstat Analytics ,使其适合国内的环境。

地理位置设置显示为中文

编辑 /wp-content/plugins/wp-slimstat/wp-slimstat.php 文件,在文件中找到下面的代码,大概在 561 行左右。

if ( !empty( $geolocation_data[ 'city' ][ 'names' ][ 'en' ] ) ) {
    self::$stat[ 'city' ] = $geolocation_data[ 'city' ][ 'names' ][ 'en' ];
}

if ( !empty( $geolocation_data[ 'subdivisions' ][ 0 ][ 'iso_code' ] ) && !empty( self::$stat[ 'city' ] ) ) {
    self::$stat[ 'city' ] .= ' (' . $geolocation_data[ 'subdivisions' ][ 0 ][ 'iso_code' ] . ')';
}

将这段代码改成如下代码即可:

if ( !empty( $geolocation_data[ 'city' ][ 'names' ][ 'zh-CN' ] ) ) {
    self::$stat[ 'city' ] = $geolocation_data[ 'city' ][ 'names' ][ 'zh-CN' ];
} 
else if ( !empty( $geolocation_data[ 'city' ][ 'names' ][ 'en' ] ) ) {
    self::$stat[ 'city' ] = $geolocation_data[ 'city' ][ 'names' ][ 'en' ];
}
else {
    self::$stat[ 'city' ] = '';
}

if ( !empty( $geolocation_data[ 'subdivisions' ][ 0 ][ 'names' ][ 'zh-CN'] ) ) {
    self::$stat[ 'city' ] .= ' (' . $geolocation_data[ 'subdivisions' ][ 0 ][ 'names' ][ 'zh-CN'] . ')';
}
else if ( !empty( $geolocation_data[ 'subdivisions' ][ 0 ][ 'iso_code' ] ) && !empty( self::$stat[ 'city' ] ) ) {
    self::$stat[ 'city' ] .= ' (' . $geolocation_data[ 'subdivisions' ][ 0 ][ 'iso_code' ] . ')';
}

搜索引擎识别增强

增强识别国内的百度、搜狗、搜搜等搜索引擎关键字

编辑 /wp-content/plugins/wp-slimstat/wp-slimstat.php 文件,在文件中找到下面的代码,大概在 880 行左右。

// We weren't lucky, but there's still hope
foreach( array( 'q','s','k','qt' ) as $a_format ) {
    if ( !empty( $query[ $a_format ] ) ) {
        $searchterms = str_replace( '\\', '', trim( urldecode( $query[ $a_format ] ) ) );
        break;
    }
}

将这段代码改成如下代码即可:

// We weren't lucky, but there's still hope
foreach( array( 'q','s','k','qt','w','word','keyword','query' ) as $a_format ) {
    if ( !empty( $query[ $a_format ] ) ) {
        $searchterms = str_replace( '\\', '', trim( urldecode( $query[ $a_format ] ) ) );
        break;
    }
}


原文链接地址:http://blog.exsvc.cn/article/slimstat-analytics-city-display-chinese.html
转载请注明:转载自 易科博客 ,谢谢!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注