Segment Nesting

Marketers usually segment users based on multiple criteria such as User Property rules (User Attributes), User activity rules (Event Attributes), User Affinity rules, and Custom Segments. Most of the time, a combination of multiple criteria using AND or OR conditions is used to create a complex user segment. 

For better understanding, let’s say A, B, C, and D represent the ‘segment blocks’, which are events & user attributes with all their filters. For example, A can be ‘users who are male’, B can be ‘users who added to cart: wallet in the last 3 days, and so on. You can always create segments like A AND B AND C AND D and A OR B OR C OR D by combining segment blocks using AND/OR operators.

AND

But when a complex segment like ‘(users who are male AND added to the cart: wallet in the last 3 days), OR (users who are female AND added to cart: handbag in the last 3 days)’ is required, it cannot be simply done using just these operators. The reason being either AND, or OR, only one of these will be used to combine these segment blocks. A combination of AND as well as OR cannot be used together. If you change one of the operators in the definition, the rest will automatically change. This is when nesting comes into the picture.

What is Nesting?

When a complex segment like the above example is to be created, we will need to group some of the segment blocks. Logically, if the segment blocks A and B are grouped inside brackets i.e. ‘(A AND B)’, then they are multiple segment blocks ‘nested’ together. So a combination of segment blocks represents the ‘nested blocks’.

With the nested AND/OR capabilities, you can create complex segments with combinations such as:

  • (A AND B) OR (C AND D). Here, (A AND B) and (C AND D) are 2 nested blocks combined together with the OR operator.
  • (A OR B) AND (C OR D). Here, (A OR B) and (C OR D) are 2 nested blocks combined together with the AND operator.
  • (A OR B) AND C AND D. Here, (A OR B) is 1 nested block combined together with 2 other segment blocks C and D using the AND operator.
  • (A AND B) OR C OR D. Here, (A AND B) is 1 nested block combined together with 2 other segment blocks C and D using the OR operator.

Nested

Understanding Nesting Levels

The examples mentioned above have 1 level of nesting. As in, for the complex segment (A AND B) OR (C AND D). In the above example A, B, C, and D have simple definitions using user attributes or event attributes. Those are not segments, those are simple user attributes or event attributes.

But when the A, B, C, or D are in itself a nested block or a segment instead of simple definitions, they will have more than 1 level of nesting.

Actions that increase the nesting level:

  1. By using a custom segment in a query: If a custom segment is used in a query it increases the nesting level of query in below way:
    [Nesting level of that query = nth level of custom segment + 1 Level increase]

  2. By using a nested filter in a query: If a nested filter is used in a query it increases the nesting level of the query by 1 level 

Note

info
  1. Using the normal filter button to the query will not affect the nesting level. Any custom segment created using this logic will create a custom segment with nesting level 1. 
  2. Adding multiple nested filters to the query will not add to the nesting level by subsequent levels. At least 1 nested filter is sufficient to increase the nesting level by 1. 

Various cases of nesting levels:

Custom segment Definition Nesting level
Type 1

Created a segment using attributes (no nested filter)


Or


Created a segment using attributes and nested filter

Level 1
Type 2 Created a segment using only 1 custom segment of Level 1/Type 1 Level 2
Type 3

Created a segment using 2 linked custom segments (only segments and no nested filters in their definition) - Eg: A -> B -> C, so C will be a Custom Segment of level 3 which has Custom Segment B (Level 2) and Custom Segment A (Level 1) nested/linked inside it.


Or


Created a segment using a custom segment of Level 1/Type 1 with at least 1 nested filter

Level 3
Type 4 1 segment (of Level 2/Type 2) + 1 attribute outside with nested filter More than 3 level of nesting
Type 5 2 linked segment inside + 1 attribute outside with nested filter More than 3 level of nesting
Type 6 Created using 4 linked segment More than 3 level of nesting 

Let’s understand this using few examples:

Case 1: Level 1 Nesting

F is an event “Has executed App Inbox Icon Clicked atleast 1 time in the last 3 days”

G is an event “Email viewed in Browser”

H is an user attribute “Install status is True” 

I is an event “WhatsApp message clicked”

Here, the nesting level is 1 (one) because:

  1. Any custom segment created only using attributes or nested filter will create a custom segment of Level 1

For example, if a custom segment E is created using these attributes, let’s say with a definition, E = (F AND G) OR (H AND I), the level of nesting for segment E will be 1. Here, the OR is a normal filter and AND is a nested filter. 

OR

By simply creating a custom segment with an user property or user behavior

The nesting level of the custom segment will be 1 in this case.

Segment F = Nesting level 1 

Case 2: Level 2 Nesting

Let’s say, Segment F = Unsubscribe is False

Using this Segment F (of nesting Level 1) in a query to create another custom segment

The above query is of nested level 2, the nesting level in this case is defined as:

  1. Nesting level of that query = nth level of custom segment + 1 Level increase

Thus, Nesting level of the above query = Level 1 (Segment F) + 1 Level = Level 2

