Skip to content

Commit

Permalink
Fixed blocking analytics requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed Nov 26, 2024
1 parent 80c36a9 commit 1f20faa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.1

* fixed blocking analytics requests

## 0.9.0

* fixed configuration in readme
Expand Down
20 changes: 12 additions & 8 deletions pkg/analytics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,24 @@ func Init() {

// PageView sends a page view using the configured Analytics provider.
func PageView(r *http.Request, tags map[string]string) {
if client != nil {
if err := client.PageView(r, tags); err != nil {
slog.Error("Error sending page view", "error", err)
go func() {
if client != nil {
if err := client.PageView(r, tags); err != nil {
slog.Error("Error sending page view", "error", err)
}
}
}
}()
}

// Event sends a custom event using the configured Analytics provider.
func Event(r *http.Request, name string, duration int, meta, tags map[string]string) {
if client != nil {
if err := client.Event(r, name, duration, meta, tags); err != nil {
slog.Error("Error sending custom event", "error", err)
go func() {
if client != nil {
if err := client.Event(r, name, duration, meta, tags); err != nil {
slog.Error("Error sending custom event", "error", err)
}
}
}
}()
}

func loadIPHeader() {
Expand Down

0 comments on commit 1f20faa

Please sign in to comment.