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
You may want to build segments with custom rules not part of the Umbraco Engage by default. You can add your custom segment parameters to Umbraco Engage.
10
+
You may want to build segments with custom rules not included in Umbraco Engage by default. You can add your custom segment parameters to Umbraco Engage.
11
11
12
-
In the following guide, we will show how this is done. There are 3 steps:
12
+
In the following guide, we will show how this is done. There are three steps:
This guide will use 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.
19
19
20
20
You can download the following code files to your project to add the parameter directly to your solution.
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:
In the above example, we have shown how you can define custom segment parameters using C#. Next we look into enabling and configuring our segment in the Umbraco Engage segment builder.
80
105
81
-
## 2. AngularJS definition
106
+
## 2. AngularJS Definition
82
107
83
108
We implemented the business logic for the segment parameter in the previous step, however, the parameter cannot be added to your backoffice segments yet. In this step, we will add some JavaScript and HTML to enable you to add and configure your segments in the Umbraco Engage segment builder.
84
109
85
110
This step will show concrete code samples that belong to our demo parameter "**Day of week**".
86
111
87
-
\
88
112
You need to create a folder in the _App\_Plugins_ folder of your project that will hold the new files.
89
113
90
114
For this example name it "`day-of-week`". The folder and content look like this:
@@ -111,11 +135,69 @@ The contents for each of the files are below:
111
135
112
136
In this file, you define the segment parameter and register it in the repository of Umbraco Engage.
113
137
114
-
{% code overflow="wrap" %}
115
138
```javascript
116
-
// If you have your own custom module, use this:// angular.module("myCustomModule", ["Engage"]);// angular.module("umbraco").requires.push("myCustomModule");// angular.module("myCustomModule").run([ ... ]) angular.module("umbraco").run([ "umsSegmentRuleRepository", function (ruleRepo) { var rule = { name: "Day of week", // Friendly name type: "DayOfWeek", // Rule type / identifier iconUrl: "/path/to/icon.png", // You can also reuse existing Umbraco Engage icons by specifying the "icon" // property rather than the "iconUrl" property. Use either one or the other, not both. // icon: "icon-browser", order: 4, // Position in segment builder // Default config is passed in to your editor when a user adds the rule to the segment defaultConfig: { dayOfWeek: null }, // If you need any data in your editor, specify it here data: { days: { 0: "Sunday", 1: "Monday", 2: "Tuesday", 3: "Wednesday", 4: "Thursday", 5: "Friday", 6: "Saturday", } }, // Specify the names of the display and editor components here. // These will be dynamically rendered in our segment builder and in some other // places. components: { display: "segment-rule-day-of-week-display", editor: "segment-rule-day-of-week-editor", }, init: function() { // Optional. Use this in case you need to fetch some data // for your segment parameter. // For example, the built-in "Browser" segment parameter will fetch // the list of possible browsers here and will update the "data" property. // The "thisArg" of this function is set to the rule definition object, // i.e. if you use "this.data" in this callback you can manipulate the data object // of this rule. } }; ruleRepo.addRule(rule); }]);
<selectng-options="value as day for (value, day) in $ctrl.rule.data.days"ng-model="$ctrl.config.dayOfWeek">
214
+
<selectng-options="value as day for (value, day) in $ctrl.rule.data.days"
215
+
ng-model="$ctrl.config.dayOfWeek">
133
216
<optionvalue="">- Select -</option>
134
217
</select>
135
218
</ums-segment-rule-editor>
@@ -140,30 +223,37 @@ We use the `data.days` property of our rule definition in the editor. The editor
140
223
This registers the editor component in the Umbraco Engage module so we can use it.\
141
224
It should not be necessary to update this file other than update the component name and `templateUrl`.
142
225
143
-
{% code overflow="wrap" %}
144
226
```javascript
145
-
// If you have your own custom module, use that name instead of "umbraco" here.angular.module("umbraco").component("segmentRuleDayOfWeekEditor", { templateUrl: "/App_Plugins/day-of-week/segment-rule-day-of-week-editor.html", bindings: { rule: "<", config: "<", save: "&", },});
227
+
// If you have your own custom module, use that name instead of "umbraco" here.
We store the chosen day of the week as an integer 0-6 ($ctrl.config.dayOfWeek) but in the display component, we want to show the actual day (e.g. `Monday`). Our rule definition defines the mapping in its `data.days` property so we convert it using that and display the name of the day.
161
251
162
252
*`segment-rule-day-of-week-display.js`
163
253
164
254
In this file, we register the display component.
165
255
166
-
```
256
+
```csharp
167
257
// If you have a custom module, use that name instead of "umbraco"
@@ -191,7 +281,7 @@ If all goes well you will see your custom parameter editor show up in the segmen
191
281
192
282

193
283
194
-
## 3. (Optional) Cockpit visualization
284
+
## 3. \[Optional] Cockpit Visualization
195
285
196
286
The new segment parameter will show up automatically in the [Cockpit](../../../../personalization/cockpit-insights/) that is part of our package. The cockpit is a live view of Umbraco Engage data for the current visitor.
197
287
@@ -206,7 +296,27 @@ If you want to change this to be more readable you can implement the `Umbraco.En
206
296
For the `DayOfWeek` demo parameter, this is the implementation:
So we transform the JSON into a human-readable representation and we configure an icon to show up in the cockpit. Make sure to register this class in a composer (you can reuse the composer from the first step):
Copy file name to clipboardExpand all lines: 13/umbraco-engage/developers/profiling/external-profile-data.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,15 +23,27 @@ When this component is registered a new tab will be rendered in the Profiles sec
23
23
24
24
To render this External Profile Tab with a custom component, you have to create your component and register it with Umbraco Engage. The following code will show how to do both. Add the below code in a JavaScript file in the `App_Plugins` folder and load it using a `package.manifest` file. If you have your own custom module, you can use this:
// Create a component. We create a component named "myCustomExternalProfileDataComponent" here:
32
31
33
-
angular.module("umbraco").component("myCustomExternalProfileDataComponent", { bindings: { visitorId:"<" }, template:"<h1>My custom external profile data component! visitorId = {{$ctrl.visitorId}}</h1>", controller: [function () { this.$onInit=function () { // Your logic here } }]});// Register your custom external profile data component.// Please note you have to use kebab-case for your component name here// just like how you would use it in an AngularJS template (i.e. myCustomComponent -> my-custom-component)angular.module("umbraco").run(["myCustomComponents", function (customComponents) { customComponents.profiles.externalProfileData = "my-custom-external-profile-data-component";}]);
0 commit comments