wordpress解决百度统计被刷广告的办法

wordpress yekong 321℃

百度统计被刷

百度统计被刷

百度统计被刷原理

他们是这样做的,先写一个机器爬虫,爬取页面内容,寻找「hm.baidu.com/hm.js」如果找到了就说明你使用了百度统计,然后再取后面的参数,就得到了你的百度统计ID,然后保存到数据库,拿到你的的百度统计ID以后,就可以进行下一步,使用程序批量的给百度统计接口发送数据,也就是说这些内容他们根本不是真的去你的网站,而是直接给百度统计的接口提交了数据,对你的网站流量没有任何贡献,你只有看广告的份。

百度统计被刷解决办法


var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?ddd5878cd7981303a5694d73f7e2f222";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();

将百度统计的特征,也就是地址打散成数组,再组装使用:


var _hmt = _hmt || [];
(function() {
    var hm = document.createElement("script");
    var analytics_bd = 'ddd5878cd7981303a5694d73f7e2f222';
    hm.src = ['ht', 't', 'ps', ':/', '/h', 'm', '.', 'ba', 'i', 'd', 'u.c', 'o', 'm/', 'h', 'm', '.j', 's?', analytics_bd].join('');
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
}
)();

我这里使用的是wpjam插件

修改文件wpjam-basic/extends/wpjam-stats.php


<?php
/*
Plugin Name: 统计代码
Plugin URI: https://blog.wpjam.com/project/wpjam-basic/
Description: 自动添加百度统计和 Google 分析代码。
Version: 1.0
*/
add_action('wp_head', function (){

    if(is_preview()) return;

    $remove_query_args  = array('from','isappinstalled','weixin_access_token','weixin_refer');
    $stats_page_url     = remove_query_arg($remove_query_args,$_SERVER["REQUEST_URI"]);
    $stats_page_url     = (is_404())?'/404'.$stats_page_url:$stats_page_url;
    $stats_page_url     = ($stats_page_url == $_SERVER["REQUEST_URI"])?'':$stats_page_url;
    $stats_page_url     = apply_filters('wpjam_stats_page_url', $stats_page_url);
    // ga('require', 'displayfeatures');
    ?>
    <?php if($google_analytics_id = wpjam_basic_get_setting('google_analytics_id')){ ?>
    <!-- Google Analytics Begin-->
    <?php if(wpjam_basic_get_setting('google_universal')){ ?>
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', '<?php echo $google_analytics_id;?>', 'auto');
    ga('set', 'displayFeaturesTask', null);
    <?php if($stats_page_url){?>
    ga('send', 'pageview', '<?php echo $stats_page_url; ?>');
    <?php }else{?>
    ga('send', 'pageview');
    <?php } ?>
    <?php if($form  = wpjam_get_parameter('from')){ ?>
    ga('send', 'event', 'weixin', 'from', '<?php echo esc_js($form);?>');
    <?php } ?>
    </script>
    <?php } else { ?>
    <script type="text/javascript">
    var _gaq = _gaq || [];
    var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
    _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
    _gaq.push(['_setAccount', '<?php echo $google_analytics_id;?>']);
    <?php if($stats_page_url){?>
    _gaq.push(['_trackPageview', '<?php echo $stats_page_url; ?>']);
    <?php }else{?>
    _gaq.push(['_trackPageview']);
    <?php } ?>
    _gaq.push(['_trackPageLoadTime']);
    (function() {
        var ga = document.createElement('script');
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        ga.setAttribute('async', 'true');
        document.getElementsByTagName('head')[0].appendChild(ga);
    })();
    </script>
    <?php } ?>
    <!-- Google Analytics End -->
    <?php } ?>

    <?php if($baidu_tongji_id = wpjam_basic_get_setting('baidu_tongji_id')){ ?>
    <!-- Baidu Tongji Start -->
    <script type="text/javascript">
    var _hmt = _hmt || [];
    <?php if($stats_page_url){?>
    _hmt.push(['_setAutoPageview', false]);
    _hmt.push(['_trackPageview', '<?php echo $stats_page_url; ?>']);
    <?php }else{?>
    _hmt.push(['_trackPageview']);
    <?php } ?>
    <?php if($form  = wpjam_get_parameter('from')){ ?>
    _hmt.push(['_trackEvent', 'weixin', 'from', '<?php echo esc_js($form);?>']);
    <?php } ?>
    (function() {
    var hm = document.createElement("script");
    var analytics_bd ='<?php echo $baidu_tongji_id;?>';
    hm.src = ['ht', 't', 'ps', ':/', '/h', 'm', '.', 'ba', 'i', 'd', 'u.c', 'o', 'm/', 'h', 'm', '.j', 's?', analytics_bd].join('');
    hm.setAttribute('async', 'true');
    document.getElementsByTagName('head')[0].appendChild(hm);
    })();
    </script>
    <!-- Baidu Tongji  End -->
    <?php }

}, 11);

喜欢 (0)