Browse Source

add google adwords track support

master
filesite 6 months ago
parent
commit
fd40b538da
  1. 3
      conf/app.php
  2. 11
      plugins/Html.php

3
conf/app.php

@ -136,6 +136,9 @@ $configs = array(
//Google Analytics MEASUREMENT ID //Google Analytics MEASUREMENT ID
'GA_MEASUREMENT_ID' => 'G-09MWT3Z9R0', 'GA_MEASUREMENT_ID' => 'G-09MWT3Z9R0',
//Google Adwords目标跟踪ID
'GAD_MEASUREMENT_ID' => '',
); );
//自定义配置支持 //自定义配置支持

11
plugins/Html.php

@ -80,6 +80,8 @@ Class Html {
$msid = !empty(FSC::$app['config']['GA_MEASUREMENT_ID']) ? FSC::$app['config']['GA_MEASUREMENT_ID'] : ''; $msid = !empty(FSC::$app['config']['GA_MEASUREMENT_ID']) ? FSC::$app['config']['GA_MEASUREMENT_ID'] : '';
if (empty($msid)) {return '';} if (empty($msid)) {return '';}
$adwords_id = !empty(FSC::$app['config']['GAD_MEASUREMENT_ID']) ? FSC::$app['config']['GAD_MEASUREMENT_ID'] : '';
$gacode = <<<eof $gacode = <<<eof
<!-- Google tag (gtag.js) --> <!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={$msid}"></script> <script async src="https://www.googletagmanager.com/gtag/js?id={$msid}"></script>
@ -89,6 +91,15 @@ Class Html {
gtag('js', new Date()); gtag('js', new Date());
gtag('config', '{$msid}'); gtag('config', '{$msid}');
eof;
if (!empty($adwords_id)) {
$gacode .= <<<eof
gtag('config', '{$adwords_id}');
eof;
}
$gacode .= <<<eof
</script> </script>
eof; eof;

Loading…
Cancel
Save