Case 3: Level 3 Nesting

Definition of segment: F is a custom segment made up of event attribute “Best time to send Email is between 10 Hrs and 13 Hrs. This will create a custom segment F of nesting level 1.

If this created custom segment F (Seg F - Nesting level 1) is used in the query along with other attributes, as shown below:

Here the level of nesting for the query is 3 because:

  1. Two level because a custom segment F (of nesting level 1) has been added in the query (Level 1 of custom segment F + 1 Level = Nesting Level 2)
  2. Another level - Using nested filter an event attribute is used that increases the nesting level to 2

If this query is used to create a custom segment, the created custom segment will be of nesting level 3.

OR

If you create a custom segment with 2 custom segments inside it, it will create a query of level 3.

Example:

Let’s say, Segment cs_level_1 = Created a custom segment of level 1 using an attribute (Has executed Allowed web Push Subscription atleast 1 time in the last 3 days)

Segment cs_level_2 = Created a level 2 custom segment by adding custom segment cs_level_1 in the query

Level 2 = 1 level of cs_level_1 + 1 level of nesting (as per rule mentioned in the beginning)

Cs_level_3 = Created a level 3 custom segment by adding custom segment cs_level_2 in the query

Level 3 = 2 level of cs_level_2 + 1 level of nesting (as per rule mentioned in the beginning)

Case 4: > Level 3 Nesting

Definition of segment: F is a custom segment made up of user or event attributes J, K, L, M and F is used as a custom segment in Segment E’s definition

F is a nested segment defined as - (J OR K) AND (L OR M). 

J is an event “Has executed Notification Received Android predominantly with (Device Model is Nexus 5 (case insensitive) ) in the last 3 days”

K is an user attribute “Best time to send Email is between 10 and 13”

L is an user attribute “SPAM is false”

M is an user attribute “Mobile user is True”


In the above image, the query has 2 levels of nesting and if the segment F is created using these filters the nesting level will be 2 (E -> F -> J.)

If the above Custom segment F (Level 2 nesting) is used in a query, it will increase the nesting level of the query to 3. As per definitions above.

Where E = (F and G) OR (H AND I)

So the overall segment E is now defined as -  (  {(J OR K) AND (L OR M)}  AND G) OR (H AND I).

 

Here the Level of nesting for the given query is 4 because:

  1. Three levels because a custom segment F (of nesting level 2) has been introduced (Level 2 of custom segment F + 1 Level = Level 3) - as per rule mentioned in the beginning.
  2. Another level - Using nested filter an event attribute is used that increases the nesting level to 4

If this query is used to create a custom segment, the created custom segment will be of nesting level 4. So, the segment E will not be processed as it will become level 4 nesting. 

How to use nested filters

Use the '+ Nested Filter' button to add a nested block. To create a segment with more than one level of nesting, you will need to create a custom segment first (segment E in the above example) and then use the custom segment in the filters.

The nested condition will be preselected, opposite to the outer condition. So, if the outer condition is AND, the nested condition will be OR (ex: (A AND B) OR (C AND D)) and vice-versa (ex: (A OR B) AND (C OR D)). 

Both the nested as well as the outer conditions can be changed. When the outer condition is changed (let's say, from AND to OR), the nested condition automatically gets updated to the opposite condition (in this case, OR to AND) and vice versa. 

Nested AND/OR functionalities are available in segmentation as well as campaign creation pages in the target audience section. They are not supported in Trigger Criteria in Event-triggered campaigns.

A particular user segment can also be excluded from the selected user segment. To use this, click on Exclude user checkbox.

MoEngage supports up to 3 levels of nesting. These combinations offer flexibility in defining specific conditions for segmenting your users.

How to simplify if there are more than 3 levels of nesting?

Segment queries are logical expressions of conditions. Any logical expression can be simplified into 1 level of nesting. Logical rules can be utilized to simplify it.

Logical rules used to simplify the nesting - 

  • (X AND Y) AND Z  =  X AND Y AND Z
  • (X OR Y) OR Z  =  X OR Y OR Z
  • (X AND Y) OR Z  =  (X OR Z) AND (Y OR Z)
  • (X OR Y) AND Z  =  (X AND Z) OR (Y AND Z)

Here is an example of making a multi-nested segment into 1 level of the nested segment:

Let's say we have a segment block of A & B with a condition - A AND B

 

Segment block A has another definition - A =  C OR D
Then, the expanded definition of the segment - (C OR D) AND B

 

Segment block C has another definition - C = E AND F
Then, the expanded definition of the segment - ((E AND F) OR D) AND B

Simplifying this - (E OR D) AND (F OR D) AND B

 

Segment block E has another definition - E = G AND H

Then, the expanded definition of the segment - ((G AND H) OR D) AND (F OR D) AND B

Simplifying this - (G OR D) AND (H OR D) AND (F OR D) AND B

 

With the above example, we can understand that any segment definition can be broken down 

into 1 level of nesting.

 

 

Was this article helpful?
0 out of 1 found this helpful

How can we improve this article?