diff --git a/app/src/constants.ts b/app/src/constants.ts index 72bbe00c0..62d106e00 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -427,4 +427,7 @@ export abstract class Constants { // third "yul", "solidity", "abap", ]; + + // Google Analytics 事件 + public static readonly ANALYTICS_EVT_ON_GET_CONFIG: string = "siyuan.onGetConfig"; } diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 5fdce99a7..73223eba8 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -160,9 +160,23 @@ export const onGetConfig = (isStart: boolean) => { mountHelp(); } - window.gtag("event", "config", { + let para = { "version": Constants.SIYUAN_VERSION, - }); + "isLoggedIn": "false", + "subscriptionStatus": "-1", + "subscriptionPlan": "-1", + "subscriptionType": "-1", + } + if (window.siyuan.user) { + para.isLoggedIn = "true"; + if (0 === window.siyuan.user.userSiYuanSubscriptionStatus) { + console.log(window.siyuan.user) + para.subscriptionStatus = window.siyuan.user.userSiYuanSubscriptionStatus.toString(); + para.subscriptionPlan = window.siyuan.user.userSiYuanSubscriptionPlan.toString(); + para.subscriptionType = window.siyuan.user.userSiYuanSubscriptionType.toString(); + } + } + window.gtag("event", Constants.ANALYTICS_EVT_ON_GET_CONFIG, para); }; const initBar = () => { diff --git a/kernel/api/snippet.go b/kernel/api/snippet.go index 90eb6b2a0..6a67b3ddb 100644 --- a/kernel/api/snippet.go +++ b/kernel/api/snippet.go @@ -126,9 +126,11 @@ func removeSnippet(c *gin.Context) { } id := arg["id"].(string) - if err := model.RemoveSnippet(id); nil != err { + snippet, err := model.RemoveSnippet(id) + if nil != err { ret.Code = -1 ret.Msg = "remove snippet failed: " + err.Error() return } -} \ No newline at end of file + ret.Data = snippet +} diff --git a/kernel/conf/user.go b/kernel/conf/user.go index 81660b27f..ad38d7a79 100644 --- a/kernel/conf/user.go +++ b/kernel/conf/user.go @@ -36,6 +36,7 @@ type User struct { UserTrafficTime float64 `json:"userTrafficTime"` UserSiYuanSubscriptionPlan float64 `json:"userSiYuanSubscriptionPlan"` // -2:未订阅,-1:试用,0:标准订阅,1:教育订阅 UserSiYuanSubscriptionStatus float64 `json:"userSiYuanSubscriptionStatus"` // -1:未订阅,0:订阅可用,1:订阅封禁,2:订阅过期 + UserSiYuanSubscriptionType float64 `json:"userSiYuanSubscriptionType"` // 0 年付;1 终生;2 月付 } type UserTitle struct { diff --git a/kernel/model/snippet.go b/kernel/model/snippet.go index 55987cded..d4f66ab06 100644 --- a/kernel/model/snippet.go +++ b/kernel/model/snippet.go @@ -29,7 +29,7 @@ import ( var snippetsLock = sync.Mutex{} -func RemoveSnippet(id string) (err error) { +func RemoveSnippet(id string) (ret *conf.Snippet, err error) { snippetsLock.Lock() defer snippetsLock.Unlock() @@ -40,6 +40,7 @@ func RemoveSnippet(id string) (err error) { for i, s := range snippets { if s.ID == id { + ret = s snippets = append(snippets[:i], snippets[i+1:]...) break } @@ -48,7 +49,7 @@ func RemoveSnippet(id string) (err error) { return } -func SetSnippet(id, name, typ, content string, enabled bool) (snippet *conf.Snippet, err error) { +func SetSnippet(id, name, typ, content string, enabled bool) (ret *conf.Snippet, err error) { snippetsLock.Lock() defer snippetsLock.Unlock() @@ -64,15 +65,15 @@ func SetSnippet(id, name, typ, content string, enabled bool) (snippet *conf.Snip s.Type = typ s.Content = content s.Enabled = enabled - snippet = s + ret = s isUpdate = true break } } if !isUpdate { - snippet = &conf.Snippet{ID: id, Name: name, Type: typ, Content: content, Enabled: enabled} - snippets = append(snippets, snippet) + ret = &conf.Snippet{ID: id, Name: name, Type: typ, Content: content, Enabled: enabled} + snippets = append(snippets, ret) } err = writeSnippetsConf(snippets) return