PluginProbe
WPJAM Basic / trunk
WPJAM Basic vtrunk
wpjam-basic / extends / wpjam-stats.php

wpjam-stats.php in WPJAM Basic trunk, at extends/wpjam-stats.php

54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Name: 统计代码
4 URI: https://mp.weixin.qq.com/s/C_Dsjy8ahr_Ijmcidk61_Q
5 Description: 统计代码扩展最简化插�
6 � Google 分析和百度统计的代码。
7 Version: 1.0
8 */
9 class WPJAM_Site_Stats{
10 public static function get_fields(){
11 return ['stats' => ['title'=>'统计代码', 'type'=>'fieldset', 'wrap_tag'=>'fieldset', 'fields'=>[
12 'baidu_tongji_id' =>['title'=>'百度统计 ID:', 'type'=>'text'],
13 'google_analytics_id' =>['title'=>'Google分析 ID:', 'type'=>'text'],
14 ]]];
15 }
16
17 public static function add_hooks(){
18 wpjam_once('wp_head', function(){
19 if(is_preview()){
20 return;
21 }
22
23 $id = WPJAM_Custom::get_setting('google_analytics_id');
24
25 $id && wpjam_echo(<<<JS
26 <script async src="https://www.googletagmanager.com/gtag/js?id=$id"></script>
27 <script>
28 window.dataLayer = window.dataLayer || [];
29 function gtag(){dataLayer.push(arguments);}
30 gtag('js', new Date());
31
32 gtag('config', '$id');
33 </script>
34 JS);
35
36 $id = WPJAM_Custom::get_setting('baidu_tongji_id');
37
38 $id && wpjam_echo(<<<JS
39 <script type="text/javascript">
40 var _hmt = _hmt || [];
41 (function(){
42 var hm = document.createElement("script");
43 hm.src = "https://hm.baidu.com/hm.js?$id";
44 hm.setAttribute('async', 'true');
45 document.getElementsByTagName('head')[0].appendChild(hm);
46 })();
47 </script>
48 JS);
49 }, 11);
50 }
51 }
52
53 wpjam_add_option_section('wpjam-custom', ['model'=>'WPJAM_Site_Stats']);
54