Skip to content

Make the pixel access token optional and skip pixels without one - #41

Merged
loevgaard merged 1 commit into
masterfrom
fix/21-pixel-access-token
Sep 7, 2026
Merged

Make the pixel access token optional and skip pixels without one#41
loevgaard merged 1 commit into
masterfrom
fix/21-pixel-access-token

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Fixes #21

Stacked on #40.

Problem

Three places disagreed about whether a pixel needs an access token:

  • Configuration marked access_token as isRequired()->cannotBeEmpty(), so a client-side-only setup had to invent a dummy token, even though the README says the token is for server side and the SDK's Pixel::$accessToken is nullable for exactly that reason.
  • ConfigurationBasedPixelProvider carried a comment claiming it filters pixels whose id or access token is empty, while the code only filtered empty ids. An unset META_ACCESS_TOKEN therefore produced a pixel with a null token.
  • SendEventHandler posted for every pixel regardless. With a null token the field is dropped from the body, Meta answers 400, the SDK throws, and Messenger retries until the message reaches the failure transport. Synchronously it took the page down instead.

Change

  • access_token is optional (defaultNull()); id stays required.
  • The misleading comment in the provider is replaced with one describing what actually happens.
  • SendEventHandler filters out pixels without an access token, logging one warning per pixel with the pixel id, event name and event id, and returns without calling the client when nothing is left. Client side tracking is untouched, since rendering fbq() only needs the id.
  • The handler clones the event before narrowing the pixel list, so a synchronously handled command does not mutate the event the application still holds.

Tests

Four unit tests for the handler (sends, skips token-less pixels, sends nothing when none qualify, does not mutate the caller's event) and an extension test asserting pixels: [{id: '1234'}] is accepted.

@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 67.07%. Comparing base (1b06004) to head (1d50dd3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #41      +/-   ##
============================================
- Coverage     67.99%   67.07%   -0.92%     
- Complexity      134      135       +1     
============================================
  Files            30       30              
  Lines           403      413      +10     
============================================
+ Hits            274      277       +3     
- Misses          129      136       +7     

☔ 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.

The configuration required an access token even for client side only
setups, while the provider happily produced pixels without one and the
handler posted them anyway, which Meta rejects and Messenger retries.

The token is now optional and the send handler skips and logs pixels
that have none.

Fixes #21
@loevgaard
loevgaard force-pushed the fix/18-user-agent-regex branch from 2809b78 to 1b06004 Compare September 7, 2026 12:18
@loevgaard
loevgaard force-pushed the fix/21-pixel-access-token branch from f7941c5 to 1d50dd3 Compare September 7, 2026 12:18
Base automatically changed from fix/18-user-agent-regex to master September 7, 2026 12:19
@loevgaard
loevgaard merged commit 5e9fbf5 into master Sep 7, 2026
46 of 47 checks passed
@loevgaard
loevgaard deleted the fix/21-pixel-access-token branch September 7, 2026 12:44
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.

Pixels without an access token: configuration requires it, provider does not filter it, handler sends without it

1 participant