skip trcking robots and tracking paths
This commit is contained in:
@@ -2,6 +2,7 @@ package tracking
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"knet.sk/src/util"
|
||||
@@ -34,10 +35,33 @@ type PageStat struct {
|
||||
|
||||
var ts *TrackingService
|
||||
|
||||
var ignorePaths = []string{
|
||||
"/tracking",
|
||||
"/metrics",
|
||||
}
|
||||
|
||||
var ignoreUserAgents = []string{
|
||||
"Prometheus",
|
||||
"UptimeRobot",
|
||||
}
|
||||
|
||||
func Echo(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
ts = StartTrackingService()
|
||||
return func(c echo.Context) error {
|
||||
fmt.Printf("Tracking visit: %s %s\n", c.RealIP(), c.Request().URL.Path)
|
||||
// Check if the path is in the ignore list
|
||||
for _, path := range ignorePaths {
|
||||
if c.Request().URL.Path == path {
|
||||
return next(c) // Skip tracking for ignored paths
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the user agent is in the ignore list
|
||||
for _, ua := range ignoreUserAgents {
|
||||
if strings.Contains(c.Request().UserAgent(), ua) {
|
||||
return next(c) // Skip tracking for ignored user agents
|
||||
}
|
||||
}
|
||||
go ts.AddVisit(c)
|
||||
return next(c)
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ func StartTrackingService() *TrackingService {
|
||||
|
||||
// Apply SQLite settings explicitly with PRAGMA statements
|
||||
pragmas := []string{
|
||||
"PRAGMA busy_timeout = 10000", // 10 second busy timeout
|
||||
"PRAGMA journal_mode = WAL", // Write-Ahead Logging mode
|
||||
"PRAGMA synchronous = NORMAL", // Normal synchronization
|
||||
"PRAGMA foreign_keys = ON", // Enable foreign key constraints
|
||||
"PRAGMA temp_store = MEMORY", // Store temp tables in memory
|
||||
"PRAGMA busy_timeout = 10000", // 10 second busy timeout
|
||||
"PRAGMA journal_mode = WAL", // Write-Ahead Logging mode
|
||||
"PRAGMA synchronous = NORMAL", // Normal synchronization
|
||||
"PRAGMA foreign_keys = ON", // Enable foreign key constraints
|
||||
"PRAGMA temp_store = MEMORY", // Store temp tables in memory
|
||||
}
|
||||
|
||||
for _, pragma := range pragmas {
|
||||
|
||||
Reference in New Issue
Block a user