# Передача взаимодействия пользователя с кампаниями

Для сбора статистики и последующей оптимизации кампаний необходимо передавать информацию о взаимодействиях пользователя с кампаниями.

## POST /ssapi/engagement

> Report user engagement (clicks) with a variation or a recommended item.

```json
{"openapi":"3.0.3","info":{"title":"Gravity Field SSAPI","version":"1.0.0"},"servers":[{"url":"https://evs.gravityfield.ai"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API-KEY"}},"schemas":{"user":{"type":"object","description":"User ID. A Gravity Field-generated identifier is used, and managed via cookies. For a new user, send this object empty.","properties":{"id":{"description":"External user identification","type":"string"},"slid":{"description":"The user ID assigned to visitors by Gravity Field. For a new user, send this param empty.","type":"string"},"slid_server":{"description":"The user ID assigned to visitors by Gravity Field. For a new user, send this param empty.","type":"string"}}},"session":{"type":"object","description":"Session ID. A Gravity Field-generated identifier is used. For new sessions, send this object empty.","properties":{"custom":{"description":"External session identification, used only external user id","type":"string"},"sl":{"description":"Pass the value of the _slsession cookie if it exists. Otherwise, a new session identifier will be created by Gravity Field and returned in the response.","type":"string"}}},"context":{"type":"object","description":"The request's context.","properties":{"page":{"description":"Data for the page currently being browsed.","type":"object","properties":{"type":{"description":"Page type. Must be upper case. Valid values are HOMEPAGE, CATEGORY, PRODUCT, CART, SEARCH and OTHER.","type":"string","enum":["HOMEPAGE","PRODUCT","CART","CATEGORY","SEARCH","OTHER"]},"data":{"description":"Additional data for non-homepage pages The SKU for a PRODUCT page, the category for a CATEGORY page, SKUs for the CART page, and query string for SEARCH","type":"array","items":{"type":"string"}},"lng":{"description":"Page locale code, such as ru_RU.","type":"string"},"location":{"description":"The current location. URL (for web), location (for SPA), or screen name (for mobile apps). Enables targeting the current page/screen.","type":"string"},"referrer":{"description":"The previous location. URL (for web), location (for SPA), or screen name (for mobile apps). Enables targeting the previous page/screen.","type":"string"}},"required":["type","data","location"]},"device":{"description":"Data for the served device.","type":"object","properties":{"userAgent":{"description":"For web clients, the browser user-agent string. If not passed, the API gateway checks for the header in the HTTPS request.","type":"string"},"ip":{"description":"The client IP address, for geolocation-based targeting and audience building. If not passed, the caller IP is used.","type":"string"}}}},"required":["page"]}},"responses":{"UnauthorizedError":{"description":"Access token is missing or invalid"},"ValidationError":{"description":"Error validation request data","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"integer"},"message":{"type":"string"},"type":{"type":"string"}}}}}}}},"paths":{"/ssapi/engagement":{"post":{"tags":["SSAPI"],"description":"Report user engagement (clicks) with a variation or a recommended item.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"user":{"$ref":"#/components/schemas/user"},"session":{"$ref":"#/components/schemas/session"},"context":{"$ref":"#/components/schemas/context"},"engagements":{"type":"array","description":"Report the type of engagement with a reference to the content or recommendation that the user engaged with.","items":{"type":"object","description":"A user engagement with a Gravity Field campaign.","properties":{"type":{"description":"Pass the value CLICK or WRIMP for API custom code campaigns. Pass the value SLOT_CLICK for API recommendation campaigns.","type":"string","enum":["CLICK","SLOT_CLICK","WRIMP"]},"decisionId":{"description":"Required for reporting CLICK or WRIMP. The unique Decision ID as returned from the /choose endpoint.","type":"string"},"slotId":{"description":"Use to report a click on an API recommendation. Pass the Slot ID for the clicked product as returned in the /choose response. Do not use for for API custom code campaigns.","type":"string"},"variations":{"description":"Use to report explicit impressions over custom code campaigns that return multiple variations on each decision (for example, a slider). Values are variation IDs.","type":"array","items":{"type":"string"}},"event_time":{"type":"string","description":"Event time, used if the event was in the past. Format ISO (YYYY-MM-DDTHH:ii:ss.ms+00:00)"}},"required":["type"]}}},"required":["user","session","context","engagements"]}}}},"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"slid":{"type":"string","nullable":true,"description":"If a user has been created then the uid is returned. Set cookies in the frontend"}}},"session":{"type":"object","properties":{"sl":{"type":"string","nullable":true,"description":"If a session has been created then the ses is returned. Set cookies in the frontend"}}}}}}}},"204":{"description":"Successful response","content":{"text/plain":{}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"422":{"$ref":"#/components/responses/ValidationError"}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.gravityfield.ai/lang/server-side-api-references/peredacha-vzaimodeistviya-polzovatelya-s-kampaniyami.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
