From e661705bddc66640fced780c5b54bc385e3fdf4c Mon Sep 17 00:00:00 2001 From: Daniel Zambo Date: Thu, 26 Mar 2026 12:26:59 +0100 Subject: [PATCH 1/7] feat: Implement queued listener mode for Facebook pixel events and update middleware behavior --- config/pixelify.php | 12 ++ .../Middleware/FacebookTrackingMiddleware.php | 12 +- src/Listeners/SendPixelEvent.php | 10 +- src/PixelifyServiceProvider.php | 10 ++ tests/Feature/PixelifyTest.php | 156 ++++++++++++------ 5 files changed, 143 insertions(+), 57 deletions(-) diff --git a/config/pixelify.php b/config/pixelify.php index 3fe472c..55c51b7 100644 --- a/config/pixelify.php +++ b/config/pixelify.php @@ -53,4 +53,16 @@ | */ 'debug' => env('FACEBOOK_PIXEL_DEBUG', false), + + /* + |-------------------------------------------------------------------------- + | Queued Listener Mode + |-------------------------------------------------------------------------- + | + | If true, the SendPixelEvent listener will be queued, allowing you to handle pixel events asynchronously. + | Make sure to set up a queue worker to process the jobs. If false, the listener will execute synchronously, + | which may impact performance if there are many events. + | + */ + 'queued_listener_mode' => env('FACEBOOK_QUEUED_LISTENER_MODE', true), ]; diff --git a/src/Http/Middleware/FacebookTrackingMiddleware.php b/src/Http/Middleware/FacebookTrackingMiddleware.php index dba7c04..bd8b878 100644 --- a/src/Http/Middleware/FacebookTrackingMiddleware.php +++ b/src/Http/Middleware/FacebookTrackingMiddleware.php @@ -14,12 +14,16 @@ final class FacebookTrackingMiddleware { use HasTracking; + public function __construct(private readonly bool $isQueued) {} + public function handle(Request $request, Closure $next): Response { - try { - $this->handleTracking($request); - } catch (Exception) { - // + if (! $this->isQueued) { + try { + $this->handleTracking($request); + } catch (Exception) { + // + } } return $next($request); diff --git a/src/Listeners/SendPixelEvent.php b/src/Listeners/SendPixelEvent.php index 56120f0..c72d32b 100644 --- a/src/Listeners/SendPixelEvent.php +++ b/src/Listeners/SendPixelEvent.php @@ -6,13 +6,19 @@ use Revoltify\Pixelify\Events\PixelEventOccurred; use Revoltify\Pixelify\Http\Client\FacebookClient; +use Illuminate\Contracts\Queue\ShouldQueue; -final readonly class SendPixelEvent +final readonly class SendPixelEvent implements ShouldQueue { - public function __construct(private FacebookClient $client) {} + public function __construct(private FacebookClient $client, private bool $isQueued) {} public function handle(PixelEventOccurred $event): void { $this->client->sendEvent($event->eventData); } + + public function shouldQueue(PixelEventOccurred $event): bool + { + return $this->isQueued; + } } diff --git a/src/PixelifyServiceProvider.php b/src/PixelifyServiceProvider.php index 0087190..3a384cb 100644 --- a/src/PixelifyServiceProvider.php +++ b/src/PixelifyServiceProvider.php @@ -30,6 +30,16 @@ public function register(): void // Register Facebook client $this->app->singleton(FacebookClient::class, fn ($app): FacebookClient => new FacebookClient); + + // Set SendPixelEvent listener to use queued mode based on config + $this->app->when(SendPixelEvent::class) + ->needs('$isQueued') + ->give(fn (): bool => (bool) config('pixelify.queued_listener', true)); + + // Set FacebookTrackingMiddleware to use queued mode based on config + $this->app->when(FacebookTrackingMiddleware::class) + ->needs('$isQueued') + ->give(fn (): bool => (bool) config('pixelify.queued_listener', true)); } public function boot(): void diff --git a/tests/Feature/PixelifyTest.php b/tests/Feature/PixelifyTest.php index bb729f1..31433c1 100644 --- a/tests/Feature/PixelifyTest.php +++ b/tests/Feature/PixelifyTest.php @@ -2,78 +2,132 @@ declare(strict_types=1); +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Event; +use Revoltify\Pixelify\DTO\EventData; use Revoltify\Pixelify\DTO\ProductData; use Revoltify\Pixelify\DTO\UserData; use Revoltify\Pixelify\Events\PixelEventOccurred; use Revoltify\Pixelify\Facades\Pixelify; +use Revoltify\Pixelify\Http\Middleware\FacebookTrackingMiddleware; +use Revoltify\Pixelify\Listeners\SendPixelEvent; -beforeEach(function (): void { - Event::fake(); -}); +describe('queued mode', function (): void { + beforeEach(function (): void { + config()->set('pixelify.queued_listener', true); + Event::fake(); + }); -test('it can track page view event', function (): void { - $userData = new UserData( - firstName: 'John', - lastName: 'Doe', - email: 'test@example.com' - ); + test('it can track page view event', function (): void { + Pixelify::pageView(new UserData(firstName: 'John', lastName: 'Doe', email: 'test@example.com')); - Pixelify::pageView($userData); + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'PageView'); + }); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'PageView'); -}); + test('it can track view content event', function (): void { + Pixelify::viewContent(new ProductData(productId: '123', price: 99.99)); -test('it can track view content event', function (): void { - $productData = new ProductData( - productId: '123', - price: 99.99, - ); + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'ViewContent' + && $event->eventData->productData->productId === '123'); + }); - Pixelify::viewContent($productData); + test('it can track add to cart event', function (): void { + Pixelify::addToCart(new ProductData(productId: '123', price: 99.99, quantity: 2)); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'ViewContent' - && $event->eventData->productData->productId === '123'); -}); + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'AddToCart' + && $event->eventData->productData->quantity === 2); + }); -test('it can track add to cart event', function (): void { - $productData = new ProductData( - productId: '123', - price: 99.99, - quantity: 2 - ); + test('it can track initiate checkout event', function (): void { + Pixelify::initiateCheckout( + new ProductData(productId: '123', price: 99.99), + new UserData(email: 'test@example.com') + ); - Pixelify::addToCart($productData); + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'InitiateCheckout' + && $event->eventData->userData->email === 'test@example.com'); + }); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'AddToCart' - && $event->eventData->productData->quantity === 2); -}); + test('it can track purchase event', function (): void { + Pixelify::purchase(new ProductData(productId: '123', price: 99.99, currency: 'USD')); + + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'Purchase' + && $event->eventData->productData->currency === 'USD'); + }); -test('it can track initiate checkout event', function (): void { - $productData = new ProductData( - productId: '123', - price: 99.99 - ); + test('listener is dispatched to queue', function (): void { + $listener = app(SendPixelEvent::class); + $event = new PixelEventOccurred(new EventData(eventName: 'PageView', eventId: 'test-id')); - $userData = new UserData( - email: 'test@example.com' - ); + expect($listener->shouldQueue($event))->toBeTrue(); + }); - Pixelify::initiateCheckout($productData, $userData); + test('middleware skips tracking cookies', function (): void { + $middleware = new FacebookTrackingMiddleware(true); + $middleware->handle(Request::create('/?fbclid=test123'), fn ($r) => response('ok')); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'InitiateCheckout' - && $event->eventData->userData->email === 'test@example.com'); + expect(Cookie::queued('_fbc'))->toBeNull(); + expect(Cookie::queued('_fbp'))->toBeNull(); + }); }); -test('it can track purchase event', function (): void { - $productData = new ProductData( - productId: '123', - price: 99.99, - currency: 'USD' - ); +describe('sync mode', function (): void { + beforeEach(function (): void { + config()->set('pixelify.queued_listener', false); + Event::fake(); + }); + + test('it can track page view event', function (): void { + Pixelify::pageView(new UserData(firstName: 'John', lastName: 'Doe', email: 'test@example.com')); + + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'PageView'); + }); + + test('it can track view content event', function (): void { + Pixelify::viewContent(new ProductData(productId: '123', price: 99.99)); + + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'ViewContent' + && $event->eventData->productData->productId === '123'); + }); - Pixelify::purchase($productData); + test('it can track add to cart event', function (): void { + Pixelify::addToCart(new ProductData(productId: '123', price: 99.99, quantity: 2)); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'Purchase' - && $event->eventData->productData->currency === 'USD'); + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'AddToCart' + && $event->eventData->productData->quantity === 2); + }); + + test('it can track initiate checkout event', function (): void { + Pixelify::initiateCheckout( + new ProductData(productId: '123', price: 99.99), + new UserData(email: 'test@example.com') + ); + + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'InitiateCheckout' + && $event->eventData->userData->email === 'test@example.com'); + }); + + test('it can track purchase event', function (): void { + Pixelify::purchase(new ProductData(productId: '123', price: 99.99, currency: 'USD')); + + Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'Purchase' + && $event->eventData->productData->currency === 'USD'); + }); + + test('listener is not queued', function (): void { + $listener = app(SendPixelEvent::class); + $event = new PixelEventOccurred(new EventData(eventName: 'PageView', eventId: 'test-id')); + + expect($listener->shouldQueue($event))->toBeFalse(); + }); + + test('middleware sets tracking cookies', function (): void { + $middleware = new FacebookTrackingMiddleware(false); + $middleware->handle(Request::create('/?fbclid=test123'), fn ($r) => response('ok')); + + expect(Cookie::queued('_fbc'))->not->toBeNull(); + expect(Cookie::queued('_fbp'))->not->toBeNull(); + }); }); + From 6b26c2f5cf381ccccd275bfd5a247514dc4baf29 Mon Sep 17 00:00:00 2001 From: Daniel Zambo Date: Thu, 26 Mar 2026 12:33:18 +0100 Subject: [PATCH 2/7] fix: Update configuration key for queued listener mode in PixelifyServiceProvider --- src/PixelifyServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PixelifyServiceProvider.php b/src/PixelifyServiceProvider.php index 3a384cb..d47aa5b 100644 --- a/src/PixelifyServiceProvider.php +++ b/src/PixelifyServiceProvider.php @@ -34,12 +34,12 @@ public function register(): void // Set SendPixelEvent listener to use queued mode based on config $this->app->when(SendPixelEvent::class) ->needs('$isQueued') - ->give(fn (): bool => (bool) config('pixelify.queued_listener', true)); + ->give(fn (): bool => (bool) config('pixelify.queued_listener_mode', true)); // Set FacebookTrackingMiddleware to use queued mode based on config $this->app->when(FacebookTrackingMiddleware::class) ->needs('$isQueued') - ->give(fn (): bool => (bool) config('pixelify.queued_listener', true)); + ->give(fn (): bool => (bool) config('pixelify.queued_listener_mode', true)); } public function boot(): void From 285e47965caf5fe2b8e489f06ae7a58a5b5776f9 Mon Sep 17 00:00:00 2001 From: Daniel Zambo Date: Thu, 26 Mar 2026 12:34:59 +0100 Subject: [PATCH 3/7] fix: Update test configuration key for queued listener mode in PixelifyTest --- tests/Feature/PixelifyTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/PixelifyTest.php b/tests/Feature/PixelifyTest.php index 31433c1..ec2875b 100644 --- a/tests/Feature/PixelifyTest.php +++ b/tests/Feature/PixelifyTest.php @@ -15,7 +15,7 @@ describe('queued mode', function (): void { beforeEach(function (): void { - config()->set('pixelify.queued_listener', true); + config()->set('pixelify.queued_listener_mode', true); Event::fake(); }); @@ -74,7 +74,7 @@ describe('sync mode', function (): void { beforeEach(function (): void { - config()->set('pixelify.queued_listener', false); + config()->set('pixelify.queued_listener_mode', false); Event::fake(); }); From aae4e98395ff7d9b32f103058c8173e752019af2 Mon Sep 17 00:00:00 2001 From: Daniel Zambo Date: Thu, 26 Mar 2026 12:37:30 +0100 Subject: [PATCH 4/7] fix: Set default value for queued listener mode to false in pixelify.php to preserve backward compatibility --- config/pixelify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/pixelify.php b/config/pixelify.php index 55c51b7..f80f610 100644 --- a/config/pixelify.php +++ b/config/pixelify.php @@ -64,5 +64,5 @@ | which may impact performance if there are many events. | */ - 'queued_listener_mode' => env('FACEBOOK_QUEUED_LISTENER_MODE', true), + 'queued_listener_mode' => env('FACEBOOK_QUEUED_LISTENER_MODE', false), ]; From a660a326a690c78afaef3cd167e5d6a3120a6300 Mon Sep 17 00:00:00 2001 From: Daniel Zambo Date: Thu, 26 Mar 2026 13:56:50 +0100 Subject: [PATCH 5/7] refactor: Simplify FacebookTrackingMiddleware and update PixelifyTest for listener modes --- .../Middleware/FacebookTrackingMiddleware.php | 13 +- src/PixelifyServiceProvider.php | 5 - tests/Feature/PixelifyTest.php | 152 ++++++------------ 3 files changed, 57 insertions(+), 113 deletions(-) diff --git a/src/Http/Middleware/FacebookTrackingMiddleware.php b/src/Http/Middleware/FacebookTrackingMiddleware.php index bd8b878..fb9790c 100644 --- a/src/Http/Middleware/FacebookTrackingMiddleware.php +++ b/src/Http/Middleware/FacebookTrackingMiddleware.php @@ -14,18 +14,13 @@ final class FacebookTrackingMiddleware { use HasTracking; - public function __construct(private readonly bool $isQueued) {} - public function handle(Request $request, Closure $next): Response { - if (! $this->isQueued) { - try { - $this->handleTracking($request); - } catch (Exception) { - // - } + try { + $this->handleTracking($request); + } catch (Exception) { + // } - return $next($request); } } diff --git a/src/PixelifyServiceProvider.php b/src/PixelifyServiceProvider.php index d47aa5b..f60afad 100644 --- a/src/PixelifyServiceProvider.php +++ b/src/PixelifyServiceProvider.php @@ -35,11 +35,6 @@ public function register(): void $this->app->when(SendPixelEvent::class) ->needs('$isQueued') ->give(fn (): bool => (bool) config('pixelify.queued_listener_mode', true)); - - // Set FacebookTrackingMiddleware to use queued mode based on config - $this->app->when(FacebookTrackingMiddleware::class) - ->needs('$isQueued') - ->give(fn (): bool => (bool) config('pixelify.queued_listener_mode', true)); } public function boot(): void diff --git a/tests/Feature/PixelifyTest.php b/tests/Feature/PixelifyTest.php index ec2875b..2cc74ec 100644 --- a/tests/Feature/PixelifyTest.php +++ b/tests/Feature/PixelifyTest.php @@ -13,121 +13,75 @@ use Revoltify\Pixelify\Http\Middleware\FacebookTrackingMiddleware; use Revoltify\Pixelify\Listeners\SendPixelEvent; -describe('queued mode', function (): void { - beforeEach(function (): void { - config()->set('pixelify.queued_listener_mode', true); - Event::fake(); - }); - - test('it can track page view event', function (): void { - Pixelify::pageView(new UserData(firstName: 'John', lastName: 'Doe', email: 'test@example.com')); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'PageView'); - }); - - test('it can track view content event', function (): void { - Pixelify::viewContent(new ProductData(productId: '123', price: 99.99)); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'ViewContent' - && $event->eventData->productData->productId === '123'); - }); - - test('it can track add to cart event', function (): void { - Pixelify::addToCart(new ProductData(productId: '123', price: 99.99, quantity: 2)); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'AddToCart' - && $event->eventData->productData->quantity === 2); - }); - - test('it can track initiate checkout event', function (): void { - Pixelify::initiateCheckout( +dataset('listener modes', [ + 'queued mode' => [true], + 'sync mode' => [false], +]); + +dataset('tracking scenarios', [ + 'page view' => [ + fn (): mixed => Pixelify::pageView(new UserData(firstName: 'John', lastName: 'Doe', email: 'test@example.com')), + fn (PixelEventOccurred $event): bool => $event->eventData->eventName === 'PageView', + ], + 'view content' => [ + fn (): mixed => Pixelify::viewContent(new ProductData(productId: '123', price: 99.99)), + fn (PixelEventOccurred $event): bool => $event->eventData->eventName === 'ViewContent' + && $event->eventData->productData->productId === '123', + ], + 'add to cart' => [ + fn (): mixed => Pixelify::addToCart(new ProductData(productId: '123', price: 99.99, quantity: 2)), + fn (PixelEventOccurred $event): bool => $event->eventData->eventName === 'AddToCart' + && $event->eventData->productData->quantity === 2, + ], + 'initiate checkout' => [ + fn (): mixed => Pixelify::initiateCheckout( new ProductData(productId: '123', price: 99.99), new UserData(email: 'test@example.com') - ); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'InitiateCheckout' - && $event->eventData->userData->email === 'test@example.com'); - }); - - test('it can track purchase event', function (): void { - Pixelify::purchase(new ProductData(productId: '123', price: 99.99, currency: 'USD')); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'Purchase' - && $event->eventData->productData->currency === 'USD'); - }); - - test('listener is dispatched to queue', function (): void { - $listener = app(SendPixelEvent::class); - $event = new PixelEventOccurred(new EventData(eventName: 'PageView', eventId: 'test-id')); - - expect($listener->shouldQueue($event))->toBeTrue(); - }); - - test('middleware skips tracking cookies', function (): void { - $middleware = new FacebookTrackingMiddleware(true); - $middleware->handle(Request::create('/?fbclid=test123'), fn ($r) => response('ok')); - - expect(Cookie::queued('_fbc'))->toBeNull(); - expect(Cookie::queued('_fbp'))->toBeNull(); - }); -}); - -describe('sync mode', function (): void { + ), + fn (PixelEventOccurred $event): bool => $event->eventData->eventName === 'InitiateCheckout' + && $event->eventData->userData->email === 'test@example.com', + ], + 'purchase' => [ + fn (): mixed => Pixelify::purchase(new ProductData(productId: '123', price: 99.99, currency: 'USD')), + fn (PixelEventOccurred $event): bool => $event->eventData->eventName === 'Purchase' + && $event->eventData->productData->currency === 'USD', + ], +]); + +describe('event tracking', function (): void { beforeEach(function (): void { - config()->set('pixelify.queued_listener_mode', false); Event::fake(); }); - test('it can track page view event', function (): void { - Pixelify::pageView(new UserData(firstName: 'John', lastName: 'Doe', email: 'test@example.com')); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'PageView'); - }); - - test('it can track view content event', function (): void { - Pixelify::viewContent(new ProductData(productId: '123', price: 99.99)); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'ViewContent' - && $event->eventData->productData->productId === '123'); - }); - - test('it can track add to cart event', function (): void { - Pixelify::addToCart(new ProductData(productId: '123', price: 99.99, quantity: 2)); + test('it dispatches the expected pixel event', function (bool $isQueued, Closure $trackEvent, Closure $assertEvent): void { + config()->set('pixelify.queued_listener_mode', $isQueued); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'AddToCart' - && $event->eventData->productData->quantity === 2); - }); + $trackEvent(); - test('it can track initiate checkout event', function (): void { - Pixelify::initiateCheckout( - new ProductData(productId: '123', price: 99.99), - new UserData(email: 'test@example.com') - ); - - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'InitiateCheckout' - && $event->eventData->userData->email === 'test@example.com'); - }); + Event::assertDispatched(PixelEventOccurred::class, fn (PixelEventOccurred $event): bool => $assertEvent($event)); + })->with('listener modes')->with('tracking scenarios'); +}); - test('it can track purchase event', function (): void { - Pixelify::purchase(new ProductData(productId: '123', price: 99.99, currency: 'USD')); +describe('listener queueing', function (): void { + test('it follows the configured queue mode', function (bool $isQueued): void { + config()->set('pixelify.queued_listener_mode', $isQueued); - Event::assertDispatched(PixelEventOccurred::class, fn ($event): bool => $event->eventData->eventName === 'Purchase' - && $event->eventData->productData->currency === 'USD'); - }); - - test('listener is not queued', function (): void { $listener = app(SendPixelEvent::class); $event = new PixelEventOccurred(new EventData(eventName: 'PageView', eventId: 'test-id')); - expect($listener->shouldQueue($event))->toBeFalse(); - }); + expect($listener->shouldQueue($event))->toBe($isQueued); + })->with('listener modes'); +}); - test('middleware sets tracking cookies', function (): void { - $middleware = new FacebookTrackingMiddleware(false); - $middleware->handle(Request::create('/?fbclid=test123'), fn ($r) => response('ok')); +describe('middleware tracking', function (): void { + test('it queues tracking cookies', function (bool $isQueued): void { + config()->set('pixelify.queued_listener_mode', $isQueued); + + $middleware = app(FacebookTrackingMiddleware::class); + $middleware->handle(Request::create('/?fbclid=test123'), fn ($request) => response('ok')); expect(Cookie::queued('_fbc'))->not->toBeNull(); expect(Cookie::queued('_fbp'))->not->toBeNull(); - }); + })->with('listener modes'); }); From b23d8fa5b332b19113ec26fa855ffb17461dca2f Mon Sep 17 00:00:00 2001 From: rtraselbd Date: Sat, 4 Apr 2026 11:52:22 +0600 Subject: [PATCH 6/7] chore: fix code style --- src/Http/Middleware/FacebookTrackingMiddleware.php | 1 + src/Listeners/SendPixelEvent.php | 2 +- tests/Feature/PixelifyTest.php | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Middleware/FacebookTrackingMiddleware.php b/src/Http/Middleware/FacebookTrackingMiddleware.php index fb9790c..dba7c04 100644 --- a/src/Http/Middleware/FacebookTrackingMiddleware.php +++ b/src/Http/Middleware/FacebookTrackingMiddleware.php @@ -21,6 +21,7 @@ public function handle(Request $request, Closure $next): Response } catch (Exception) { // } + return $next($request); } } diff --git a/src/Listeners/SendPixelEvent.php b/src/Listeners/SendPixelEvent.php index c72d32b..a1a6b1d 100644 --- a/src/Listeners/SendPixelEvent.php +++ b/src/Listeners/SendPixelEvent.php @@ -4,9 +4,9 @@ namespace Revoltify\Pixelify\Listeners; +use Illuminate\Contracts\Queue\ShouldQueue; use Revoltify\Pixelify\Events\PixelEventOccurred; use Revoltify\Pixelify\Http\Client\FacebookClient; -use Illuminate\Contracts\Queue\ShouldQueue; final readonly class SendPixelEvent implements ShouldQueue { diff --git a/tests/Feature/PixelifyTest.php b/tests/Feature/PixelifyTest.php index 2cc74ec..a3210b5 100644 --- a/tests/Feature/PixelifyTest.php +++ b/tests/Feature/PixelifyTest.php @@ -84,4 +84,3 @@ expect(Cookie::queued('_fbp'))->not->toBeNull(); })->with('listener modes'); }); - From 72aaaa8b3cc7e706b9f651d54469a5117b70cdff Mon Sep 17 00:00:00 2001 From: rtraselbd Date: Sat, 4 Apr 2026 12:03:39 +0600 Subject: [PATCH 7/7] refactor: decouple SendPixelEvent from constructor-injected queue configuration in favor of direct config access --- src/Listeners/SendPixelEvent.php | 4 ++-- src/PixelifyServiceProvider.php | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Listeners/SendPixelEvent.php b/src/Listeners/SendPixelEvent.php index a1a6b1d..ec27014 100644 --- a/src/Listeners/SendPixelEvent.php +++ b/src/Listeners/SendPixelEvent.php @@ -10,7 +10,7 @@ final readonly class SendPixelEvent implements ShouldQueue { - public function __construct(private FacebookClient $client, private bool $isQueued) {} + public function __construct(private FacebookClient $client) {} public function handle(PixelEventOccurred $event): void { @@ -19,6 +19,6 @@ public function handle(PixelEventOccurred $event): void public function shouldQueue(PixelEventOccurred $event): bool { - return $this->isQueued; + return config()->boolean('pixelify.queued_listener_mode', false); } } diff --git a/src/PixelifyServiceProvider.php b/src/PixelifyServiceProvider.php index f60afad..0087190 100644 --- a/src/PixelifyServiceProvider.php +++ b/src/PixelifyServiceProvider.php @@ -30,11 +30,6 @@ public function register(): void // Register Facebook client $this->app->singleton(FacebookClient::class, fn ($app): FacebookClient => new FacebookClient); - - // Set SendPixelEvent listener to use queued mode based on config - $this->app->when(SendPixelEvent::class) - ->needs('$isQueued') - ->give(fn (): bool => (bool) config('pixelify.queued_listener_mode', true)); } public function boot(): void