Vai al contenuto principale
POST
/
api
/
v1
/
Analytics
Query di Custom Analytics
curl --request POST \
  --url https://server.codeium.com/api/v1/Analytics \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "service_key": "<string>",
  "group_name": "<string>",
  "query_requests": [
    {
      "data_source": "<string>",
      "selections": [
        {
          "field": "<string>",
          "name": "<string>",
          "aggregation_function": "<string>"
        }
      ],
      "filters": [
        {
          "name": "<string>",
          "filter": "<string>",
          "value": "<string>"
        }
      ],
      "aggregations": [
        {
          "field": "<string>",
          "name": "<string>"
        }
      ]
    }
  ]
}
'
import requests

url = "https://server.codeium.com/api/v1/Analytics"

payload = {
    "service_key": "<string>",
    "group_name": "<string>",
    "query_requests": [
        {
            "data_source": "<string>",
            "selections": [
                {
                    "field": "<string>",
                    "name": "<string>",
                    "aggregation_function": "<string>"
                }
            ],
            "filters": [
                {
                    "name": "<string>",
                    "filter": "<string>",
                    "value": "<string>"
                }
            ],
            "aggregations": [
                {
                    "field": "<string>",
                    "name": "<string>"
                }
            ]
        }
    ]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    service_key: '<string>',
    group_name: '<string>',
    query_requests: [
      {
        data_source: '<string>',
        selections: [{field: '<string>', name: '<string>', aggregation_function: '<string>'}],
        filters: [{name: '<string>', filter: '<string>', value: '<string>'}],
        aggregations: [{field: '<string>', name: '<string>'}]
      }
    ]
  })
};

