---
title: Track event for the given user.
slug: feature-experimentation/api/track-event-for-the-given-user
docTags: 
createdAt: 2026-08-28T15:54:06.731Z
---

{
  "id": "xiRwhx2KV-6sOAQCaBcwd",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "/v1/track",
    "servers": [],
    "name": "Track event for the given user.",
    "description": "<p>Send event and user details to Optimizely analytics backend, so you can see metrics for an experiment. You can view metrics either on your Results page or as a data export.</p>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [
        {
          "kind": "required",
          "name": "eventKey",
          "type": "string",
          "description": "Key of the event we're tracking"
        }
      ],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "",
          "customType": "TrackContext",
          "schema": [
            {
              "name": "eventTags",
              "kind": "optional",
              "type": "object",
              "description": "",
              "example": "",
              "schema": []
            },
            {
              "name": "userId",
              "kind": "optional",
              "type": "string",
              "description": ""
            },
            {
              "name": "userAttributes",
              "kind": "optional",
              "type": "object",
              "description": "",
              "example": "",
              "schema": []
            }
          ],
          "modelRef": "#/components/schemas/TrackContext",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "SdkKeyAuth",
          "name": "X-Optimizely-SDK-Key",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        },
        {
          "id": "TokenAuth",
          "name": "TokenAuth",
          "kind": "optional",
          "type": "http",
          "scheme": "bearer"
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "<p>Valid response, event received</p>",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "400",
        "description": "Missing required parameters",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "<p>Unauthorized, invalid JWT</p>",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "403",
        "description": "You do not have necessary permissions for the resource",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "You do not have necessary permissions for the resource",
            "customType": "Forbidden",
            "schema": [],
            "modelRef": "#/components/responses/Forbidden",
            "isExpanded": true
          }
        ]
      }
    ],
    "hasXCodeSamples": false,
    "deprecated": false,
    "examples": {
      "languages": [
        {
          "id": "n5L_9O8usMUyr916FOBGh",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url '/v1/track?eventKey=string' \\\n     --header 'accept: application/json'"
        },
        {
          "id": "NLhJCEewpiIst7pi_HqME",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"/v1/track?eventKey=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "_HNJuiF-KBf2-leFLsU2v",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"/v1/track?eventKey=string\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "QmBoK0pVsbsg6oTRs_XOx",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"/v1/track?eventKey=string\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "n5L_9O8usMUyr916FOBGh"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Valid response, event received\n"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Missing required parameters\n"
        },
        {
          "id": "response-2-401",
          "language": "401",
          "code": "// Unauthorized, invalid JWT\n"
        },
        {
          "id": "response-3-403",
          "language": "403",
          "code": "// You do not have necessary permissions for the resource\n{}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}