Eric Bower
·
29 Nov 24
analytics.go
1package main
2
3import (
4 "log/slog"
5 "os"
6
7 "github.com/picosh/pico/db"
8 "github.com/picosh/pico/db/postgres"
9 "github.com/picosh/utils"
10)
11
12func main() {
13 logger := slog.Default()
14 DbURL := os.Getenv("DATABASE_URL")
15 dbpool := postgres.NewDB(DbURL, logger)
16
17 args := os.Args
18 host := args[1]
19
20 stats, err := dbpool.VisitSummary(
21 &db.SummaryOpts{
22 Origin: utils.StartOfMonth(),
23 Host: host,
24 },
25 )
26 if err != nil {
27 panic(err)
28 }
29
30 for _, s := range stats.Intervals {
31 logger.Info(
32 "interval",
33 "interval", s.Interval,
34 "visitors", s.Visitors,
35 )
36 }
37
38 for _, url := range stats.TopUrls {
39 logger.Info(
40 "url",
41 "url", url.Url,
42 "count", url.Count,
43 )
44 }
45
46 for _, url := range stats.TopReferers {
47 logger.Info(
48 "referer",
49 "url", url.Url,
50 "count", url.Count,
51 )
52 }
53}