Skip to content

Commit

Permalink
Added: Bot detecting
Browse files Browse the repository at this point in the history
  • Loading branch information
igormukhingmailcom committed Nov 19, 2021
1 parent d028fb1 commit a3bb879
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ in `config/bundles.php` file of your project before (!) `SyliusGridBundle`:
$bundles = [
Setono\ClientIdBundle\SetonoClientIdBundle::class => ['all' => true],
Setono\ConsentBundle\SetonoConsentBundle::class => ['all' => true],
Setono\BotDetectionBundle\SetonoBotDetectionBundle::class => ['all' => true],
Setono\SyliusFacebookPlugin\SetonoSyliusFacebookPlugin::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];
Expand Down
3 changes: 2 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
1. As we're moving to server side tracking - we no longer need `SetonoTagBagBundle`
and `SetonoSyliusTagBagPlugin`.

- Remove them from `config/bundles.php`:
- Remove them from `config/bundles.php` and add ones we're using:

```diff
$bundles = [
- Setono\TagBagBundle\SetonoTagBagBundle::class => ['all' => true],
- Setono\SyliusTagBagPlugin\SetonoSyliusTagBagPlugin::class => ['all' => true],
+ Setono\ClientIdBundle\SetonoClientIdBundle::class => ['all' => true],
+ Setono\ConsentBundle\SetonoConsentBundle::class => ['all' => true],
+ Setono\BotDetectionBundle\SetonoBotDetectionBundle::class => ['all' => true],

Setono\SyliusFacebookPlugin\SetonoSyliusFacebookPlugin::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"fzaninotto/faker": "^1.6",
"knplabs/knp-menu": "^3.0",
"psr/log": "^1.1",
"setono/bot-detection-bundle": "^1.1",
"setono/client-id-bundle": "^0.2",
"setono/client-id-contracts": "^0.2",
"setono/consent-bundle": "^0.1",
Expand Down
17 changes: 15 additions & 2 deletions src/EventListener/AbstractSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Setono\SyliusFacebookPlugin\EventListener;

use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface;
use Setono\SyliusFacebookPlugin\Context\PixelContextInterface;
use Setono\SyliusFacebookPlugin\Generator\PixelEventsGeneratorInterface;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
Expand All @@ -21,16 +22,20 @@ abstract class AbstractSubscriber implements EventSubscriberInterface

protected PixelEventsGeneratorInterface $pixelEventsGenerator;

protected BotDetectorInterface $botDetector;

public function __construct(
RequestStack $requestStack,
FirewallMap $firewallMap,
PixelContextInterface $pixelContext,
PixelEventsGeneratorInterface $pixelEventsGenerator
PixelEventsGeneratorInterface $pixelEventsGenerator,
BotDetectorInterface $botDetector
) {
$this->requestStack = $requestStack;
$this->firewallMap = $firewallMap;
$this->pixelContext = $pixelContext;
$this->pixelEventsGenerator = $pixelEventsGenerator;
$this->botDetector = $botDetector;
}

protected function isShopContext(Request $request = null): bool
Expand Down Expand Up @@ -60,6 +65,14 @@ protected function isRequestEligible(): bool
return false;
}

return $this->isShopContext();
if (!$this->isShopContext()) {
return false;
}

if ($this->botDetector->isBotRequest()) {
return false;
}

return true;
}
}
10 changes: 9 additions & 1 deletion src/EventListener/AddToCartSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Setono\SyliusFacebookPlugin\EventListener;

use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface;
use Setono\SyliusFacebookPlugin\Context\PixelContextInterface;
use Setono\SyliusFacebookPlugin\Generator\PixelEventsGeneratorInterface;
use Setono\SyliusFacebookPlugin\ServerSide\ServerSideEventInterface;
Expand All @@ -21,9 +22,16 @@ public function __construct(
FirewallMap $firewallMap,
PixelContextInterface $pixelContext,
PixelEventsGeneratorInterface $pixelEventsGenerator,
BotDetectorInterface $botDetector,
CartContextInterface $cartContext
) {
parent::__construct($requestStack, $firewallMap, $pixelContext, $pixelEventsGenerator);
parent::__construct(
$requestStack,
$firewallMap,
$pixelContext,
$pixelEventsGenerator,
$botDetector
);

$this->cartContext = $cartContext;
}
Expand Down
10 changes: 9 additions & 1 deletion src/EventListener/InitiateCheckoutSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Setono\SyliusFacebookPlugin\EventListener;

use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface;
use Setono\SyliusFacebookPlugin\Context\PixelContextInterface;
use Setono\SyliusFacebookPlugin\Generator\PixelEventsGeneratorInterface;
use Setono\SyliusFacebookPlugin\ServerSide\ServerSideEventInterface;
Expand All @@ -22,9 +23,16 @@ public function __construct(
FirewallMap $firewallMap,
PixelContextInterface $pixelContext,
PixelEventsGeneratorInterface $pixelEventsGenerator,
BotDetectorInterface $botDetector,
CartContextInterface $cartContext
) {
parent::__construct($requestStack, $firewallMap, $pixelContext, $pixelEventsGenerator);
parent::__construct(
$requestStack,
$firewallMap,
$pixelContext,
$pixelEventsGenerator,
$botDetector
);

$this->cartContext = $cartContext;
}
Expand Down
10 changes: 9 additions & 1 deletion src/EventListener/PurchaseSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Setono\SyliusFacebookPlugin\EventListener;

use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface;
use Setono\SyliusFacebookPlugin\Context\PixelContextInterface;
use Setono\SyliusFacebookPlugin\Generator\PixelEventsGeneratorInterface;
use Setono\SyliusFacebookPlugin\ServerSide\ServerSideEventInterface;
Expand All @@ -23,9 +24,16 @@ public function __construct(
FirewallMap $firewallMap,
PixelContextInterface $pixelContext,
PixelEventsGeneratorInterface $pixelEventsGenerator,
BotDetectorInterface $botDetector,
OrderRepositoryInterface $orderRepository
) {
parent::__construct($requestStack, $firewallMap, $pixelContext, $pixelEventsGenerator);
parent::__construct(
$requestStack,
$firewallMap,
$pixelContext,
$pixelEventsGenerator,
$botDetector
);

$this->orderRepository = $orderRepository;
}
Expand Down
10 changes: 9 additions & 1 deletion src/EventListener/ViewCategorySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Setono\SyliusFacebookPlugin\EventListener;

use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface;
use Setono\SyliusFacebookPlugin\Context\PixelContextInterface;
use Setono\SyliusFacebookPlugin\Data\ViewCategoryData;
use Setono\SyliusFacebookPlugin\Generator\PixelEventsGeneratorInterface;
Expand Down Expand Up @@ -33,10 +34,17 @@ public function __construct(
FirewallMap $firewallMap,
PixelContextInterface $pixelContext,
PixelEventsGeneratorInterface $pixelEventsGenerator,
BotDetectorInterface $botDetector,
LocaleContextInterface $localeContext,
TaxonRepositoryInterface $taxonRepository
) {
parent::__construct($requestStack, $firewallMap, $pixelContext, $pixelEventsGenerator);
parent::__construct(
$requestStack,
$firewallMap,
$pixelContext,
$pixelEventsGenerator,
$botDetector
);

$this->localeContext = $localeContext;
$this->taxonRepository = $taxonRepository;
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/event_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<argument type="service" id="security.firewall.map"/>
<argument type="service" id="setono_sylius_facebook.context.pixel"/>
<argument type="service" id="setono_sylius_facebook.generator.pixel_events"/>
<argument type="service" id="setono_bot_detection.bot_detector.default"/>
</service>

<service id="setono_sylius_facebook.event_listener.add_to_cart"
Expand Down
1 change: 1 addition & 0 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Setono\ClientIdBundle\SetonoClientIdBundle::class => ['all' => true],
Setono\ConsentBundle\SetonoConsentBundle::class => ['all' => true],
Setono\BotDetectionBundle\SetonoBotDetectionBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
];

0 comments on commit a3bb879

Please sign in to comment.