Skip to content

Commit ce59d63

Browse files
committed
feat: use jaybizzle/crawler-detect to detect bots
1 parent e649d03 commit ce59d63

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"require": {
1212
"php": "^8.0",
1313
"magento-hackathon/magento-composer-installer": "*",
14-
"hirale/openmage-redis-queue": "*"
14+
"hirale/openmage-redis-queue": "*",
15+
"jaybizzle/crawler-detect": "^1.2"
1516
},
1617
"authors": [
1718
{

src/app/code/community/Hirale/GAMeasurementProtocol/Model/Observer.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<?php
22

3+
use Jaybizzle\CrawlerDetect\CrawlerDetect;
4+
35
class Hirale_GAMeasurementProtocol_Model_Observer
46
{
57
protected $helper;
68
protected $gaHelper;
79
protected $queue;
810
protected $baseEventData;
9-
protected $isBot;
11+
protected $CrawlerDetect;
1012

1113
public function __construct()
1214
{
1315
$this->helper = Mage::helper('gameasurementprotocol');
1416
$this->gaHelper = Mage::helper('googleanalytics');
1517
$this->queue = Mage::getModel('hirale_queue/task');
18+
$this->CrawlerDetect = new CrawlerDetect();
1619
}
1720

1821
public function generateClientId(Varien_Event_Observer $observer)
@@ -22,11 +25,7 @@ public function generateClientId(Varien_Event_Observer $observer)
2225

2326
protected function isBot()
2427
{
25-
if (preg_match('/bot|crawl|slurp|spider|GeedoProductSearch|mediapartners/i', Mage::helper('core/http')->getHttpUserAgent())) {
26-
return true;
27-
} else {
28-
return false;
29-
}
28+
return $this->CrawlerDetect->isCrawler(Mage::helper('core/http')->getHttpUserAgent());
3029
}
3130

3231
protected function canSend()

0 commit comments

Comments
 (0)