Assigning Segments to Pimcore Elements
Besides customers, you can assign segments directly to other Pimcore elements, so elements like documents can be tagged with segments. Use this, for example, to track that a user visited several pages tagged with a certain segment, so that interacting with those elements creates a connection between the customer and the segment.
Configuration
Configure segment assignment to fit your needs in the Configuration chapter.
Allowed Element Types
Configure the element types segments can be assigned to in the Symfony configuration, for example:
pimcore_customer_management_framework:
segment_assignment_classes:
types:
document:
page: true
email: true
asset:
image: true
object:
object:
Product: true
ShopCategory: true
folder: true
Below types, every Pimcore element type has its own subtree. Each valid subtype is a boolean value, except for
object, where you specify explicit class names. All types default to false, so configure only the ones you need.
Segment Assignment
To assign segments to an element, open its Segment Assignment tab, visible once segment assignment is activated for
that element type, and assign segments by drag and drop or search.
Inheritance
Segment assignments are inherited along the element tree, so you can conveniently set them for whole groups of elements. This is not always desired.
Breaking the Chain of Inheritance
Use the checkbox to disable inheritance for any node in the tree. This also removes segments implicitly assigned by parents from that node's children.
Use Assigned Segments for Targeting and Personalization
Assigned segments are a valuable data source for targeting and personalization. Pimcore automatically issues
Track Segment actions whenever a user opens a document with assigned segments. This information is stored in
Pimcore's Targeting Store and available to Pimcore Targeting Rules. See
Personalization for details.
For assets and objects, no automatic action or functionality is provided.
Indexing
For scalable performance, both inherited and directly assigned segments are indexed in a separate table as a simple ID mapping.
Whenever an element's assigned segments are saved via SegmentAssignerInterface, that element and its children are
queued for indexing by IndexerInterface. Process that queue with the cmf:maintenance command (for example as a
cron job), or run bin/console cmf:segment-assignment-index to process it manually.
Working with Assignments
Retrieving Assigned Segments for an Element
To retrieve the segments assigned to an element, use
SegmentManagerInterface::getSegmentsForElement
or
SegmentManagerInterface::getSegmentsForElementId.
Both return an array of fully hydrated CustomerSegment objects.
Filter Elements by Assigned Segments
When working with Pimcore listings,
QueryServiceInterface
provides a condition that narrows the results down to elements assigned a specific segment, one or more segments, or
all segments in an array of IDs. The relevant element type is determined by the type of the provided listing, and the
condition is added to it directly.
<?php
$queryService = \Pimcore::getContainer()->get(QueryServiceInterface::class); // or however you access your services
$listing = new Listing();
$queryService->bySegmentIds($listing, [1, 2, 3], $concatMode = QueryServiceInterface::MODE_DISJUNCTION); // OR
$queryService->bySegmentIds($listing, [4, 5], $concatMode = QueryServiceInterface::MODE_CONJUNCTION); // AND

