Skip to content

Commit 0d146fe

Browse files
Sofie Toft Kristensengitbook-bot
authored andcommitted
GITBOOK-62: Expanded the Engage Headless documentation
1 parent 3704322 commit 0d146fe

File tree

2 files changed

+129
-24
lines changed

2 files changed

+129
-24
lines changed

13/umbraco-engage/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
* [Custom goals scoring](developers/settings/custom-goals-scoring.md)
125125
* [Configuration](developers/settings/configuration.md)
126126
* [Headless](developers/headless/README.md)
127-
* [Using the Marketing API](developers/headless/using-the-marketing-api.md)
127+
* [Using the Engage API](developers/headless/using-the-marketing-api.md)
128128
* [Headless Example](developers/headless/headless-example.md)
129129

130130
## Security and Privacy

13/umbraco-engage/developers/headless/using-the-marketing-api.md

Lines changed: 128 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
---
22
description: >-
3-
Learn how to use the Headless API to track page views, personalize content,
4-
and manage segmentation for visitors.
3+
Learn how to use the Umbraco Engage API to track page views, personalize
4+
content, and manage segmentation for visitors.
55
---
66

7-
# Using the Marketing API
7+
# Using the Engage API
88

9-
After setting up the Umbraco Engage Headless API, let us learn how to use it.
9+
After setting up the Umbraco Engage API, let us learn how to use it.
1010

11-
## Summary
11+
With the installation of `Umbraco.Engage.Headless` you can track visitor page views, personalize content, and manage segmentation for visitors through the Umbraco Engage API. Personalized content and A/B tests work with Umbraco's Content Delivery API, delivering the correct content. For more details on how to use and query content from Umbraco, see the [Umbraco Documentation](https://docs.umbraco.com/umbraco-cms/reference/content-delivery-api#enable-the-content-delivery-api).
1212

13-
Umbraco Engage segmented content and A/B tests work with Umbraco's Content Delivery API, delivering the correct content. For more details on how to use and query content from Umbraco, see the [Umbraco Documentation](https://docs.umbraco.com/umbraco-cms/reference/content-delivery-api#enable-the-content-delivery-api).
13+
The steps to track & retrieve personalized content are as follows:
1414

15-
To track user activity and assign segments or personas, make an HTTP POST request to:
15+
1. A new visitor visits their first page. An HTTP POST request is made to the `analytics/pageview/trackpageview/client` endpoint with the requested URL. This returns an External Visitor ID unique to this visitor.
16+
2. Content is retrieved for that visitor through the Umbraco Content Delivery API. The External Visitor ID is used as the `External-Visitor-Id` header to retrieve content for that specific visitor.
17+
3. The page is rendered using the retrieved content and returned to the visitor.
18+
4. The same visitor visits another page. An HTTP POST request is made to the `analytics/pageview/trackpageview/client` endpoint with the requested URL **and** the _External-Visitor-Id_ header. This pageview will be attributed to the same visitor.
1619

17-
**/umbraco/engage/api/v1/analytics/pageview/trackpageview/client** endpoint
20+
{% hint style="info" %}
21+
_Without providing the_ `External-Visitor-Id` _header, each registered pageview will be considered as a new visitor._
22+
{% endhint %}
1823

19-
with the following JSON body to indicate what page the user has visited.
24+
5. Repeat these steps for each page visit for a new or existing visitor.
2025

21-
```json
22-
{ "url": "https://localhost:44374"}
23-
```
24-
25-
This determines if the user meets criteria for segmenting, A/B testing, or applying personalization. Subsequent requests to the Umbraco content API then deliver personalized content.
26+
By tracking visitor behavior, Engage determines if the user meets criteria for segmenting, A/B testing, or applying personalization. Subsequent requests to the Umbraco content API then deliver personalized content.
2627

2728
Umbraco Engage needs to be explicitly notified because a single request to Umbraco's Content Delivery API represents one page visit.
2829

2930
## Configuration
3031

3132
Umbraco Engage Headless package settings can be configured through .NET options, including AppSettings JSON file, Environment Variables, or other configuration sources.
3233

33-
An example of configuration in AppSettings.json file:
34+
An example of configuration in `AppSettings.json` file:
3435

3536
```json
3637
"Engage": {
@@ -45,7 +46,7 @@ An example of configuration in AppSettings.json file:
4546
}
4647
```
4748

48-
The settings can be changed at runtime without restarting the website for these changes to take effect.
49+
The settings can be changed at runtime without restarting the website for these changes to take effect. These configurations will toggle whether Umbraco Engage will apply segmentation to the various Content Delivery API endpoints when applicable.
4950

5051
| **Key** | **Description** | **Default Value** |
5152
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
@@ -69,7 +70,18 @@ To track a page view, send a POST request to:
6970
* Can notify Umbraco Engage when a page view has taken place and provide extra information.
7071
* Requests extra metadata like `headers`, `browserUserAgent`, `remoteClientAddress`, and `userIdentifier`.
7172

72-
**Client and Server**
73+
Both API endpoints will return the following response:
74+
75+
```json
76+
{
77+
"externalVisitorId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
78+
"pageviewId": "64955e29-4edf-475a-b154-aa8efd1f3724"
79+
}
80+
```
81+
82+
The `externalVisitorId` is unique to this visitor and is to be used in subsequent API calls for this visitor, and this visitor only. The pageviewId is unique to this specific pageview and used in specific API's like tracking events on pageviews.
83+
84+
#### **Client and Server**
7385