fetch('https://server.codeium.com/api/v1/Analytics', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://server.codeium.com/api/v1/Analytics",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'service_key' => '<string>',
    'group_name' => '<string>',
    'query_requests' => [
        [
                'data_source' => '<string>',
                'selections' => [
                                [
                                                                'field' => '<string>',
                                                                'name' => '<string>',
                                                                'aggregation_function' => '<string>'
                                ]
                ],
                'filters' => [
                                [
                                                                'name' => '<string>',
                                                                'filter' => '<string>',
                                                                'value' => '<string>'
                                ]
                ],
                'aggregations' => [
                                [
                                                                'field' => '<string>',
                                                                'name' => '<string>'
                                ]
                ]
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://server.codeium.com/api/v1/Analytics"

	payload := strings.NewReader("{\n  \"service_key\": \"<string>\",\n  \"group_name\": \"<string>\",\n  \"query_requests\": [\n    {\n      \"data_source\": \"<string>\",\n      \"selections\": [\n        {\n          \"field\": \"<string>\",\n          \"name\": \"<string>\",\n          \"aggregation_function\": \"<string>\"\n        }\n      ],\n      \"filters\": [\n        {\n          \"name\": \"<string>\",\n          \"filter\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ],\n      \"aggregations\": [\n        {\n          \"field\": \"<string>\",\n          \"name\": \"<string>\"\n        }\n      ]\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://server.codeium.com/api/v1/Analytics")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"service_key\": \"<string>\",\n  \"group_name\": \"<string>\",\n  \"query_requests\": [\n    {\n      \"data_source\": \"<string>\",\n      \"selections\": [\n        {\n          \"field\": \"<string>\",\n          \"name\": \"<string>\",\n          \"aggregation_function\": \"<string>\"\n        }\n      ],\n      \"filters\": [\n        {\n          \"name\": \"<string>\",\n          \"filter\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ],\n      \"aggregations\": [\n        {\n          \"field\": \"<string>\",\n          \"name\": \"<string>\"\n        }\n      ]\n    }\n  ]\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://server.codeium.com/api/v1/Analytics")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"service_key\": \"<string>\",\n  \"group_name\": \"<string>\",\n  \"query_requests\": [\n    {\n      \"data_source\": \"<string>\",\n      \"selections\": [\n        {\n          \"field\": \"<string>\",\n          \"name\": \"<string>\",\n          \"aggregation_function\": \"<string>\"\n        }\n      ],\n      \"filters\": [\n        {\n          \"name\": \"<string>\",\n          \"filter\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ],\n      \"aggregations\": [\n        {\n          \"field\": \"<string>\",\n          \"name\": \"<string>\"\n        }\n      ]\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
{
  "queryResults": [
    {
      "responseItems": [
        {
          "item": {}
        }
      ]
    }
  ]
}

Panoramica

L’API Custom Analytics offre funzionalità di interrogazione flessibili per i dati di completamento automatico, chat e comandi, con selezioni, filtri, aggregazioni e ordinamenti personalizzabili.

Richiesta

service_key
string
obbligatorio
La tua chiave di servizio con l’autorizzazione “Analytics Read”
group_name
string
Filtra i risultati agli utenti di un gruppo specifico (facoltativo)
query_requests
array
obbligatorio
Array di oggetti di richiesta di query che definiscono i dati da recuperare

Struttura della richiesta di query

Ogni oggetto di richiesta di query contiene:
  • data_source (obbligatorio): Origine dati da interrogare
  • selections (obbligatorio): Array di campi da recuperare
  • filters (facoltativo): Array di filtri da applicare
  • aggregations (facoltativo): Array di aggregazioni in base a cui raggruppare

Selezioni

Le selezioni definiscono quali campi recuperare e come aggregarli.
  • field (obbligatorio): Nome del campo da includere
  • name (facoltativo): Alias del campo
  • aggregation_function (facoltativo): Funzione di aggregazione da applicare

Esempio di selezione

{
  "field": "num_acceptances",
  "name": "total_acceptances",
  "aggregation_function": "QUERY_AGGREGATION_SUM"
}

Filtri

I filtri consentono di limitare i dati agli elementi che soddisfano criteri specifici.
  • name (obbligatorio): Nome del campo su cui filtrare
  • filter (obbligatorio): Operazione di filtro
  • value (obbligatorio): Valore con cui confrontare

Esempio di filtro

{
  "name": "language",
  "filter": "QUERY_FILTER_EQUAL",
  "value": "PYTHON"
}

Aggregazioni

Le aggregazioni raggruppano i dati in base ai criteri specificati.
  • field (obbligatorio): Nome del campo in base al quale raggruppare
  • name (obbligatorio): Alias del campo di aggregazione

Esempio di aggregazione

{
  "field": "ide",
  "name": "ide_type"
}

Campi disponibili

Dati utente

Tutti i dati utente sono aggregati per utente e per ora.
Nome campoDescrizioneAggregazioni valide
api_keyHash dell’API key dell’utenteUNSPECIFIED, COUNT
dateData UTC di AutocompleteUNSPECIFIED, COUNT
date UTC-xData con offset del fuso orario (ad es. “date UTC-8” per PST)UNSPECIFIED, COUNT
hourOra UTC di AutocompleteUNSPECIFIED, COUNT
languageLinguaggio di programmazioneUNSPECIFIED, COUNT
ideIDE in usoUNSPECIFIED, COUNT
versionVersione dell’estensione/plugin (language-server), ad es. 1.48.xUNSPECIFIED, COUNT
num_acceptancesNumero di Autocomplete accettatiSUM, MAX, MIN, AVG
num_lines_acceptedRighe di codice accettateSUM, MAX, MIN, AVG
num_bytes_acceptedByte accettatiSUM, MAX, MIN, AVG
distinct_usersUtenti distintiUNSPECIFIED, COUNT
distinct_developer_daysTuple distinte (utente, giorno)UNSPECIFIED, COUNT
distinct_developer_hoursTuple distinte (utente, ora)UNSPECIFIED, COUNT

Dati della chat

I dati della chat sono separati dai dati di Cascade e rappresentano l’utilizzo dei nostri plugin legacy non agentici
Tutti i dati della chat rappresentano le risposte del modello di chat, non le domande degli utenti.
Nome del campoDescrizioneAggregazioni valide
api_keyHash dell’API key dell’utenteUNSPECIFIED, COUNT
model_idID del modello di chatUNSPECIFIED, COUNT
dateData UTC della risposta in chatUNSPECIFIED, COUNT
date UTC-xData con offset del fuso orarioUNSPECIFIED, COUNT
ideIDE in usoUNSPECIFIED, COUNT
versionVersione dell’estensione/plugin (language-server), ad es. 1.48.xUNSPECIFIED, COUNT
latest_intent_typeTipo di intento della chat (vedi Tipi di intento sotto)UNSPECIFIED, COUNT
num_chats_receivedNumero di messaggi di chat ricevutiSUM, MAX, MIN, AVG
chat_acceptedIndica se la chat è stata accettata (pollice in su)SUM, COUNT
chat_inserted_at_cursorIndica se è stato fatto clic sul pulsante “Insert”SUM, COUNT
chat_appliedIndica se è stato fatto clic sul pulsante “Apply Diff”SUM, COUNT
chat_loc_usedRighe di codice utilizzate dalla chatSUM, MAX, MIN, AVG

Tipi di intent della chat

  • CHAT_INTENT_GENERIC - Chat standard
  • CHAT_INTENT_FUNCTION_EXPLAIN - Code lens per la spiegazione della funzione
  • CHAT_INTENT_FUNCTION_DOCSTRING - Code lens per la docstring della funzione
  • CHAT_INTENT_FUNCTION_REFACTOR - Code lens per il refactor della funzione
  • CHAT_INTENT_CODE_BLOCK_EXPLAIN - Code lens per la spiegazione del blocco di codice
  • CHAT_INTENT_CODE_BLOCK_REFACTOR - Code lens per il refactor del blocco di codice
  • CHAT_INTENT_PROBLEM_EXPLAIN - Code lens per la spiegazione del problema
  • CHAT_INTENT_FUNCTION_UNIT_TESTS - Code lens per i test unitari della funzione

Dati del comando

I dati del comando includono tutti i comandi, compresi quelli rifiutati. Usa il campo accepted per filtrare solo i comandi accettati.
Nome campoDescrizioneAggregazioni valide
api_keyHash della chiave API dell’utenteUNSPECIFIED, COUNT
dateData UTC del comandoUNSPECIFIED, COUNT
timestampTimestamp UTC del comandoUNSPECIFIED, COUNT
languageLinguaggio di programmazioneUNSPECIFIED, COUNT
ideIDE in usoUNSPECIFIED, COUNT
versionVersione dell’estensione/plugin (language-server), ad es. 1.48.xUNSPECIFIED, COUNT
command_sourceOrigine dell’attivazione del comando (vedi fonte dei comandi sotto)UNSPECIFIED, COUNT
provider_sourceModalità di generazione o modificaUNSPECIFIED, COUNT
lines_addedRighe di codice aggiunteSUM, MAX, MIN, AVG
lines_removedRighe di codice rimosseSUM, MAX, MIN, AVG
bytes_addedByte aggiuntiSUM, MAX, MIN, AVG
bytes_removedByte rimossiSUM, MAX, MIN, AVG
selection_linesRighe selezionate (zero per le generazioni)SUM, MAX, MIN, AVG
selection_bytesByte selezionati (zero per le generazioni)SUM, MAX, MIN, AVG
acceptedIndica se il comando è stato accettatoSUM, COUNT

Fonti dei comandi

  • COMMAND_REQUEST_SOURCE_LINE_HINT_CODE_LENS
  • COMMAND_REQUEST_SOURCE_DEFAULT - Uso tipico del comando
  • COMMAND_REQUEST_SOURCE_RIGHT_CLICK_REFACTOR
  • COMMAND_REQUEST_SOURCE_FUNCTION_CODE_LENS
  • COMMAND_REQUEST_SOURCE_FOLLOWUP
  • COMMAND_REQUEST_SOURCE_CLASS_CODE_LENS
  • COMMAND_REQUEST_SOURCE_PLAN
  • COMMAND_REQUEST_SOURCE_SELECTION_HINT_CODE_LENS

Sorgenti del provider

  • PROVIDER_SOURCE_COMMAND_GENERATE - Modalità di generazione
  • PROVIDER_SOURCE_COMMAND_EDIT - Modalità di modifica

Dati PCW

Dati relativi alla Percentuale di Codice Scritto, con monitoraggio separato dei contributi di completamento automatico e dei comandi.
Nome campoDescrizioneAggregazioni valide
percent_code_writtenCalcolato come codeium_bytes / (codeium_bytes + user_bytes)UNSPECIFIED
codeium_bytesByte totali generati da CodeiumUNSPECIFIED
user_bytesByte totali scritti dall’utenteUNSPECIFIED
total_bytescodeium_bytes + user_bytesUNSPECIFIED
codeium_bytes_by_autocompleteByte di Codeium generati dal completamento automaticoUNSPECIFIED
codeium_bytes_by_commandByte di Codeium generati dai comandiUNSPECIFIED

Filtri PCW

Nome del campoDescrizioneEsempi
languageLinguaggio di programmazioneKOTLIN, GO, JAVA
ideIDE utilizzatojetbrains, vscode
versionVersione dell’estensione/del plugin (language-server), ad es. 1.48.x1.28.0, 130.0
Per filtrare per data nelle query PCW, usa start_timestamp e end_timestamp nel corpo principale della richiesta.

Esempi di richieste

Esempio di dati utente

curl -X POST --header "Content-Type: application/json" \
--data '{
  "service_key": "your_service_key_here",
  "query_requests": [
    {
      "data_source": "QUERY_DATA_SOURCE_USER_DATA",
      "selections": [
        {
          "field": "num_acceptances",
          "name": "total_acceptances",
          "aggregation_function": "QUERY_AGGREGATION_SUM"
        },
        {
          "field": "num_lines_accepted",
          "name": "total_lines",
          "aggregation_function": "QUERY_AGGREGATION_SUM"
        }
      ],
      "filters": [
        {
          "name": "date",
          "filter": "QUERY_FILTER_GE",
          "value": "2024-01-01"
        },
        {
          "name": "date",
          "filter": "QUERY_FILTER_LE",
          "value": "2024-02-01"
        }
      ]
    }
  ]
}' \
https://server.codeium.com/api/v1/Analytics

Esempio di dati della chat

curl -X POST --header "Content-Type: application/json" \
--data '{
  "service_key": "your_service_key_here",
  "query_requests": [
    {
      "data_source": "QUERY_DATA_SOURCE_CHAT_DATA",
      "selections": [
        {
          "field": "chat_loc_used",
          "name": "lines_used",
          "aggregation_function": "QUERY_AGGREGATION_SUM"
        }
      ],
      "filters": [
        {
          "name": "latest_intent_type",
          "filter": "QUERY_FILTER_EQUAL",
          "value": "CHAT_INTENT_FUNCTION_DOCSTRING"
        }
      ],
      "aggregations": [
        {
          "field": "ide",
          "name": "ide_type"
        }
      ]
    }
  ]
}' \
https://server.codeium.com/api/v1/Analytics

