Only write the fbp and fbc cookies when there is a pixel to send to - #50
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
============================================
+ Coverage 90.49% 97.95% +7.45%
- Complexity 148 151 +3
============================================
Files 31 32 +1
Lines 484 488 +4
============================================
+ Hits 438 478 +40
+ Misses 46 10 -36
🚀 New features to boost your workflow:
|
9a99ee8 to
dcbe1cb
Compare
eb5e4ab to
4bb3064
Compare
dcbe1cb to
af21153
Compare
4bb3064 to
0cb43bc
Compare
af21153 to
bac5d1e
Compare
0cb43bc to
11986eb
Compare
bac5d1e to
c9f1d9d
Compare
11986eb to
25b8339
Compare
c9f1d9d to
5c3470c
Compare
25b8339 to
9040b2c
Compare
5c3470c to
77d1a3e
Compare
1752b17 to
97ab8f5
Compare
77d1a3e to
d13d703
Compare
97ab8f5 to
3a3a2e3
Compare
d13d703 to
6857dd6
Compare
3a3a2e3 to
659351d
Compare
176bc4b to
749cb00
Compare
| ->arrayNode('cookies') | ||
| ->info('The bundle writes the _fbp and _fbc cookies server side. When client side tracking is enabled the browser pixel writes the same cookies, so you may not need these') | ||
| ->addDefaultsIfNotSet() | ||
| ->children() | ||
| ->booleanNode('fbp')->defaultTrue()->end() | ||
| ->booleanNode('fbc')->defaultTrue()->end() | ||
| ->end() | ||
| ->end() |
There was a problem hiding this comment.
Not sure we need this?
There was a problem hiding this comment.
Agreed, and removed. These switches came from my own hedge in the original issue ("consider a config switch") rather than from anything anyone asked for. The case they were meant for — a site where the browser pixel already writes the cookies — does not need them either: the pixel simply overwrites the same cookie name. The pixel guard is what actually matters for sites that don't use cookies at all, and that stays.
The cookies node is now introduced by #51, which only holds domain and lifetime.
749cb00 to
6a31353
Compare
Both cookies were written on every main-request response, including in applications with no pixels configured at all, and every Set-Cookie header makes a response uncacheable for shared caches. Skip when the pixel provider returns nothing, move the cookie names and lifetime into a shared Cookies class instead of four magic strings, and rename the setCookie() predicate to shouldSetCookie(). Fixes #28
6a31353 to
0fb55dd
Compare
Fixes #28
Problem
StoreFbpSubscriberandStoreFbcSubscriberwrote their cookies on the response to every main request, including in applications with zero pixels configured. EverySet-Cookieheader makes a response uncacheable for Symfony HttpCache, Varnish and CDNs, so this quietly cost cacheability sitewide for something that may not be in use at all. Neither subscriber consulted the pixel provider, unlikeAddLibraryToTagBagSubscriber, which already checksgetPixels().The private
setCookie()method was a predicate whose name read like a command.Change
Cookie\Cookiesclass used by the two contexts that read them and the two subscribers that write them, replacing four magic strings.setCookie()is renamed toshouldSetCookie().Removed after review
An earlier revision also added
cookies.fbp/cookies.fbcswitches and skipped writing on 4xx/5xx responses. Both are gone. The switches were speculative configuration with no request behind them, and the status-code guard did not achieve what it claimed — a status code says nothing about whether a response is a cacheable HTML page — while Meta's own parameter builder does no such check. The pixel guard is what actually stops cookies on sites that do not use them.Tests
StoreFbpSubscriberTest(its first): cookie set, not http-only so the browser pixel can read it, skipped without pixels, without consent and on a sub request, and the two-hour renewal window in both directions.StoreFbcSubscriberTestmirrors it, plus thefbclidpresence check and the context returning no value.Verified on PHP 8.1 and 8.4, with
--prefer-lowestand highest.