leowebguy / craft-crawler-detect
Craft plugin for detecting bots/crawlers/spiders
Package info
github.com/leowebguy/craft-crawler-detect
Type:craft-plugin
pkg:composer/leowebguy/craft-crawler-detect
Requires
- php: ^8.2
- craftcms/cms: ^5.0
- jaybizzle/crawler-detect: ^1.2
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- craftcms/rector: dev-main
- laravel/pint: ^1.14.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Craft CMS plugin for detecting bots, crawlers, and spiders.
A wrapper for CrawlerDetect by Mark Beech.
Requirements
This plugin requires:
- Craft CMS:
^5.0.0 - PHP:
^8.2 || ^8.3 || ^8.4 || ^8.5
Installation
Open your terminal and navigate to your Craft project:
cd /path/to/project
Then install the plugin using Composer:
composer require leowebguy/craft-crawler-detect -w
In the Control Panel, navigate to Settings → Plugins and click the Install button for Crawler Detect, or run:
php craft plugin/install crawler-detect
Usage
The plugin exposes CrawlerDetect methods through the craft.crawlerDetect Twig variable:
Basic Check
Check whether the current request is coming from a bot or crawler:
{{ craft.crawlerDetect.isCrawler ? 'I am a crawler.' : 'I am not a crawler.' }}
{% if craft.crawlerDetect.isCrawler %}
{# Do not render analytics or track bot views #}
{% endif %}
Check a Specific User-Agent
Pass an explicit user-agent string:
{% if craft.crawlerDetect.isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)') %}
Crawler detected: {{ craft.crawlerDetect.getMatches() }}
{% endif %}
Additional Methods
craft.crawlerDetect.isCrawler(userAgent): Returnstrueif bot/crawler,falseotherwise.craft.crawlerDetect.getMatches(): Returns matched crawler name (ornull).craft.crawlerDetect.getUserAgent(): Returns the inspected user-agent string.craft.crawlerDetect.getCrawlerDetect(): Returns the underlyingJaybizzle\CrawlerDetect\CrawlerDetectinstance for advanced usage.
Development
Run development tools and checks:
# Check code style with ECS composer check-cs # Format code style with Pint composer pint # Verify code style with Pint composer pint-test # Run static analysis (PHPStan Level 8) composer phpstan