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_73.md b/devel/201_73.md new file mode 100644 index 0000000000..922407c9ab --- /dev/null +++ b/devel/201_73.md @@ -0,0 +1,23 @@ +# [201_73] 用户行为分析功能 + +## 如何测试 +编译启动观察终端日志 +``` 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..394d83fa9f 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..0ad6ee825b 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,37 @@ 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..797634d433 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; }