beast/visitor-tracker-bundle
Install the Bundle
composer require beast/visitor-tracker-bundle
Add to config/bundles.php if not auto-discovered:
return [
// ...
Beast\VisitorTrackerBundle\VisitorTrackerBundle::class => ['all' => true],
];
Enable Tracking
Configure in config/packages/visitor_tracker.yaml:
visitor_tracker:
enabled: true
anonymize_ip: true # Recommended for GDPR compliance
geo_lookup: false # Enable if you need country/city data
First Use Case: Debug a Slow Request Trigger a request, then run:
php bin/console visitor:tracker:list --limit=5
Output will show request metadata, duration, and memory usage.
Development Debugging
visitor:tracker:show <id> to inspect a specific request.php bin/console visitor:tracker:show 12345
Reveals IP, user agent, route, and performance metrics.CLI-Driven Analytics
# Top routes by traffic
php bin/console visitor:tracker:routes --limit=10
# Detect 5xx errors
php bin/console visitor:tracker:errors --status=5xx
# UTM campaign analysis
php bin/console visitor:tracker:utm --campaign=summer-sale
Integration with Symfony Events
// src/EventListener/CustomTrackerListener.php
namespace App\EventListener;
use Beast\VisitorTrackerBundle\Event\TrackVisitorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CustomTrackerListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
TrackVisitorEvent::NAME => 'onTrackVisitor',
];
}
public function onTrackVisitor(TrackVisitorEvent $event)
{
$event->getVisitor()->setMetadata('subscription', 'premium');
}
}
GeoIP Enrichment (Optional)
visitor_tracker:
geo_lookup: true
geo_service: 'maxmind' # or 'ip-api'
Then filter by country:
php bin/console visitor:tracker:list --country=US
Performance Overhead
visitor_tracker:
enabled: false # Set to false for production
visitor:tracker:purge to clear old logs periodically.GeoIP Service Dependencies
composer require geoip2/geoip2) and update config:
visitor_tracker:
geo_service: 'maxmind'
geo_database: '%kernel.project_dir%/var/GeoLite2-City.mmdb'
Anonymization Conflicts
anonymize_ip: false, stored IPs may violate GDPR/privacy laws.visitor_tracker:
anonymize_ip: true
Log Rotation
php bin/console visitor:tracker:purge --older-than=30days
Verify Tracking Check if the bundle is active:
php bin/console debug:config visitor_tracker
Look for enabled: true.
Inspect Visitor Data
Use visitor:tracker:show to debug a specific request. Example output:
ID: 12345
IP: 192.0.2.1 (anonymized)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)
Route: app.homepage
Duration: 123ms
Memory: 2.1MB
Metadata: {"subscription": "premium"}
Custom Metadata Serialization
Visitor class or use JSON strings:
$event->getVisitor()->setMetadata('tags', json_encode(['newsletter', 'vip']));
Add Custom Fields
Extend the Visitor entity (override in a custom bundle):
// src/Entity/CustomVisitor.php
namespace App\Entity;
use Beast\VisitorTrackerBundle\Entity\Visitor;
class CustomVisitor extends Visitor
{
private $customField;
// Add getters/setters and update mapping in config.
}
Override CLI Commands Replace or extend commands by creating a custom command that calls the original:
// src/Command/CustomTrackerCommand.php
use Beast\VisitorTrackerBundle\Command\ListTrackerCommand;
class CustomTrackerCommand extends ListTrackerCommand
{
protected function configure()
{
$this->setName('app:visitor:custom-list');
parent::configure();
}
}
Hook into Tracker Events
Subscribe to TrackVisitorEvent for real-time modifications:
// src/EventSubscriber/TrackerSubscriber.php
use Beast\VisitorTrackerBundle\Event\TrackVisitorEvent;
class TrackerSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [TrackVisitorEvent::NAME => 'onTrack'];
}
public function onTrack(TrackVisitorEvent $event)
{
if ($event->getVisitor()->isBot()) {
$event->setMetadata('bot_type', 'known');
}
}
}
Change Log Storage Override the default logger to use a database or external service:
visitor_tracker:
logger: 'monolog.logger.visitor' # Custom logger name
Then configure the logger in monolog.yaml.
How can I help you explore Laravel packages today?