From bd27a3dccb1136b792a83bcfb4ba1720b9d13174 Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 7 Jun 2025 21:36:34 +0800 Subject: [PATCH] add adwords conversion support --- conf/app.php | 4 ++++ plugins/Html.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/conf/app.php b/conf/app.php index a1a7b05..191c84f 100644 --- a/conf/app.php +++ b/conf/app.php @@ -200,6 +200,10 @@ $configs = array( //Google Adwords目标跟踪ID 'GAD_MEASUREMENT_ID' => '', + //Google Adwords conversion配置 + //示例:{'controller': 'xx', 'action': 'yy', 'send_to': 'zzz'} + 'GA_MEASUREMENT_CONVERSIONS' => [], + //密码授权默认关闭 "password_auth" => array( "enable" => false, diff --git a/plugins/Html.php b/plugins/Html.php index 39112c9..dd4cf35 100644 --- a/plugins/Html.php +++ b/plugins/Html.php @@ -98,6 +98,7 @@ Class Html { } //生成GA统计代码 + //支持conversion代码,示例:gtag('event', 'conversion', {'send_to': 'xxx/NUaEOrczuQD'}); public static function getGACode() { if (!empty(FSC::$app['config']['debug'])) {return '';} $msid = !empty(FSC::$app['config']['GA_MEASUREMENT_ID']) ? FSC::$app['config']['GA_MEASUREMENT_ID'] : ''; @@ -123,6 +124,22 @@ eof; eof; } + + if (!empty(FSC::$app['config']['GA_MEASUREMENT_CONVERSIONS'])) { + $conversions = FSC::$app['config']['GA_MEASUREMENT_CONVERSIONS']; + //格式:{'controller': 'xx', 'action': 'yy', 'send_to': 'zzz'} + foreach ($conversions as $item) { + if (FSC::$app['controller'] == $item['controller'] && FSC::$app['action'] == $item['action']) { + gacode .= << eof;