> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doofinder.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Click stats

> Save click event on doofinder statistics



## OpenAPI

````yaml /openapi/search-v6.yaml put /6/{hashid}/stats/click
openapi: 3.0.0
info:
  title: Search API
  contact:
    name: Doofinder Support
    url: https://docs.doofinder.com/
  version: '6.0'
  description: >
    # Introduction

    Search API allows you to perform the search requests you can do on your
    search

    engines using the doofinder layer, directly from your code.

    # Basics

    ## Endpoint

    All requests should be done with `https` protocol in our api location.

    `https://{search_zone}-search.doofinder.com`

    where `{search_zone}` depends on your location, is the geographic zone your
    search engine is located at.

    i.e.: eu1. Also, indicates which host to use in your API calls.

    ## Authentication

    The authentication method for search API requires an api key that could be
    obtained in our

    [management control panel](https://admin.doofinder.com).

    You can generate it in your user account -> Api Keys.

    Example of the generated API Key:

    `eu1-ab46030xza33960aac71a10248489b6c26172f07`

    ### API Token

    You could authenticate with the previous API key in header as a Token. The
    correct way to authenticate is

    to send a HTTP Header with the name `Authorization` and the value `Token
    <API Key>`

    For example, for the key shown above:

    `Authorization: Token eu1-ab46030xza33960aac71a10248489b6c26172f07`

    ## Client IP

    If you're calling this API directly from your own backend, rather than
    through Doofinder's

    JS layer, forward your end user's real IP address on every request, using
    one of:

    - `X-Real-IP`

    - `X-Forwarded-For`

    Without one of these headers, every request from your integration will
    appear to come from

    your server's single static IP address. Repeated requests from that one
    static IP can be

    flagged as bot traffic, which silently drops the affected search and
    click/session stats

    from your reports. It also skews any geographic breakdown in your stats,
    since it will be

    based on your server's location instead of your end users' locations.

    ## Conventions

    Along most of the code samples you will find placeholders for some common
    variable values. They are:

    - `{hashid}`: The search engine's unique id. i.e.:
    d8fdeab7fce96a19d3fc7b0ca7a1e98b

    - `{token}`: Your personal authentication token obtained in the control
    panel.

    - `{index}`: The index of the data you're searching at. i.e.: product

    - `{id}`: Unique identification of a resource. i.e.: 1234 or HVIUYC
  termsOfService: https://www.doofinder.com/es/terms-and-conditions
  x-logo:
    url: https://admin.doofinder.com/images/logo.svg
    backgroundColor: '#33268C'
    altText: Doofinder Search Engine
servers:
  - url: https://{search_zone}-search.doofinder.com
    variables:
      search_zone:
        enum:
          - eu1
          - us1
          - ap1
        default: eu1
  - url: /
security:
  - api_token: []
tags:
  - name: Search
    description: Search operations.
  - name: Session & Events
    description: Stats operations.
paths:
  /6/{hashid}/stats/click:
    put:
      tags:
        - Session & Events
      summary: Click stats
      description: Save click event on doofinder statistics
      operationId: click_stats
      parameters:
        - $ref: '#/components/parameters/hashid'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClickStatsRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatsResponse'
        '400':
          description: >-
            Bad Request — missing required fields (dfid, session_id), invalid
            dfid format, dfid belongs to a different search engine, or invalid
            position.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                missing_fields:
                  summary: Required fields missing
                  value:
                    error: '[dfid, session_id] fields are missing'
                invalid_dfid:
                  summary: dfid format is invalid
                  value:
                    error: Bad request, dfid is invalid
                dfid_hashid_mismatch:
                  summary: dfid belongs to a different search engine
                  value:
                    error: Item hashid must be the same as search engine hashid
                invalid_session_id:
                  summary: session_id too long
                  value:
                    error: session_id should have 32 characters or less
        '403':
          description: >-
            Forbidden — missing or invalid API token, client IP is blocked, or
            CORS `Origin` not allowed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Missing or invalid API token
                  value:
                    error: forbidden
                banned_ip:
                  summary: Client IP is blocked
                  value:
                    error: banned ip
        '404':
          description: >-
            Not Found — the item referenced by `dfid` does not exist in this
            search engine.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                summary: Item not found
                value:
                  error: Not found
components:
  parameters:
    hashid:
      name: hashid
      in: path
      description: Unique id of a search engine.
      required: true
      schema:
        type: string
  schemas:
    ClickStatsRequest:
      type: object
      properties:
        custom_results_id:
          $ref: '#/components/schemas/custom_results_id'
        dfid: 70da9c06-6aea-46e5-aa98-8a60dfd8f34d
        session_id:
          $ref: '#/components/schemas/session_id'
        user_id:
          $ref: '#/components/schemas/user_id'
        query:
          $ref: '#/components/schemas/query'
        position:
          $ref: '#/components/schemas/position'
        resource_id:
          $ref: '#/components/schemas/resource_id'
      required:
        - session_id
        - dfid
    StatsResponse:
      title: Stats Response
      description: Response returned over register stat operation.
      type: object
      properties:
        status:
          description: Result of the stats request. i.e. 'registered'
          type: string
      example:
        status: registered
    ErrorResponse:
      type: object
      description: Standard error response returned on all non-200 outcomes.
      properties:
        error:
          type: string
          description: Human-readable error message.
      required:
        - error
    custom_results_id:
      description: Identifier of the custom result the search results belongs to.
      type: string
    session_id:
      type: string
      description: Identifier of search session
      maxLength: 32
    user_id:
      type: string
      description: Identifier of user
      maxLength: 36
    query:
      type: string
      description: The search query that led to this
    position:
      description: >-
        The position the clicked item have in the search results. The first
        position should be 1.
      type: integer
    resource_id:
      type: string
      description: Identifier of the resource that generated the click
  securitySchemes:
    api_token:
      type: apiKey
      name: Authorization
      in: header
      description: >
        Doofinder API key. The `Token` prefix is part of the header value, so
        enter it too — the field is sent verbatim as:

            Authorization: Token <api_key>
      x-default: Token <your_api_key>

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.