Events
The targeting engine dispatches Symfony events throughout the request lifecycle, and the Pimcore Studio backend fires pre-response events for the Personalization API. Subscribe to these events to hook into targeting without overriding the engine's services.
Targeting Lifecycle Events
Defined as constants on
TargetingEvents:
| Constant | Event name | Event class | Dispatched from |
|---|---|---|---|
PRE_RESOLVE | pimcore.targeting.pre_resolve | TargetingResolveVisitorInfoEvent | VisitorInfoResolver::resolve(), before matching starts |
POST_RESOLVE | pimcore.targeting.post_resolve | TargetingEvent | VisitorInfoResolver::resolve(), after all rules matched |
PRE_RULE_ACTIONS | pimcore.targeting.pre_rule_actions | TargetingRuleEvent | VisitorInfoResolver, when a rule matches, before its actions run |
POST_RULE_ACTIONS | pimcore.targeting.post_rule_actions | TargetingRuleEvent | VisitorInfoResolver, when a rule matches, after its actions ran |
BUILD_CONDITION | pimcore.targeting.build_condition | BuildConditionEvent | ConditionFactory::build(), see Conditions |
ASSIGN_DOCUMENT_TARGET_GROUP | pimcore.targeting.assign_document_target_group | AssignDocumentTargetGroupEvent | DocumentTargetGroupListener, once per target group configured on a document's Target Groups panel |
TARGETING_CODE | pimcore.targeting.targeting_code | TargetingCodeEvent | TargetingCodeGenerator::generateCode(), see Frontend JavaScript |
RENDER_TOOLBAR | pimcore.targeting.render_toolbar | RenderToolbarEvent | ToolbarListener, before rendering the on-page debug toolbar |
VISITED_PAGES_COUNT_MATCH | pimcore.targeting.visited_pages_count_match | Symfony\Component\EventDispatcher\GenericEvent | VisitedPagesBefore::postMatch(), internal signal consumed by VisitedPagesCountListener to increment the visited-page count |
PRE_RESOLVE is documented on TargetingEvents as carrying a TargetingEvent, but the actual dispatch uses the
subclass TargetingResolveVisitorInfoEvent, which additionally exposes setVisitorInfo() so a listener can swap
in a different VisitorInfo instance before matching runs.
VISITED_PAGES_COUNT_MATCH is internal bookkeeping for the Visited Pages Before condition rather than a general
extension point, and carries no custom payload.
Example: Reacting to Rule Matches
<?php
namespace App\EventListener;
use Pimcore\Bundle\PersonalizationBundle\Event\Targeting\TargetingRuleEvent;
use Pimcore\Bundle\PersonalizationBundle\Event\TargetingEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RuleMatchedListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
TargetingEvents::POST_RULE_ACTIONS => 'onRuleMatched',
];
}
public function onRuleMatched(TargetingRuleEvent $event): void
{
$rule = $event->getRule();
$visitorInfo = $event->getVisitorInfo();
// e.g. forward the match to an analytics system
}
}
Target Group Model Events
Defined as constants on
TargetGroupEvents,
all carrying an Event\Model\TargetGroupEvent with the affected TargetGroup model:
| Constant | Event name | Dispatched from |
|---|---|---|
POST_ADD | pimcore.targetgroup.postAdd | TargetGroup::save(), when creating a new target group |
POST_UPDATE | pimcore.targetgroup.postUpdate | TargetGroup::save(), when updating an existing target group |
POST_DELETE | pimcore.targetgroup.postDelete | TargetGroup::delete() |
Pimcore Studio Pre-Response Events
The Personalization Studio API controllers under Controller/Studio are internal and may change without notice;
do not call them directly. The pre-response events below are the supported extension point: they let you add
custom data to the API response schemas the Studio frontend consumes. See the Studio Backend Bundle's
Additional and Custom Attributes
documentation for the general mechanism.
| Event name | Event class | Dispatched from |
|---|---|---|
pre_response.personalization.target_group.list | PreResponse\TargetGroupEvent | TargetGroupService::listTargetGroups(), once per persisted target group. The synthetic default entry added when includeDefault is requested is appended outside the dispatch loop and does not fire the event |
pre_response.personalization.target_group.detail | PreResponse\TargetingGroupDetailEvent | TargetGroupService::getGroup() |
pre_response.personalization.targeting_rule.list | PreResponse\TargetingRuleEvent | TargetingRuleService::listRules(), once per rule in the list |
pre_response.personalization.targeting_rule.detail | PreResponse\TargetingRuleDetailEvent | TargetingRuleService::getRule() |
Each event exposes the response schema object (for example getTargetGroup(), getTargetingRuleDetail()) and,
through the shared AbstractPreResponseEvent base class, hasAdditionalAttribute(), getAdditionalAttribute(),
addAdditionalAttribute() and removeAdditionalAttribute() to add or read custom data on the response.