Browse Source

add ga code support

master
filesite 7 months ago
parent
commit
f7dc798f1e
  1. 3
      conf/app.php
  2. 20
      plugins/Html.php
  3. 1
      themes/beauty/views/layout/main.php
  4. 1
      themes/googleimage/views/layout/main.php
  5. 1
      themes/manual/views/layout/main.php
  6. 1
      themes/tajian/views/layout/index.php
  7. 1
      themes/tajian/views/layout/main.php
  8. 1
      themes/videoblog/views/layout/main.php
  9. 1
      themes/webdirectory/views/layout/main.php
  10. 9
      views/layout/error.php
  11. 9
      views/layout/main.php

3
conf/app.php

@ -127,6 +127,9 @@ $configs = array( @@ -127,6 +127,9 @@ $configs = array(
'service_3rd_api_key' => '你的密钥',
'sms_code_cache_time' => 600, //短信验证码缓存时长,单位:秒
//Google Analytics MEASUREMENT ID
'GA_MEASUREMENT_ID' => 'G-09MWT3Z9R0',
);
//自定义配置支持

20
plugins/Html.php

@ -73,4 +73,24 @@ Class Html { @@ -73,4 +73,24 @@ Class Html {
return $sorted;
}
//生成GA统计代码
public static function getGACode() {
$msid = !empty(FSC::$app['config']['GA_MEASUREMENT_ID']) ? FSC::$app['config']['GA_MEASUREMENT_ID'] : '';
if (empty($msid)) {return '';}
$gacode = <<<eof
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={$msid}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{$msid}');
</script>
eof;
return $gacode;
}
}

1
themes/beauty/views/layout/main.php

@ -91,5 +91,6 @@ eof; @@ -91,5 +91,6 @@ eof;
<script src="/js/lazyload.js"></script>
<script src="/js/fubox.min.js"></script>
<script src="/js/beauty.js?v<?= Html::getStaticFileVersion('beauty.js', 'js') ?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

1
themes/googleimage/views/layout/main.php

@ -113,5 +113,6 @@ eof; @@ -113,5 +113,6 @@ eof;
<script src="/js/lazysizes.min.js"></script>
<script src="/js/blueimp-gallery.min.js"></script>
<script src="/js/googleimage.js?v<?=Html::getStaticFileVersion('googleimage.js', 'js')?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

1
themes/manual/views/layout/main.php

@ -42,5 +42,6 @@ include_once $viewFile; @@ -42,5 +42,6 @@ include_once $viewFile;
<script src="/js/main.js?v.1.0"></script>
<!--for theme manual-->
<script src="/js/manual.js?v<?=Html::getStaticFileVersion('manual.js', 'js')?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

1
themes/tajian/views/layout/index.php

@ -52,5 +52,6 @@ if (!empty($viewFile) && file_exists($viewFile)) { @@ -52,5 +52,6 @@ if (!empty($viewFile) && file_exists($viewFile)) {
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/lazyload.js"></script>
<script src="/js/tajian.js?v<?=Html::getStaticFileVersion('tajian.js', 'js')?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

1
themes/tajian/views/layout/main.php

@ -148,5 +148,6 @@ eof; @@ -148,5 +148,6 @@ eof;
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/lazyload.js"></script>
<script src="/js/tajian.js?v<?=Html::getStaticFileVersion('tajian.js', 'js')?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

1
themes/videoblog/views/layout/main.php

@ -74,5 +74,6 @@ eof; @@ -74,5 +74,6 @@ eof;
<script src="/js/lazysizes.min.js"></script>
<script src="/js/video.min.js"></script>
<script src="/js/videoblog.js?v<?=Html::getStaticFileVersion('videoblog.js', 'js')?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

1
themes/webdirectory/views/layout/main.php

@ -67,5 +67,6 @@ eof; @@ -67,5 +67,6 @@ eof;
<script src="/js/main.js?v.1.0"></script>
<!--for theme webdirectory-->
<script src="/js/webdirectory.js?v<?=Html::getStaticFileVersion('webdirectory.js', 'js')?>"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>

9
views/layout/error.php

@ -1,4 +1,8 @@ @@ -1,4 +1,8 @@
<!DocType html>
<?php
//常用方法
require_once __DIR__ . '/../../plugins/Html.php';
?><!DocType html>
<head>
<meta charset="utf-8">
<title><?php echo $errors['title']; ?></title>
@ -14,5 +18,6 @@ h1{color:#FF0000} @@ -14,5 +18,6 @@ h1{color:#FF0000}
<h1><?php echo $errors['title']; ?></h1>
<h3>Exception <?php echo $errors['code']; ?>:</h3>
<div class="error"><?php echo $errors['content']; ?></div>
<?php echo Html::getGACode(); ?>
</body>
</html>
</html>

9
views/layout/main.php

@ -1,4 +1,8 @@ @@ -1,4 +1,8 @@
<!DocType html>
<?php
//常用方法
require_once __DIR__ . '/../../plugins/Html.php';
?><!DocType html>
<html>
<head>
<meta charset="utf-8">
@ -22,5 +26,6 @@ include_once $viewFile; @@ -22,5 +26,6 @@ include_once $viewFile;
<script src="/js/js.cookie.min.js"></script>
<script src="/js/main.js?v.1.0"></script>
<?php echo Html::getGACode(); ?>
</body>
</html>
</html>
Loading…
Cancel
Save