/
count.go
89 lines (79 loc) · 2.6 KB
/
count.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package analytic
import (
"fmt"
"time"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/util/uuid"
)
const (
CumulativeUserCountType = "cumulative.user"
MonthlyActiveUserCountType = "monthly.active_user"
WeeklyActiveUserCountType = "weekly.active_user"
DailyActiveUserCountType = "daily.active_user"
DailySignupCountType = "daily.signup"
DailySignupPageViewCountType = "daily.page_view.signup"
DailySignupUniquePageViewCountType = "daily.unique_page_view.signup"
DailyLoginPageViewCountType = "daily.page_view.login"
DailyLoginUniquePageViewCountType = "daily.unique_page_view.login"
// nolint: gosec
DailySignupWithLoginIDCountType = "daily.signup.login_id.%s"
DailySignupWithOAuthCountType = "daily.signup.oauth.%s"
DailySignupAnonymouslyCountType = "daily.signup.anonymous"
)
type DailySignupCountTypeByMethod struct {
// MethodName is the name of method
// It could be LoginIDKeyType or OAuthSSOProviderType. e.g. (email, username, google, anonymous)
MethodName string
CountType string
}
var DailySignupCountTypeByMethods = []*DailySignupCountTypeByMethod{}
func init() {
for _, typ := range model.LoginIDKeyTypes {
DailySignupCountTypeByMethods = append(DailySignupCountTypeByMethods, &DailySignupCountTypeByMethod{
string(typ), fmt.Sprintf(DailySignupWithLoginIDCountType, typ),
})
}
for _, typ := range config.OAuthSSOProviderTypes {
DailySignupCountTypeByMethods = append(DailySignupCountTypeByMethods, &DailySignupCountTypeByMethod{
string(typ), fmt.Sprintf(DailySignupWithOAuthCountType, typ),
})
}
DailySignupCountTypeByMethods = append(DailySignupCountTypeByMethods, &DailySignupCountTypeByMethod{
"anonymous", DailySignupAnonymouslyCountType,
})
}
type Count struct {
ID string
AppID string
Count int
Date time.Time
Type string
}
func NewCount(appID string, count int, date time.Time, typ string) *Count {
return &Count{
ID: uuid.New(),
AppID: appID,
Count: count,
Date: date,
Type: typ,
}
}
func NewDailySignupWithLoginID(appID string, count int, date time.Time, loginIDType string) *Count {
return &Count{
ID: uuid.New(),
AppID: appID,
Count: count,
Date: date,
Type: fmt.Sprintf(DailySignupWithLoginIDCountType, loginIDType),
}
}
func NewDailySignupWithOAuth(appID string, count int, date time.Time, provider string) *Count {
return &Count{
ID: uuid.New(),
AppID: appID,
Count: count,
Date: date,
Type: fmt.Sprintf(DailySignupWithOAuthCountType, provider),
}
}