-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathVTEX - Intelligent Search Events API - Headless.json
465 lines (465 loc) · 28.2 KB
/
VTEX - Intelligent Search Events API - Headless.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
{
"openapi": "3.0.0",
"info": {
"title": "VTEX Intelligent Search Events API - Headless",
"description": "Intelligent Search Events API is responsible for collecting the search events to improve your search results, such as page interactions and conversion, in a headless implementation. Some of the features improved by this collection are the possibility to sort the products by clicks or record the top search in the autocomplete.\r\n\r\n>⚠️ **This API applies only to Headless scenarios**. It doesn't apply to stores using Store Framework, since they are already integrated with all Intelligent Search features.\r\n\r\n## Building the request body\r\n\r\nIn the following sections, we explain the required structure for the request body for saving events. Check the `POST` [Save events](https://developers.vtex.com/docs/api-reference/intelligent-search-events-api-headless#post-/event) endpoint reference for more detailed field descriptions and examples.\r\n\r\nFull request example (Session Ping):\r\n\r\n```json\r\ncurl --request post \\\r\n\t--url https://sp.vtex.com/event-api/v1/{accountName}/event \\\r\n\t--header 'Content-Type: application/json' \\\r\n\t--data '{\"session\":\"df66a4d239864d2e8497c89aea14a3ad\",\"anonymous\":\"eed429ecf04a4a23ae7f4429033b48cd\",\"url\":\"https://example.com/search/?query=zapatilha\",\"agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0\",\"type\":\"search.query\",\"text\":\"zapatilha\",\"misspelled\":true,\"match\":392,\"operator\":\"and\"}'\r\n```\r\n\r\n### User identification\r\n\r\nTo identify the user, there are two required identifiers: `session` and `anonymous`. We recommend using a [Universally Unique Identifier (UUID) v4](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID) without dashes.\r\n\r\nSample JavaScript code to generate a random UUID without dashes:\r\n\r\n```js\r\nwindow.crypto.randomUUID().replaceAll('-', '')\r\n```\r\n\r\n>⚠️ The `session` and `anonymous` identifiers need to be sent in every request.\r\n\r\n\r\n### Event type\r\n\r\nTo identify the events that occur in our search, the `type` field is required in the request. The most common event types are the following:\r\n\r\n| Event type | Value | Description |\r\n| - | - | - |\r\n| Session Ping | `session.ping` | Sends an ACK to the API to renew the session server-side. It should be sent every 1 minute. |\r\n| Page Confirmation |`page.confirmation` | Sends a confirmation informing the products that were bought. |\r\n| Search Click | `search.click` | Sends an event every time a shopper clicks on a product from a search page. |\r\n| Search Query | `search.query` | Sends a query event every time the shopper makes a full-text search. |\r\n\r\n### Optional fields\r\n\r\nInformation to identify where the context of that request came from: `agent` and `URL`. Read the API reference for more information on each field.\r\n\r\n### Request body examples per event type\r\n\r\nThe body is built by combining the user information, the event type, and add the optional fields. Below there is an example for each type of event.\r\n\r\n#### Session Ping\r\n\r\n\r\n```json\r\n{\r\n\t\"session\":\"df66a4d239864d2e8497c89aea14a3ad\",\r\n\t\"anonymous\":\"eed429ecf04a4a23ae7f4429033b48cd\",\r\n\t\"url\":\"https://example.com/search/?query=zapatilha\",\r\n\t\"agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0\",\r\n\t\"type\":\"session.ping\"\r\n}\r\n```\r\n\r\n#### Page Confirmation\r\n\r\n```json\r\n{\r\n \"session\":\"df66a4d239864d2e8497c89aea14a3ad\",\r\n \"anonymous\":\"eed429ecf04a4a23ae7f4429033b48cd\",\r\n \"products\": [\r\n {\r\n \"productId\": \"ABC123\",\r\n \"price\": 9.99,\r\n \"quantity\": 3\r\n },\r\n {\r\n \"productId\": \"XYZ789\",\r\n \"price\": 5.99,\r\n \"quantity\": 2\r\n }\r\n ],\r\n \"order\": \"123ABC\",\r\n \"type\": \"page.confirmation\"\r\n}\r\n```\r\n\r\n#### Search Click\r\n\r\n```json\r\n{\r\n\t\"type\": \"search.click\",\r\n\t\"productId\": \"12345\",\r\n\t\"position\": 1,\r\n\t\"url\": \"https://example.com/s?q=pneu&sort=score_desc&page=0\",\r\n\t\"text\": \"pneu\",\r\n\t\"agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36\",\r\n\t\"anonymous\": \"1ce47e50-3f10-4556-95d3-57d4881c03a4\",\r\n\t\"session\": \"51a53ce3-096d-4740-a6d0-3cf86085ba13\"\r\n}\r\n```\r\n\r\n#### Search Query\r\n\r\n```json\r\n{\r\n\t\"session\":\"df66a4d239864d2e8497c89aea14a3ad\",\r\n\t\"anonymous\":\"eed429ecf04a4a23ae7f4429033b48cd\",\r\n\t\"url\":\"https://example.com/search/?query=zapatilha\",\r\n\t\"agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0\",\r\n\t\"type\":\"search.query\",\r\n\t\"text\":\"zapatilha\",\r\n\t\"misspelled\":true,\r\n\t\"match\":392,\r\n\t\"operator\":\"and\"\r\n}\r\n```\r\n\r\n### Finding search query information\r\n\r\nSearch query information is possible to find in the Intelligent Search GraphQL response. To retrieve the information above, add operator, fuzzy, and correction attributes in the GraphQL query. Example:\r\n\r\n```graphql\r\nquery {\r\n productSearch(fullText: \"id:43534\") {\r\n products {\r\n productId\r\n productName\r\n ...\r\n }\r\n operator\r\n fuzzy\r\n correction{ \r\n misspelled\r\n }\r\n }\r\n}\r\n```",
"contact": {},
"version": "1.0"
},
"servers": [
{
"url": "https://sp.vtex.com/event-api/v1/{accountName}",
"description": "Server URL.",
"variables": {
"accountName": {
"default": "apiexamples",
"description": "Name of the VTEX account. Used as part of the URL."
}
}
}
],
"paths": {
"/event": {
"post": {
"summary": "Save events",
"description": "Creates search events to integrate with VTEX Intelligent Search using a headless implementation. \r\n\r\nRead [VTEX Intelligent Search Events API - Headless - Overview](https://developers.vtex.com/docs/api-reference/intelligent-search-events-api-headless) for more information on event types and user identification.\r\n\r\n>⚠️ **This API applies only to Headless scenarios**. It doesn't apply to stores using VTEX's storefront solution, since they are natively integrated with Intelligent Search.\r\n\r\n## Permissions\r\n\r\nThis endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3).",
"parameters": [
{
"name": "accountName",
"in": "path",
"description": "Name of the VTEX account. Used as part of the URL.",
"required": true,
"schema": {
"type": "string",
"example": "apiexamples"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SessionPing"
},
{
"$ref": "#/components/schemas/PageConfirmation"
},
{
"$ref": "#/components/schemas/Click"
},
{
"$ref": "#/components/schemas/Query"
}
]
},
"examples": {
"Session Ping": {
"value": {
"session": "df66a4d239864d2e8497c89aea14a3ad",
"anonymous": "eed429ecf04a4a23ae7f4429033b48cd",
"url": "https://example.com/search/?query=zapatilha",
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0",
"type": "search.query",
"text": "zapatilha",
"misspelled": true,
"match": 392,
"operator": "and"
}
},
"Page Confirmation": {
"value": {
"session": "df66a4d239864d2e8497c89aea14a3ad",
"anonymous": "eed429ecf04a4a23ae7f4429033b48cd",
"products": [
{
"productId": "ABC123",
"price": 9.99,
"quantity": 3
},
{
"productId": "XYZ789",
"price": 5.99,
"quantity": 2
}
],
"order": "123ABC",
"type": "page.confirmation"
}
},
"Search Click": {
"value": {
"type": "search.click",
"productId": "12345",
"position": 1,
"url": "https://example.com/s?q=pneu&sort=score_desc&page=0",
"text": "pneu",
"agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
"anonymous": "1ce47e50-3f10-4556-95d3-57d4881c03a4",
"session": "51a53ce3-096d-4740-a6d0-3cf86085ba13"
}
},
"Search Query": {
"value": {
"session": "df66a4d239864d2e8497c89aea14a3ad",
"anonymous": "eed429ecf04a4a23ae7f4429033b48cd",
"url": "https://example.com/search/?query=zapatilha",
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0",
"type": "search.query",
"text": "zapatilha",
"misspelled": true,
"match": 392,
"operator": "and"
}
}
}
}
}
},
"tags": [
"Events"
],
"responses": {
"204": {
"description": "No content"
}
}
}
}
},
"components": {
"schemas": {
"UserIdentification": {
"required": [
"anonymous",
"session"
],
"properties": {
"anonymous": {
"type": "string",
"title": "anonymous",
"description": "Identifier related to related to the user, in UUID v4 format without dashes. This information is kept in storage for one year.",
"example": "df66a4d239864d2e8497c89aea14a3ad"
},
"session": {
"type": "string",
"title": "session",
"description": "Identifier related to the current navigation, in UUID v4 format without dashes. It is a cookie that lasts for 30 minutes, changing if the user opens another tab in private navigation mode.",
"example": "eed429ecf04a4a23ae7f4429033b48cd"
}
}
},
"SessionPing": {
"title": "SessionPing",
"description": "Sends an ACK to the API to renew the session server-side. It should be sent every 1 minute.",
"type": "object",
"required": [
"session",
"anonymous",
"type",
"agent"
],
"properties": {
"session": {
"$ref": "#/components/schemas/UserIdentification/properties/session"
},
"anonymous": {
"$ref": "#/components/schemas/UserIdentification/properties/anonymous"
},
"type": {
"type": "string",
"title": "type",
"description": "Type of event, which can be one of the following: `page.cart`, `page.empty_cart`, `search.query`, `page.confirmation`, `session.ping`, `search.click`.",
"example": "session.ping"
},
"agent": {
"type": "string",
"title": "agent",
"description": "Identifies whether the request came from a mobile or desktop application. It's used as a filter in the search report.",
"default": "desktop",
"example": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0"
}
}
},
"PageCart": {
"title": "PageCart",
"description": "Sends an event every time the shopper enters the cart page. Each interaction should include all products inside the shopping cart at that time. In case a product is removed, sent the updated card.",
"type": "object",
"required": [
"session",
"anonymous",
"type",
"products"
],
"properties": {
"session": {
"$ref": "#/components/schemas/UserIdentification/properties/session"
},
"anonymous": {
"$ref": "#/components/schemas/UserIdentification/properties/anonymous"
},
"products": {
"type": "array",
"title": "products",
"description": "Array of objects containing products. If the event type is `page.cart`, the array contains all the products in the cart, with their ID and quantity. Each interaction should include all products inside the shopping cart at that time. In case a product is removed, sent the updated card. If there are no products in the cart (page.`empty_cart`), the array is empty. If the event type is `page.confirmation`, the array contains all the products that were purchased, with their ID, price and quantity.",
"items": {
"$ref": "#/components/schemas/CartProduct"
}
},
"type": {
"type": "string",
"title": "type",
"description": "Type of event, which can be one of the following: `page.cart`, `page.empty_cart`, `search.query`, `page.confirmation`, `session.ping`, `search.click`.",
"example": "page.cart"
}
}
},
"PageEmptyCart": {
"title": "Empty Cart",
"description": "Sends an event if there are no products in the shopping cart at that time.",
"type": "object",
"required": [
"session",
"anonymous",
"type",
"products"
],
"properties": {
"session": {
"$ref": "#/components/schemas/UserIdentification/properties/session"
},
"anonymous": {
"$ref": "#/components/schemas/UserIdentification/properties/anonymous"
},
"products": {
"type": "array",
"title": "products",
"description": "Array of objects containing products. If the event type is `page.cart`, the array contains all the products in the cart, with their ID and quantity. Each interaction should include all products inside the shopping cart at that time. In case a product is removed, sent the updated card. If there are no products in the cart (page.`empty_cart`), the array is empty. If the event type is `page.confirmation`, the array contains all the products that were purchased, with their ID, price and quantity.",
"items": {
"$ref": "#/components/schemas/CartProduct"
}
},
"type": {
"type": "string",
"title": "type",
"description": "Type of event, which can be one of the following: `page.cart`, `page.empty_cart`, `search.query`, `page.confirmation`, `session.ping`, `search.click`.",
"example": "page.empty_cart"
}
}
},
"PageConfirmation": {
"title": "Page Confirmation",
"description": "Sends a confirmation informing the products that were bought.",
"type": "object",
"required": [
"session",
"anonymous",
"type",
"order",
"products"
],
"properties": {
"session": {
"$ref": "#/components/schemas/UserIdentification/properties/session"
},
"anonymous": {
"$ref": "#/components/schemas/UserIdentification/properties/anonymous"
},
"products": {
"type": "array",
"title": "products",
"description": "Array of objects containing products. If the event type is `page.cart`, the array contains all the products in the cart, with their ID and quantity. Each interaction should include all products inside the shopping cart at that time. In case a product is removed, sent the updated card. If there are no products in the cart (page.`empty_cart`), the array is empty. If the event type is `page.confirmation`, the array contains all the products that were purchased, with their ID, price and quantity.",
"items": {
"$ref": "#/components/schemas/OrderProduct"
}
},
"order": {
"type": "string",
"title": "order",
"description": "Order ID.",
"example": "123ABC"
},
"type": {
"type": "string",
"title": "type",
"description": "Type of event, which can be one of the following: `page.cart`, `page.empty_cart`, `search.query`, `page.confirmation`, `session.ping`, `search.click`.",
"example": "page.confirmation"
}
}
},
"Click": {
"title": "Search Click",
"description": "Sends an event every time a shopper clicks on a product from a search page.",
"type": "object",
"required": [
"type",
"productId",
"position",
"text",
"anonymous",
"session"
],
"properties": {
"type": {
"type": "string",
"title": "type",
"description": "Type of event, which can be one of the following: `page.cart`, `page.empty_cart`, `search.query`, `page.confirmation`, `session.ping`, `search.click`.",
"example": "search.click"
},
"productId": {
"type": "string",
"description": "Unique identifier of the clicked product.",
"example": "12345"
},
"position": {
"type": "integer",
"description": "Position of the clicked product on the search results page.",
"example": 1
},
"url": {
"type": "string",
"title": "url",
"description": "URL that identifies from which page the event occurred.",
"example": "https://example.com/s?q=pneu&sort=score_desc&page=0"
},
"text": {
"type": "string",
"title": "text",
"description": "Query used in the search.",
"example": "tv"
},
"agent": {
"type": "string",
"title": "agent",
"description": "Identifies whether the request came from a mobile or desktop application. It's used as a filter in the search report.",
"default": "desktop",
"example": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0"
},
"anonymous": {
"$ref": "#/components/schemas/UserIdentification/properties/anonymous"
},
"session": {
"$ref": "#/components/schemas/UserIdentification/properties/session"
}
}
},
"Query": {
"title": "Search Query",
"description": "Sends a query event every time the shopper makes a full-text search.",
"type": "object",
"required": [
"session",
"anonymous",
"type",
"misspelled",
"text",
"match",
"operator"
],
"properties": {
"session": {
"$ref": "#/components/schemas/UserIdentification/properties/session"
},
"anonymous": {
"$ref": "#/components/schemas/UserIdentification/properties/anonymous"
},
"url": {
"type": "string",
"title": "url",
"description": "URL that identifies from which page the event occurred.",
"example": "https://example.com/search/?query=zapatilha"
},
"agent": {
"type": "string",
"title": "agent",
"description": "Identifies whether the request came from a mobile or desktop application. It's used as a filter in the search report.",
"default": "desktop",
"example": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0"
},
"type": {
"type": "string",
"title": "type",
"description": "Type of event, which can be one of the following: `page.cart`, `page.empty_cart`, `search.query`, `page.confirmation`, `session.ping`, `search.click`.",
"example": "search.query"
},
"text": {
"type": "string",
"title": "text",
"description": "Query used in the search.",
"example": "tv"
},
"misspelled": {
"type": "boolean",
"title": "misspelled",
"description": "Indicates whether the query has a typo (`true`) or not (`false`).",
"example": true
},
"match": {
"type": "number",
"title": "match",
"description": "Amount of products retrieved by the search.",
"example": 396
},
"operator": {
"type": "string",
"title": "operator",
"description": "Identifies the type of operator used on the search. The possible values are: `and`, `or`. Find more details in [this Elastic Search guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html).",
"example": "and"
}
}
},
"CartProduct": {
"type": "object",
"description": "Product information.",
"required": [
"productId",
"quantity"
],
"properties": {
"productId": {
"type": "string",
"description": "Unique identifier of the product.",
"example": "ABC123"
},
"quantity": {
"type": "number",
"description": "Quantity of the product.",
"example": 2
}
}
},
"OrderProduct": {
"type": "object",
"description": "Product information.",
"required": [
"productId",
"price",
"quantity"
],
"properties": {
"productId": {
"type": "string",
"description": "Unique identifier of the product.",
"example": "ABC123"
},
"price": {
"type": "number",
"description": "Price of the product.",
"example": 9.99
},
"quantity": {
"type": "number",
"description": "Quantity of the product.",
"example": 3
}
}
}
}
},
"tags": [
{
"name": "Events"
}
]
}