Skip to content

v1.1.0

Latest

Choose a tag to compare

@Rau-N Rau-N released this 20 Oct 12:19
· 1 commit to main since this release

🚀 Release: Response-based Tracking Conditions

🎯 Highlights

  • Post-response tracking: Tracking now happens after the response is generated.
  • New responseConditions: Filter tracking by final HTTP status and response headers.
  • Granular control: Path-level overrides can refine or override domain-level conditions.
  • Backward compatible: No configuration changes needed to preserve current behavior.

🧩 What Changed

  • Tracking decision deferred: Matomo tracking now executes after the next handler writes the response.
  • New data model:
    • DomainConfig.ResponseConditions
    • PathConfig.ResponseConditions
  • ResponseConditions structure:
    • TrackOnStatusCodes: list of allowed HTTP status codes (empty = allow any)
    • TrackWhenHeaders: required response headers as exact key/value pairs (header name is case-insensitive)
  • Evaluation logic (AND conditions):
    • If TrackOnStatusCodes is defined, the final status must match one of the listed codes.
    • All headers in TrackWhenHeaders must exist with exactly matching values.
    • Header values match if any value for a given key equals the configured value.

⚙️ Configuration Example (Traefik YAML)

http:
  middlewares:
    matomo-tracking:
      plugin:
        matomoTracking:
          matomoURL: "http://matomo-local/matomo.php"
          domains:
            "demo.localhost":
              trackingEnabled: true
              idSite: 1
              # Track only successful HTML pages
              responseConditions:
                trackOnStatusCodes: [200]
                trackWhenHeaders:
                  Content-Type: "text/html; charset=UTF-8"

🧠 Behavior & Precedence

  • Precedence: Path-level overrides > domain-level defaults.
  • Evaluation order:
    1. Domain enablement
    2. Path include/exclude rules
    3. Response conditions (after response generated)
  • Header names are case-insensitive; values must match exactly.

🔄 Upgrade & Migration

  • No action required — existing setups behave the same if responseConditions is omitted.
  • To restrict tracking to 200 OK responses, for example:
    trackOnStatusCodes: [200]

🧪 Files Changed

  • main.go — defer tracking until after response; apply response conditions
  • response_conditions.go — new ResponseConditions type, matcher, and status recorder
  • Tests:
    • response_conditions_unit_test.go
    • response_conditions_integration_test.go

🧰 How to Run Tests

  • Unit and integration tests:
    go test -v ./...

⚠️ Known Limitations

  • Header values require exact match (no partial or regex matching).
  • Multi-value headers pass if any value matches the configured one.
  • Tracking is delayed until the final status is known — very long-running responses may delay the tracking call.