|
|
4 лет назад | |
|---|---|---|
| content | 4 лет назад | |
| analytics.go | 4 лет назад | |
| analytics_mock.go | 4 лет назад | |
| go.mod | 4 лет назад | |
| go.sum | 4 лет назад | |
| readme.md | 4 лет назад |
A minimal analytics package to start collecting traffic data without client dependencies.
analytics := NewAnalytics(AnalyticsConfiguration{
Name: "sanjuanpuertorico",
Password: os.Getenv("DASHBOARD_KEY"),
GroupByURLSegment: 1,
EntriesByURLSegment: 2,
WriteScheduleSeconds: 30,
Directory: "logs",
HashIPSecret: os.Getenv("HASH_IP_KEY"),
UserAgentBlackList: DefaultUserAgentBlacklist,
}, fmt.Println)
router.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
analytics.InsertRequest(r)
next.ServeHTTP(w, r)
})
})
router.HandleFunc("/analytics", analytics.Dashboard).Methods("GET")
type AnalyticsConfiguration struct {
HashIPSecret string
GroupByURLSegment int
EntriesByURLSegment int
WriteScheduleSeconds int
Name string
Password string
Directory string
UserAgentBlackList []string
}
HashIPSecretis a seed that if provided will be used to hash the IP so you don't have plaintext user IPs stored
GroupByURLSegmentindex in the URL split by/to group the results
EntriesByURLSegmentindex in the URL split by/to count as results
WriteScheduleSecondshow often we write to the file Name of file
Directoryparent directory for the log files
Passwordfor a dashboard if it's used /analytics?k=mypassword
UserAgentBlacklistentries to check if the user agent contains in order to avoid things like bots or automated tests