From 368f2bb17971aefd1ca2f7ab77d1003019b27ecd Mon Sep 17 00:00:00 2001 From: jiadong Date: Thu, 5 Feb 2026 14:31:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[201=5F72]=20=E7=94=A8=E6=88=B7=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=E5=88=86=E6=9E=90=E5=8A=9F=E8=83=BD-=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=20analyticsToSendUseAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/account/progs/liii/account.scm | 1 + devel/201_72.md | 23 +++++++++++++ src/System/Boot/init_texmacs.cpp | 4 +++ src/Texmacs/Server/tm_server.cpp | 33 +++++++++++++++++++ src/Texmacs/server.hpp | 1 + src/Texmacs/tm_server.hpp | 1 + 6 files changed, 63 insertions(+) create mode 100644 devel/201_72.md diff --git a/TeXmacs/plugins/account/progs/liii/account.scm b/TeXmacs/plugins/account/progs/liii/account.scm index e3b076c1e3..c60d983f06 100644 --- a/TeXmacs/plugins/account/progs/liii/account.scm +++ b/TeXmacs/plugins/account/progs/liii/account.scm @@ -88,6 +88,7 @@ ((== key "user-info-url") (string-append base-url "/api/v1/oauth2/membershipInfo")) ((== key "pricing-url") (string-append base-url "/pricing.html")) ((== key "click-return-liii-url") "https://liiistem.cn/?from=login_button") + ((== key "user-action-url") (string-append base-url "/api/v1/analytics/userAction")) (else "")))) ;; 本地 diff --git a/devel/201_72.md b/devel/201_72.md new file mode 100644 index 0000000000..641bf1bd0d --- /dev/null +++ b/devel/201_72.md @@ -0,0 +1,23 @@ +# [201_72] 用户行为分析功能 + +## 如何测试 +编译启动观察终端日志 +``` bash +# 启动时出现 +Starting event loop... +2026-02-05-14.24.25.367 TeXmacs] Sent user action analytics: open +# 关闭时出现 +2026-02-05-14.24.37.279 TeXmacs] Stopping the server... +2026-02-05-14.24.37.280 TeXmacs] Sent user action analytics: close +``` + +## 2026/02/05 实现 analyticsToSendUseAction +### what +通过异步 HEAD 请求上报用户行为数据到 analytics 接口。 +- URL: 通过 Scheme 函数 `account-oauth2-config` 获取 +- Product: 社区版为 "mogan",商业版为 "liiistem" +- 异步请求,无需等待结果 + +### 调用时机 +- 启动时: 在 C++ 层 `init_texmacs.cpp` 中调用 +- 退出时: 在 C++ 层 `tm_server.cpp` 中调用 \ No newline at end of file diff --git a/src/System/Boot/init_texmacs.cpp b/src/System/Boot/init_texmacs.cpp index 5099d22b1b..809a86db38 100644 --- a/src/System/Boot/init_texmacs.cpp +++ b/src/System/Boot/init_texmacs.cpp @@ -944,6 +944,10 @@ TeXmacs_main (int argc, char** argv) { bench_reset ("initialize scheme"); if (DEBUG_STD) debug_boot << "Starting event loop...\n"; + + // Send open action analytics + get_server()->analyticsToSendUseAction ("open"); + texmacs_started= true; if (!disable_error_recovery) { // 注册信号处理器,确保子进程被正确清理 diff --git a/src/Texmacs/Server/tm_server.cpp b/src/Texmacs/Server/tm_server.cpp index 51300e392d..e266b3e97d 100644 --- a/src/Texmacs/Server/tm_server.cpp +++ b/src/Texmacs/Server/tm_server.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #endif server* the_server = NULL; @@ -309,6 +310,8 @@ tm_server_rep::is_yes (string s) { void tm_server_rep::quit () { debug_automatic << "Stopping the server..." << LF; + + analyticsToSendUseAction ("close"); close_all_pipes (); call ("quit-TeXmacs-scheme"); clear_pending_commands (); @@ -353,6 +356,36 @@ tm_server_rep::is_logged_in () { return m_account->isLoggedIn (); } +/****************************************************************************** + * User action analytics + ******************************************************************************/ + +/*! + * \brief Send user action analytics data + * + * Sends user behavior statistics to the server via HTTP HEAD request + * for product analytics. Supports recording user actions like + * "open" and "close" events. + * + * \param action User action type, e.g., "open", "close" + * + * \note This method works without a window, suitable for startup scenarios + */ +void +tm_server_rep::analyticsToSendUseAction (string action) { + string product = is_community_stem () ? "mogan" : "liiistem"; + + eval ("(use-modules (liii account))"); + string url_base = as_string (call ("account-oauth2-config", "user-action-url")); + string full_url = url_base * "?action=" * action * "&product=" * product; + + QNetworkAccessManager* manager = new QNetworkAccessManager (); + QUrl url (to_qstring (full_url)); + QNetworkRequest request (url); + manager->head (request); // asynchronous + debug_automatic << "Sent user action analytics: " << action << "\n"; +} + /****************************************************************************** * System commands ******************************************************************************/ diff --git a/src/Texmacs/server.hpp b/src/Texmacs/server.hpp index 2fd0243d5a..77386b8200 100644 --- a/src/Texmacs/server.hpp +++ b/src/Texmacs/server.hpp @@ -120,6 +120,7 @@ class server_rep : public abstract_struct { virtual void shell (string s) = 0; virtual void login () = 0; virtual bool is_logged_in () = 0; + virtual void analyticsToSendUseAction (string action)= 0; }; class server { diff --git a/src/Texmacs/tm_server.hpp b/src/Texmacs/tm_server.hpp index 2d3706bb85..906741dd96 100644 --- a/src/Texmacs/tm_server.hpp +++ b/src/Texmacs/tm_server.hpp @@ -52,6 +52,7 @@ class tm_server_rep : public tm_config_rep, public tm_frame_rep { void shell (string s); void login (); bool is_logged_in (); + void analyticsToSendUseAction (string action); QTMOAuth* getAccount () const { return m_account; } From 4822b41a353680c07fed3f9c5a524d4f978f5896 Mon Sep 17 00:00:00 2001 From: jiadong Date: Thu, 5 Feb 2026 14:32:35 +0800 Subject: [PATCH 2/3] fix --- devel/{201_72.md => 201_73.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename devel/{201_72.md => 201_73.md} (95%) diff --git a/devel/201_72.md b/devel/201_73.md similarity index 95% rename from devel/201_72.md rename to devel/201_73.md index 641bf1bd0d..922407c9ab 100644 --- a/devel/201_72.md +++ b/devel/201_73.md @@ -1,4 +1,4 @@ -# [201_72] 用户行为分析功能 +# [201_73] 用户行为分析功能 ## 如何测试 编译启动观察终端日志 From bb5bf58ef6ebcaef4616729f7730c46a2cd77440 Mon Sep 17 00:00:00 2001 From: jiadong Date: Thu, 5 Feb 2026 16:00:39 +0800 Subject: [PATCH 3/3] format --- src/System/Boot/init_texmacs.cpp | 2 +- src/Texmacs/Server/tm_server.cpp | 13 +++++++------ src/Texmacs/server.hpp | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/System/Boot/init_texmacs.cpp b/src/System/Boot/init_texmacs.cpp index 809a86db38..394d83fa9f 100644 --- a/src/System/Boot/init_texmacs.cpp +++ b/src/System/Boot/init_texmacs.cpp @@ -946,7 +946,7 @@ TeXmacs_main (int argc, char** argv) { if (DEBUG_STD) debug_boot << "Starting event loop...\n"; // Send open action analytics - get_server()->analyticsToSendUseAction ("open"); + get_server ()->analyticsToSendUseAction ("open"); texmacs_started= true; if (!disable_error_recovery) { diff --git a/src/Texmacs/Server/tm_server.cpp b/src/Texmacs/Server/tm_server.cpp index e266b3e97d..0ad6ee825b 100644 --- a/src/Texmacs/Server/tm_server.cpp +++ b/src/Texmacs/Server/tm_server.cpp @@ -373,15 +373,16 @@ tm_server_rep::is_logged_in () { */ void tm_server_rep::analyticsToSendUseAction (string action) { - string product = is_community_stem () ? "mogan" : "liiistem"; + string product= is_community_stem () ? "mogan" : "liiistem"; eval ("(use-modules (liii account))"); - string url_base = as_string (call ("account-oauth2-config", "user-action-url")); - string full_url = url_base * "?action=" * action * "&product=" * product; + string url_base= + as_string (call ("account-oauth2-config", "user-action-url")); + string full_url= url_base * "?action=" * action * "&product=" * product; - QNetworkAccessManager* manager = new QNetworkAccessManager (); - QUrl url (to_qstring (full_url)); - QNetworkRequest request (url); + QNetworkAccessManager* manager= new QNetworkAccessManager (); + QUrl url (to_qstring (full_url)); + QNetworkRequest request (url); manager->head (request); // asynchronous debug_automatic << "Sent user action analytics: " << action << "\n"; } diff --git a/src/Texmacs/server.hpp b/src/Texmacs/server.hpp index 77386b8200..797634d433 100644 --- a/src/Texmacs/server.hpp +++ b/src/Texmacs/server.hpp @@ -120,7 +120,7 @@ class server_rep : public abstract_struct { virtual void shell (string s) = 0; virtual void login () = 0; virtual bool is_logged_in () = 0; - virtual void analyticsToSendUseAction (string action)= 0; + virtual void analyticsToSendUseAction (string action) = 0; }; class server {