Esempio di dati del comando

curl -X POST --header "Content-Type: application/json" \
--data '{
  "service_key": "your_service_key_here",
  "query_requests": [
    {
      "data_source": "QUERY_DATA_SOURCE_COMMAND_DATA",
      "selections": [
        {
          "field": "lines_added",
          "name": "total_lines_added",
          "aggregation_function": "QUERY_AGGREGATION_SUM"
        },
        {
          "field": "lines_removed",
          "name": "total_lines_removed",
          "aggregation_function": "QUERY_AGGREGATION_SUM"
        }
      ],
      "filters": [
        {
          "name": "provider_source",
          "filter": "QUERY_FILTER_EQUAL",
          "value": "PROVIDER_SOURCE_COMMAND_EDIT"
        },
        {
          "name": "accepted",
          "filter": "QUERY_FILTER_EQUAL",
          "value": "true"
        }
      ],
      "aggregations": [
        {
          "field": "language",
          "name": "programming_language"
        }
      ]
    }
  ]
}' \
https://server.codeium.com/api/v1/Analytics

Esempio di dati PCW

curl -X POST --header "Content-Type: application/json" \
--data '{
  "service_key": "your_service_key_here",
  "start_timestamp": "2024-01-01T00:00:00Z",
  "end_timestamp": "2024-12-22T00:00:00Z",
  "query_requests": [
    {
      "data_source": "QUERY_DATA_SOURCE_PCW_DATA",
      "selections": [
        {
          "field": "percent_code_written",
          "name": "pcw"
        },
        {
          "field": "codeium_bytes",
          "name": "ai_bytes"
        },
        {
          "field": "total_bytes",
          "name": "total"
        },
        {
          "field": "codeium_bytes_by_autocomplete",
          "name": "autocomplete_bytes"
        },
        {
          "field": "codeium_bytes_by_command",
          "name": "command_bytes"
        }
      ],
      "filters": [
        {
          "filter": "QUERY_FILTER_EQUAL",
          "name": "language",
          "value": "GO"
        }
      ]
    }
  ]
}' \
https://server.codeium.com/api/v1/Analytics