7486
Umbraco Engage gathers information about visitors based on their requests, extracting details from your request like HTTPContext.
7587

@@ -89,20 +101,113 @@ Optionally, provide an External-Visitor-Id header in order to automatically upda
89101

90102
### Segmentation - Assets
91103

92-
`/umbraco/engage/api/v1/segmentation/assets/item/{path}` `/umbraco/engage/api/v1/segmentation/assets/item/{id}`
104+
`/umbraco/engage/api/v1/segmentation/assets/item/{path}` 
105+
106+
`/umbraco/engage/api/v1/segmentation/assets/item/{id}`
93107

94-
These requests let you verify if a content page, by ID or Path, has a **JavaScript** or **CSS** variant available for page injection.
108+
These requests let you verify if a content page has a **JavaScript** or **CSS** variant available for page injection for this specific visitor. This endpoint requires the External-Visitor-Id header to function. This returns the following response:
109+
110+
```json
111+
{
112+
"javascript": [
113+
"alert('hello world')"
114+
],
115+
"css": [
116+
"body { background-color:red; }"
117+
]
118+
}
119+
```
95120

96121
![Add custom code for variant](../../.gitbook/assets/engage-headless-segment-css.png)
97122

98123
### Segmentation - Content
99124

100-
`/umbraco/engage/api/v1/segmentation/content/segments` `/umbraco/engage/api/v1/segmentation/content/segments/{path}` `/umbraco/engage/api/v1/segmentation/content/segments/{id}`
125+
`/umbraco/engage/api/v1/segmentation/content/segments` 
126+
127+
`/umbraco/engage/api/v1/segmentation/content/segments/{path}`
128+
129+
 `/umbraco/engage/api/v1/segmentation/content/segments/{id}`
101130

102-
These requests return details about segments (personalization and A/B testing) configured for a page. This helps determine if content can be changed by Umbraco Engage or cached more aggressively.
131+
These requests return details about segments (personalization and A/B testing) configured for a page. This helps determine if content can be changed by Umbraco Engage or cached more aggressively. The information returned by the APIs is visitor agnostic and reflects all the segments as configured in Umbraco. This returns the following response:
132+
133+
```json
134+
{
135+
"segmentedContent": [
136+
{
137+
"contentTypeAlias": "home",
138+
"contentId": 1097,
139+
"contentGuid": "ca4249ed-2b23-4337-b522-63cabe5587d1",
140+
"contentUrls": [
141+
"/",
142+
"https://umbraco.com/",
143+
"https://umbraco.com/en/"
144+
],
145+
"segments": [
146+
{
147+
"umbracoSegmentAlias": "engage_personalization_1",
148+
"segmentId": 1,
149+
"segmentName": "All Developers",
150+
"segmentType": "Personalization",
151+
"segmentApplicationType": "SinglePage"
152+
},
153+
{
154+
"umbracoSegmentAlias": "engage_personalization_2",
155+
"segmentId": 2,
156+
"segmentName": "All Marketeers",
157+
"segmentType": "Personalization",
158+
"segmentApplicationType": "SinglePage"
159+
}
160+
]
161+
},
162+
...
163+
]
164+
}
165+
```
103166

104167
### Segmentation - Visitor
105168

106-
`/umbraco/engage/api/v1/segmentation/content/activesegments/{path}` `/umbraco/engage/api/v1/segmentation/content/activesegments/{id}`
169+
`/umbraco/engage/api/v1/segmentation/content/activesegments/{path}`
170+
171+
 `/umbraco/engage/api/v1/segmentation/content/activesegments/{id}`
172+
173+
These requests return the segment (personalization and A/B testing) that the current visitor ID of that specific page belongs to. This endpoint requires the External-Visitor-Id header to function. 
174+
175+
This returns the following response:
176+
177+
```json
178+
{
179+
"contentTypeAlias": "home",
180+
"contentId": 1097,
181+
"contentGuid": "ca4249ed-2b23-4337-b522-63cabe5587d1",
182+
"contentUrls": [
183+
"/",
184+
"https://umbraco.com/",
185+
"https://umbraco.com/en/"
186+
],
187+
"segments": [
188+
{
189+
"umbracoSegmentAlias": "engage_personalization_1",
190+
"segmentId": 1,
191+
"segmentName": "All Developers",
192+
"segmentType": "Personalization",
193+
"segmentApplicationType": "SinglePage"
194+
}
195+
]
196+
]
197+
}
198+
```
199+
200+
### Cookies & External Visitor IDs
201+
202+
Umbraco Engage in a non-headless setup uses cookies to track returning visitors. This, however, has proven difficult to work with in a headless setup for most clients. Therefore, it is not a recommended way of working with the Engage API. 
203+
204+
Each API endpoint that allows for tracking analytics, segmentation, and retrieving content has support for adding the External Visitor ID header. This is a unique ID for an individual visitor and is to be used instead of the cookie. When tracking pageviews, a new External Visitor ID will be generated and is to be used for subsequent API calls corresponding to that visitor.
205+
206+
{% hint style="info" %}
207+
A visitor will be considered an **existing visitor** when either of the following applies to the request:
208+
209+
* An `umbracoEngageAnalyticsVisitorId` cookie is present.
210+
* An `External-Visitor-Id` Header is provided.
107211

108-
These requests return the segment (personalization and A/B testing) that the current visitor ID of that specific page belongs to based on its cookie.
212+
If neither applies, the requests will be considered coming from a new visitor.
213+
{% endhint %}

0 commit comments

Comments
 (0)