@@ -46,6 +46,16 @@ type UIHeader struct {
46
46
Logo string `yaml:"logo"`
47
47
}
48
48
49
+ type Analytics struct {
50
+ Type string `yaml:"type"`
51
+ Umami AnalyticsUmami `yaml:"umami"`
52
+ }
53
+
54
+ type AnalyticsUmami struct {
55
+ Script string `yaml:"script"`
56
+ WebsiteID string `yaml:"websiteID"`
57
+ }
58
+
49
59
type Metrics struct {
50
60
Enabled bool `yaml:"enabled"`
51
61
Port int `yaml:"port"`
@@ -76,6 +86,8 @@ type Config struct {
76
86
Refresh time.Duration `yaml:"refresh"`
77
87
78
88
UI UI `yaml:"ui"`
89
+
90
+ Analytics Analytics `yaml:"analytics"`
79
91
}
80
92
81
93
func Load (path string ) (* Config , error ) {
@@ -159,6 +171,10 @@ func setDefaults(conf *Config) {
159
171
if conf .UI .Theme == "" {
160
172
conf .UI .Theme = "light"
161
173
}
174
+
175
+ if conf .Analytics .Type == "" {
176
+ conf .Analytics .Type = "none"
177
+ }
162
178
}
163
179
164
180
func setDefaultQueryValues (q * Query ) {
@@ -216,6 +232,30 @@ func (c *Config) Validate() error {
216
232
}
217
233
}
218
234
235
+ analyticsTypeValid := false
236
+ analyticsTypes := []string {
237
+ "none" ,
238
+ "umami" ,
239
+ }
240
+
241
+ for _ , val := range analyticsTypes {
242
+ if val == c .Analytics .Type {
243
+ analyticsTypeValid = true
244
+ }
245
+ }
246
+ if ! analyticsTypeValid {
247
+ return errors .New ("unsupportet analytics type" )
248
+ }
249
+
250
+ if c .Analytics .Type == "umami" {
251
+ if c .Analytics .Umami .Script == "" {
252
+ return errors .New ("analytics umami script must be set" )
253
+ }
254
+ if c .Analytics .Umami .WebsiteID == "" {
255
+ return errors .New ("analytics umami websiteID must be set" )
256
+ }
257
+ }
258
+
219
259
return nil
220
260
}
221
261
0 commit comments