Risposta

queryResults
array
Array dei risultati delle query, uno per ogni richiesta di query
responseItems
array
Array di elementi di risultato
item
object
Oggetto contenente i campi selezionati e i relativi valori

Esempi di risposta

Risposta con i dati dell’utente

{
  "queryResults": [
    {
      "responseItems": [
        {
          "item": {
            "total_acceptances": "125",
            "total_lines": "863"
          }
        }
      ]
    }
  ]
}

Risposta con i dati della chat

{
  "queryResults": [
    {
      "responseItems": [
        {
          "item": {
            "lines_used": "74",
            "ide_type": "jetbrains"
          }
        },
        {
          "item": {
            "lines_used": "41",
            "ide_type": "vscode"
          }
        }
      ]
    }
  ]
}

Risposta con i dati del comando

{
  "queryResults": [
    {
      "responseItems": [
        {
          "item": {
            "programming_language": "PYTHON",
            "total_lines_added": "21",
            "total_lines_removed": "5"
          }
        },
        {
          "item": {
            "programming_language": "GO",
            "total_lines_added": "31",
            "total_lines_removed": "27"
          }
        }
      ]
    }
  ]
}

Risposta dati PCW

{
  "queryResults": [
    {
      "responseItems": [
        {
          "item": {
            "ai_bytes": "6018",
            "autocomplete_bytes": "4593",
            "command_bytes": "1425",
            "pcw": "0.61",
            "total": "9900"
          }
        }
      ]
    }
  ]
}

Note importanti

  • Il PCW (Percentuale di Codice Scritto) presenta un’elevata variabilità su singole giornate o singoli utenti: aggrega i dati su base settimanale per ottenere migliori approfondimenti
  • Tutti i campi di selezione devono avere funzioni di aggregazione, oppure nessuno deve averle (non è possibile mescolarli)
  • I campi con pattern “distinct_*” non possono essere usati nelle aggregazioni
  • Gli alias dei campi devono essere univoci in tutte le selezioni e aggregazioni
  • Se non viene specificata alcuna funzione di aggregazione, il valore predefinito è UNSPECIFIED