You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 16/umbraco-engage/marketers-and-editors/personalization/extending-personalization/implement-custom-segment-parameters.md
+99-16Lines changed: 99 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,20 +5,21 @@ description: >-
5
5
6
6
# Implement your own segment parameters
7
7
8
-
Umbraco Engage comes with various built-in segment parameters to build a segment, such as "Customer Journey" and "Time of Day". However, you may want to build segments with custom rules that are not part of Engage by default. We've got you covered; you can add your own custom segment parameters to the Engage.
8
+
Umbraco Engage comes with built-in parameters to build a segment, such as "Customer Journey" and "Time of Day".
9
+
However, you may want to build segments with custom rules that are not part of Engage by default. We've got you covered; you can add your own custom segment parameters to Engage.
9
10
10
11
The following guide will explain how this can be done. Note this is aimed at developers.
11
12
There are 3 steps, 2 of which are mandatory and the 3rd is optional:
12
13
13
14
1. C# definition
14
-
2.AngularJS definition
15
-
3.(optional) Cockpit visualization
15
+
2.Web component definition
16
+
3. Cockpit visualization (optional)
16
17
17
18
This guide will use concrete code samples to add a "Day of week" segment parameter where you can select a single day of the week. If a pageview happens on that day the segment parameter will be satisfied.
18
19
19
20
## 1. C# definition
20
21
21
-
Your custom segment parameter will need to be defined in C# in order for the Engage to use it.
22
+
Your custom segment parameter will need to be defined in C# in order for Engage to use it.
22
23
In code we refer to a segment parameter as a "segment rule".
23
24
24
25
A segment rule is not much more than this:
@@ -70,7 +71,8 @@ public class DayOfWeekSegmentRuleFactory : ISegmentRuleFactory
70
71
}
71
72
```
72
73
73
-
We are using the class DayOfWeekSegmentRuleConfig as a representation of the configuration of the rule, which is not strictly necessary but makes it easier. The configuration is stored as a string in the database but in code we like to have intellisense so we parse the stored configuration to this class:
74
+
We are using the class DayOfWeekSegmentRuleConfig to represent the rule configuration. This is not strictly necessary but makes it easier.
75
+
The configuration is stored as a string in the database. In code we like to have intellisense so we parse the stored configuration to this class:
74
76
75
77
```c#
76
78
//Generating config schema on client side.
@@ -83,19 +85,87 @@ public class DayOfWeekSegmentRuleConfig
83
85
84
86
That's the C# part of the custom segment parameter.
85
87
86
-
## 2. Lit definition
88
+
## 2. Web component definition
87
89
88
-
We have implemented the business logic for the segment parameter in the previous step, but the parameter cannot be added to your segments in the backoffice yet. In this step we will add a Lit element to enable you to add and configure your segments in the Engage segment builder.
90
+
We have implemented the business logic for the segment parameter, but the parameter cannot be used in the backoffice yet. In this step we will add a web component to render the new rule in the Engage segment builder.
89
91
90
92
These steps will once again show concrete code samples that belong to our demo parameter "Day of week".
93
+
You can create a folder to manage new files. Those files look like this:
94
+
* segment-rule-base.ts
95
+
* Type declaration for UeSegmentRuleBaseElement from Umbraco Engage. This is a temporary declaration until Umbraco Engage provides an npm package.
96
+
* segment-rule-day-of-week.ts
97
+
* Declaration for your web component using Lit.
98
+
* index.ts
99
+
* Exporting all your elements.
100
+
* manifest.ts
101
+
* Declares your element as a backoffice extension and register it in the Extension Registry. Read more about Extension Manifest [here](../../../../umbraco-cms/customizing/extending-overview/extension-registry/extension-manifest.md/).
91
102
92
103
First, re-generate the DayOfWeek config type on client side using the below command
93
104
94
105
```text
95
106
npm run generate:api
96
107
```
97
108
98
-
Then, create a new Lit element, implemeting new "Day of week" segment.
export { UeSegmentRuleDayOfWeekElement } from "./segment-rule-day-of-week.js";
240
+
export { UeSegmentRuleBaseElement } from "./segment-rule-base.js";
241
+
```
167
242
168
243
**manifest.ts**
169
244
170
245
```json
171
246
{
172
-
name: "Day of week",
173
-
type: "DayOfWeek",
174
-
icon: "icon-calendar",
175
-
elementName: "day-of-week",
176
-
config: { dayOfWeek: "Sunday" },
247
+
type: ENGAGE_SEGMENT_RULE_EXTENSION_TYPE,
248
+
name: 'Engage Day of Week Segment Rule',
249
+
alias: 'Engage.Segment.Rule.DayOfWeek',
250
+
elementName: 'ue-segment-rule-day-of-week',
251
+
weight: 100,
252
+
meta: {
253
+
name: 'Day of week',
254
+
icon: 'icon-calendar',
255
+
type: 'DayOfWeek',
256
+
config: { dayOfWeek: 'Sunday' },
257
+
},
177
258
}
178
259
```
179
260
180
261
That's it. If all went well you will see your custom parameter editor show up in the segment builder:
181
262
182
263
<figure><imgsrc="../../../.gitbook/assets/engage-tutorials-personalized-segments-v16.png"alt="Day of week Segment."><figcaption><p>Day of week Segment.</p></figcaption></figure>
183
264
184
-
## 3. (optional) Cockpit visualization
265
+
## 3. Cockpit visualization (optional)
266
+
267
+
The new segment parameter will show up automatically in the Cockpit that is part of our package. The cockpit is a live view of Engage data for the current visitor. This includes active segments of the current visitor, and therefore your new segment parameter can also show up in the cockpit.
185
268
186
-
The new segment parameter will show up automatically in the Cockpit that is part of our package. The cockpit is a live view of Engage data for the current visitor. This includes active segments of the current visitor, and therefore your new segment parameter can also show up in the cockpit. By default it will simply display the the raw configuration of the parameter as stored in the database ("{ dayOfWeek: Thursday }" in our example), and if you hover over it you will see the rule identifier "DayOfWeek" rather than a friendly name.
269
+
By default it will simply display the the raw configuration of the parameter as stored in the database ("{ dayOfWeek: Thursday }" in our example), and if you hover over it you will see the rule identifier "DayOfWeek" rather than a friendly name.
0 commit comments