Skip to content

Only apply the request filters to website events - #44

Merged
loevgaard merged 1 commit into
masterfrom
fix/24-non-website-events
Sep 7, 2026
Merged

Only apply the request filters to website events#44
loevgaard merged 1 commit into
masterfrom
fix/24-non-website-events

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Fixes #24

Stacked on #43.

Problem

FilterEmptyUserAgentSubscriber stopped propagation whenever userData->clientUserAgent was empty. The user agent is only populated when there is a main request, so every event raised outside a browser request was silently discarded: imports and cron jobs, a Purchase raised while handling a payment webhook asynchronously, and anything server-to-server.

The SDK explicitly supports those cases through Event::ACTION_SOURCE_*, and Meta only expects client_user_agent for website events, so the filter was making six of the seven action sources unusable.

FilterBotsSubscriber had the same shape of problem: it asks whether the current request comes from a bot, which says nothing about an event raised from a console command.

Change

Both filters return early unless actionSource is website, which is the default, so ordinary browser tracking is unaffected.

FilterConfiguredUserAgentsSubscriber needs no change: it only acts when a user agent is present and matches.

A note on request properties

PopulateRequestPropertiesSubscriber still fills in the source url, client ip and user agent of the current request for every event. When a non-website event is raised while handling an HTTP request, for instance a payment provider's webhook, those describe the sender and not the customer. Changing that silently would reduce match quality for anyone relying on the current behaviour, so this PR documents the assumption in the README and points at overriding it in a listener above PRIORITY_POPULATE instead.

Tests

Nine unit tests for the empty user agent filter, covering both stopping cases, the passing case, and all six non-website action sources, plus one for the bot filter with a system generated event.

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.85%. Comparing base (04febac) to head (ee77aa5).

Additional details and impacted files
@@                    Coverage Diff                     @@
##             fix/23-filters-early      #44      +/-   ##
==========================================================
+ Coverage                   68.76%   69.85%   +1.09%     
- Complexity                    135      137       +2     
==========================================================
  Files                          30       30              
  Lines                         413      418       +5     
==========================================================
+ Hits                          284      292       +8     
+ Misses                        129      126       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loevgaard
loevgaard force-pushed the fix/23-filters-early branch from 939221d to f7c16ec Compare September 7, 2026 12:03
@loevgaard
loevgaard force-pushed the fix/24-non-website-events branch from adf67ff to 3437c5c Compare September 7, 2026 12:03
FilterEmptyUserAgentSubscriber dropped every event without a user agent,
which silently discarded events raised from console commands, message
handlers and webhooks. The bot filter had the same problem: it asks
about the current request, which such an event has no relation to.

Both now only apply to events whose action source is website.

Fixes #24
@loevgaard
loevgaard force-pushed the fix/23-filters-early branch from f7c16ec to 04febac Compare September 7, 2026 12:18
@loevgaard
loevgaard force-pushed the fix/24-non-website-events branch from 3437c5c to ee77aa5 Compare September 7, 2026 12:18
Base automatically changed from fix/23-filters-early to master September 7, 2026 12:47
@loevgaard
loevgaard merged commit ecc8912 into master Sep 7, 2026
47 checks passed
@loevgaard
loevgaard deleted the fix/24-non-website-events branch September 7, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FilterEmptyUserAgentSubscriber drops every event that is not raised inside a website request

1 participant