From 22b2abb4b8b9c1706c2a5dd67d0d8f7d75be20c4 Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Tue, 23 Sep 2025 15:22:23 +0000 Subject: [PATCH 1/2] improvements for analytics (customize Google Site Verification ID and add support for Umami (github.com/umami-software/umami)) Signed-off-by: Seth Grover --- main.go | 10 +++++++++- pkg/server/server.go | 36 ++++++++++++++++++++++++------------ templates/view.html | 7 ++++++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 9a83410..04100da 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,9 @@ func main() { Flags: []cli.Flag{ cli.StringFlag{Name: "url, u", Value: "localhost", Usage: "public URL to use"}, cli.StringFlag{Name: "port", Value: "8010", Usage: "ports of the local relay"}, + cli.StringFlag{Name: "google-site-verification-id, g", Value: "", Usage: "Google site verification ID"}, + cli.StringFlag{Name: "umami-url", Value: "", Usage: "Umami analytics URL"}, + cli.StringFlag{Name: "umami-id", Value: "", Usage: "Umami analytics ID"}, }, HelpName: "hostyoself relay", Action: func(c *cli.Context) error { @@ -118,6 +121,11 @@ func relay(c *cli.Context) (err error) { flagPublicURL = "http://" + flagPublicURL } - s := server.New(flagPublicURL, c.String("port")) + s := server.New( + flagPublicURL, + c.String("port"), + c.String("google-site-verification-id"), + c.String("umami-url"), + c.String("umami-id")) return s.Run() } diff --git a/pkg/server/server.go b/pkg/server/server.go index 9ecae83..41c3b89 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -21,8 +21,11 @@ import ( ) type server struct { - publicURL string - port string + publicURL string + port string + googleSiteVerification string + umamiURL string + umamiID string // connections stored as map of domain -> connections conn map[string][]*connection @@ -39,11 +42,14 @@ type connection struct { ws *wsconn.WebsocketConn } -func New(publicURL, port string) *server { +func New(publicURL, port, googleSiteVerification, umamiURL, umamiID string) *server { return &server{ - publicURL: publicURL, - port: port, - conn: make(map[string][]*connection), + publicURL: publicURL, + port: port, + googleSiteVerification: googleSiteVerification, + umamiURL: umamiURL, + umamiID: umamiID, + conn: make(map[string][]*connection), } } @@ -106,14 +112,20 @@ Disallow:`)) return err } type view struct { - PublicURL template.JS - GeneratedDomain string - GeneratedKey string + PublicURL template.JS + GoogleSiteVerification string + UmamiURL template.JS + UmamiID string + GeneratedDomain string + GeneratedKey string } return t.Execute(w, view{ - PublicURL: template.JS(s.publicURL), - GeneratedDomain: namesgenerator.GetRandomName(), - GeneratedKey: utils.RandStringBytesMaskImpr(6), + PublicURL: template.JS(s.publicURL), + GoogleSiteVerification: s.googleSiteVerification, + UmamiURL: template.JS(s.umamiURL), + UmamiID: s.umamiID, + GeneratedDomain: namesgenerator.GetRandomName(), + GeneratedKey: utils.RandStringBytesMaskImpr(6), }) } else { // get IP address diff --git a/templates/view.html b/templates/view.html index f8eacf9..152f275 100644 --- a/templates/view.html +++ b/templates/view.html @@ -4,7 +4,12 @@ host yo self - + {{ if .GoogleSiteVerification }} + + {{ end }} + {{ if and .UmamiURL .UmamiID }} + + {{ end }} From 8c31c2f733f81fb286683b94a48391762be9a0cb Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Tue, 23 Sep 2025 16:00:21 +0000 Subject: [PATCH 2/2] additinoal improvements for analytics (add Umami script reference to files.html as well) Signed-off-by: Seth Grover --- pkg/server/server.go | 12 ++++++++---- templates/files.html | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index 41c3b89..1debe5c 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -218,11 +218,15 @@ Disallow:`)) return } return t.Execute(w, struct { - Files []File - Domain string + Domain string + Files []File + UmamiURL template.JS + UmamiID string }{ - Domain: domain, - Files: fs, + Domain: domain, + Files: fs, + UmamiURL: template.JS(s.umamiURL), + UmamiID: s.umamiID, }) } else { log.Debugf("problem getting: %s", err.Error()) diff --git a/templates/files.html b/templates/files.html index 237b285..31f3c00 100644 --- a/templates/files.html +++ b/templates/files.html @@ -1,6 +1,9 @@ + {{ if and .UmamiURL .UmamiID }} + + {{ end }}