Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TeXmacs/plugins/account/progs/liii/account.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""))))

;; 本地
Expand Down
23 changes: 23 additions & 0 deletions devel/201_73.md
Original file line number Diff line number Diff line change
@@ -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` 中调用
4 changes: 4 additions & 0 deletions src/System/Boot/init_texmacs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// 注册信号处理器,确保子进程被正确清理
Expand Down
34 changes: 34 additions & 0 deletions src/Texmacs/Server/tm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QApplication>
#include <QProcess>
#include <QStringList>
#include <QtNetwork/qnetworkaccessmanager.h>
#endif

server* the_server = NULL;
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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
******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/Texmacs/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/Texmacs/tm_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down