forked from vtex/openapi-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VTEX - Intelligent Search Events API - Headless.json
448 lines (448 loc) · 25.4 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
{
"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 detail the required structure for the request body to save events using this API.\r\n\r\n### User identification\r\n\r\nTo identify the user, there are two required identifiers according to the [nanoid](https://github.com/ai/nanoid) pattern: `session` and `anonymous`. Read the API reference for more information on each field.\r\n\r\n> ⚠️ The `session` and `anonymous` identifiers need to be sent in every request.\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 Cart | `page.cart` | 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. |\r\n| Empty Cart | `page.empty_cart` | Sends an event if there are no products in the shopping cart at that time. | \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` | Should send a query event every time the shopper makes a full-text search. |\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```\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\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```json\r\n{\r\n\t\"session\":\"zZlNhqz1vFJP6iPG5Oqdf\",\r\n\t\"anonymous\":\"Om1TNluGvgmSgU5OOTvdfg\",\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 Cart \r\n\r\n```json\r\n{\r\n \"session\":\"zZlNhqz1vFJP6iPG5Oqtt\",\r\n \"anonymous\":\"Om1TNluGvgmSgU5OOTvkkd\",\r\n \"products\": [\r\n {\r\n \"productId\": \"ABC123\",\r\n \"quantity\": 2\r\n },\r\n {\r\n \"productId\": \"XYZ789\",\r\n \"quantity\": 1\r\n }\r\n ],\r\n \"type\": \"page.cart\"\r\n}\r\n```\r\n\r\n#### Empty Cart \r\n\r\n```json\r\n{\r\n \"session\":\"zZlNhqz1vFJP6iPG5Oqtt\",\r\n \"anonymous\":\"Om1TNluGvgmSgU5OOTvkkd\",\r\n \"products\": [],\r\n \"type\": \"page.empty_cart\"\r\n}\r\n```\r\n\r\n#### Page Confirmation\r\n\r\n```json\r\n{\r\n \"session\":\"zZlNhqz1vFJP6iPG5Oqtt\",\r\n \"anonymous\":\"Om1TNluGvgmSgU5OOTvkkd\",\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#### Query Type\r\n\r\n```json\r\n{\r\n\t\"session\":\"zZlNhqz1vFJP6iPG5Oqtt\",\r\n\t\"anonymous\":\"Om1TNluGvgmSgU5OOTvkkd\",\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",
"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\n >⚠️ **This API applies only to Headless scenarios**. It doesn't apply to stores using VTEX's storefront solution, natively integrated with Intelligent Search.",
"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": {
"example": {
"session": "zZlNhqz1vFJP6iPG5Oqtt",
"anonymous": "Om1TNluGvgmSgU5OOTvkkd",
"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"
},
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SessionPing"
},
{
"$ref": "#/components/schemas/PageCart"
},
{
"$ref": "#/components/schemas/PageEmptyCart"
},
{
"$ref": "#/components/schemas/PageConfirmation"
},
{
"$ref": "#/components/schemas/Click"
},
{
"$ref": "#/components/schemas/Query"
}
],
"allOf": [
{
"$ref": "#/components/schemas/UserIdentification"
}
]
}
}
}
},
"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, according to the [nanoid](https://github.com/ai/nanoid) pattern. This information is kept in storage for one year.",
"example": "Om1TNluGvgmSgU5OOTvkkd"
},
"session": {
"type": "string",
"title": "session",
"description": "Identifier related to the current navigation, according to the [nanoid](https://github.com/ai/nanoid) pattern. It is a cookie that lasts for 30 minutes, changing if the user opens another tab in private navigation mode.",
"example": "zZlNhqz1vFJP6iPG5Oqtt"
}
}
},
"SessionPing": {
"type": "object",
"required": [
"type",
"agent"
],
"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": "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"
}
},
"example": {
"type": "session.ping",
"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": "ee15a2ad-d2f1-4a29-995e-e514b468385e"
}
},
"PageCart": {
"type": "object",
"required": [
"type",
"products"
],
"properties": {
"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.",
"example": [
{
"productId": "ABC123",
"quantity": 2
}
],
"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"
}
},
"example": {
"session": "zZlNhqz1vFJP6iPG5Oqtt",
"anonymous": "Om1TNluGvgmSgU5OOTvkkd",
"products": [
{
"productId": "ABC123",
"quantity": 2
},
{
"productId": "XYZ789",
"quantity": 1
}
],
"type": "page.cart"
}
},
"PageEmptyCart": {
"type": "object",
"required": [
"type",
"products"
],
"properties": {
"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.",
"example": [],
"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"
}
},
"example": {
"session": "zZlNhqz1vFJP6iPG5Oqtt",
"anonymous": "Om1TNluGvgmSgU5OOTvkkd",
"products": [],
"type": "page.empty_cart"
}
},
"PageConfirmation": {
"type": "object",
"required": [
"type",
"order",
"products"
],
"properties": {
"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.",
"example": [
{
"productId": "ABC123",
"price": 9.99,
"quantity": 3
}
],
"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"
}
},
"example": {
"session": "zZlNhqz1vFJP6iPG5Oqtt",
"anonymous": "Om1TNluGvgmSgU5OOTvkkd",
"products": [
{
"productId": "ABC123",
"price": 9.99,
"quantity": 3
},
{
"productId": "XYZ789",
"price": 5.99,
"quantity": 2
}
],
"order": "123ABC",
"type": "page.confirmation"
}
},
"Click": {
"type": "object",
"required": [
"type",
"productId",
"position",
"text"
],
"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": "The unique identifier of the clicked product."
},
"position": {
"type": "integer",
"description": "Position of the clicked product on the search results page."
},
"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": "The 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"
}
},
"example": {
"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"
}
},
"Query": {
"type": "object",
"required": [
"type",
"misspelled",
"text",
"match",
"operator"
],
"properties": {
"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": "The 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"
}
},
"example": {
"session": "zZlNhqz1vFJP6iPG5Oqtt",
"anonymous": "Om1TNluGvgmSgU5OOTvkkd",
"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"
}
},
"CartProduct": {
"type": "object",
"required": [
"productId",
"quantity"
],
"properties": {
"productId": {
"type": "string",
"description": "The unique identifier of the product."
},
"quantity": {
"type": "number",
"description": "The quantity of the product."
}
},
"example": {
"productId": "ABC123",
"quantity": 2
}
},
"OrderProduct": {
"type": "object",
"required": [
"productId",
"price",
"quantity"
],
"properties": {
"productId": {
"type": "string",
"description": "The unique identifier of the product."
},
"price": {
"type": "number",
"description": "The price of the product."
},
"quantity": {
"type": "number",
"description": "The quantity of the product.",
"default": 1
}
},
"example": {
"productId": "ABC123",
"price": 9.99,
"quantity": 3
}
}
}
},
"tags": [
{
"name": "Events"
}
]
}