How to get realtime analytics for assistants?
# support
c
I want to render realtime analytics for my assistants like "how many calls" it has taken. How do i do that? Does Vapi provides any out the box solution or do i have to build it on own.
@User @Vapi
v
@ChasingClouds I'm here to help you with your query about real-time analytics for your voice assistants. VAPI does offer various tools and APIs that can help you track metrics such as the number of calls your assistant has taken. However, the specifics of how to implement real-time analytics can depend on the details of your setup and what VAPI features you are currently using. If VAPI has built-in analytics features, you would typically access them through your VAPI dashboard or API to retrieve the data you need. If such a feature is not available out of the box, you may need to integrate with a third-party analytics service or build a custom solution to track these metrics. To provide you with the most accurate information, could you please let me know if you are currently using any specific VAPI features for analytics or if you have any existing setup for tracking metrics? This will help me guide you better on how to proceed.
c
@Vapi I am building assistants using the server sdk. I wanna know in realtime how many calls the particular assistant has taken and show in realtime. I don't have an existing solution implemented yet.
v
@ChasingClouds Great, since you're building assistants using the server SDK, you can implement real-time analytics by capturing call events. Here's a high-level approach to achieve this: 1. **Capture Call Events**: Utilize the server SDK to listen for call events. Each time a call is initiated or completed, the SDK should trigger an event. 2. **Log Events**: Implement logging within your server environment to record these events. You can log the call event details, such as call start time, end time, duration, and the assistant that took the call. 3. **Real-Time Analytics Engine**: Develop or integrate a real-time analytics engine that processes these logs and updates the call count in real-time. This could be a custom-built solution or a third-party service like Google Analytics, Mixpanel, or a real-time database like Firebase. 4. **Dashboard**: Create a dashboard that connects to your analytics engine and displays the call count in real-time. This dashboard can be a web application that polls or listens for updates from your analytics engine and updates the display accordingly. 5. **WebSockets or Server-Sent Events (SSE)**: To push updates to the dashboard in real-time, you can use WebSockets or Server-Sent Events. This allows your server to send updates to the dashboard without the need for the client to request it. Since you don't have an existing solution, you would need to build these components. If you need guidance on any specific part of this setup or if you have any other questions, feel free to ask.
d
@Shubham Bajaj anything else we should know?
m
@ChasingClouds did you read any of the messages on your last ticket bruvva
where chowder explained how to use the analytics endpoint
c
Yaa
That thing doesn’t work
m
we both tested it and it worked for us
wdym by it didnt work
c
Thats what i am saying lol. I understand being upset because its not there, but it def works. Even if this did not work. You could still do this by simply tracking your calls in any database and filtering them. @User https://cdn.discordapp.com/attachments/1331285157088333955/1331316741422321684/Screenshot_2025-01-21_091413.png?ex=67912cd5&is=678fdb55&hm=1dea93e74bedc03681267225bad9d2db16ea8ce04677340e4de12e1c94beb033&
c
I know how to implement it or use a KV for it
What i am looking if they are providing any analytics solution
And for your information
The query gives for all assistants🤷🏻‍♂️
Now you will be like why not filter them for each assistant. That’s not an ideal solution. Think when you have 100s of assistants taking 100s of calls
That query is just not cut out for it
What i needed to know if Vapi has any analytics endpoint which can query specifically for each assistantId
I mean a UNIQUE ASSISTANT
I don’t want all the results in response.
If they don’t have, I will implement my own analytics
But this is my last resort. No need to overcomplicate
I mean its not what i am looking for
c
Once again there are multiple queries. You said you could not only filter by Assistant, so I went to go check it and you can, so i am not sure what you mean once again. Of course i did not put multipleiD's i just put one. Also not working and not what you are looking for are two completely different things altogether. Your saying "real-time" but analytics can't be pulled until after a call..... We are not tryna over-complicate but make sure we are on the same page.
m
you can literally query by assistantId
c
Please show
m
jesus dude lol did you read any of what we said on the first ticket
it uses the same params as any get
so query by ?assistantId=
c
I tagged you in general.
c
have you tried it?? Like before yapping?? This is my query:
Copy code
const analyticsQuery = {
    queries: [
        {
            table: "call",
            groupBy: ["assistantId", "type", "status"],
            name: "Call Analytics",
            timeRange: {
                step: "day",
                start: "2024-01-01T00:00:00Z",
                end: "2025-01-20T23:59:59Z",
                timezone: "UTC"
            },
            operations: [
                {
                    operation: "count",
                    column: "id",
                    alias: "call_count"
                }]
        }
    ]
};

// Make the fetch request
fetch('https://api.vapi.ai/analytics?assistantId=3a9e0733-6004-4995-b54d-f38af0701bfc', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        // You'll need to add your authentication header here
        'Authorization': 'Bearer <my-token>'
    },
    body: JSON.stringify(
        analyticsQuery
    )
})
    .then(response => response.json())
    .then(data => {
        console.log('Success:', data);
        console.log(JSON.stringify(data, 2, null));
    })
    .catch((error) => {
        console.error('Error:', error);
    });
This is my result:
Copy code
[{"name":"Call Analytics","timeRange":{"start":"2024-01-01T00:00:00.000Z","end":"2025-01-20T23:59:59.000Z","step":"day","timezone":"UTC"},"result":[{"date":"2024-10-20T00:00:00.000Z"
,"assistantId":"3a9e0733-6004-4995-b54d-f38af0701bfc","type":"inboundPhoneCall","status":"ended","callCount":"4"},{"date":"2024-10-20T00:00:00.000Z","assistantId":"d753855a-10e9-4334
-a2df-675fdcdda02a","type":"inboundPhoneCall","status":"ended","callCount":"15"},{"date":"2024-11-23T00:00:00.000Z","assistantId":"3a9e0733-6004-4995-b54d-f38af0701bfc","type":"inbou
ndPhoneCall","status":"ended","callCount":"1"},{"date":"2025-01-11T00:00:00.000Z","assistantId":"3a9e0733-6004-4995-b54d-f38af0701bfc","type":"outboundPhoneCall","status":"ended","ca
llCount":"1"},{"date":"2025-01-11T00:00:00.000Z","assistantId":"00000000-0000-0000-0000-000000000000","type":"webCall","status":"ended","callCount":"2"}]}]
Why are there different assistantIds involved as well??? Because it does not matter even if you query by ?assistantId or just query on the base analytics url.
The result is gonna be the same. It ignores the assistantId. That's what I am trying to tell. So stop yapping.
@Chowderr most likely will have to setup a KV for the analytics. I don't want to get all the results and then apply filter in application level. It would be more performant on a DB level.
I was just hoping if Vapi provides something like that which could have avoided some of my work but doesn't seem so.
c
I can't read code but I am sure the request is wrong somewhere. i have shown you an API which each request you said. Also i am not sure what a KV is.
c
KV -> Key Value store. Sorry for the abbreviation
As for the request, its what is in the "AnalyticsQueryDto" interface, so all the parameters are same. Even your query is literally same.
c
I am a bit slow sometimes, bear with me. 1. I am not sure what interface you are referring to. I am in a customGPT I built that is directly connected to VAPI. It has all the parameters in the schema. So I just talk to it and it does it thing. This was way before they took it down and put the endpoint back up. 2. All i am saying is that your main point is that it could not filter by a single assistant so i just showed an API call where i did just that. (Actually lucky because I only use Transient Assistants and i do use any API to track all the metrics you have said). Because I track all my calls and log all the data i can track anything by filtering in my DB. 3. I most likely wont be creating key-values pairs. Or a KB or anything like that. Either someone can by the schema for the GPT and use that as a base for everything. What I most likely will do is change the structure of the GPT to name all parameters for the API for any endpoint. Even deleted ones.
c
I am not sure what customGPT you are referring to, but this is the result from actual code. You can copy it into a test file and add your bearer token to see if this works properly or not.
I would not like to go via GPT route for this.
For your second point, can you point to the message where you did it?
What DB are you referring there as well?
c
My friend. I don't think you are reading what i am saying. I literally have all of the API from VAPI connected to a customGPT. It's using the VAPI API. I dont need any code at all. I know it works properly because I and others have been using it for a year. The information was from the endpoint when it showed all the parameters that you can use. https://cdn.discordapp.com/attachments/1331285157088333955/1331347085546487960/Screenshot_2025-01-21_113643.png?ex=67914918&is=678ff798&hm=0f676b39441af21e28589f12c324b995a1ae83cdb9711a2b0b8794d3f4f67c34&
c
The GPT analytics is simply get all the data and just parse it 🙂
at least that's what i can infer. GPT is good at that. I need proper api not GPT.
c
@Mason | Building KOI this is solved. Let it be.
c
Oh godd. leave it. I want it to connect it to an app. I don't want to query analytics over GPT. I am done banging my head.
c
I am not saying use the GPT. i am telling you what i am using to call the endpoint Your original statement was you were using the sdk which literally is the endpoint analytics. So I have no clue why you are saying proper api - its literally the VAPI API lol.
c
Brooo
how do you think sdks are built
its just a wrapper over the vapi endpoint.
other than that, there's no information about hitting the vapi analytics endpoint. Its incorrect.
Even if you hit it, it does not filter your responses much. Not much choice there, so its still not that useful.
That's what i am saying.
Leave it. I got my answers through enough experiemenatition and pointless arguments.
Thanks anyways. some things did help.
@Vapi Close the ticket.
v
@ChasingClouds Sweet. Have a great day!
s
@ChasingClouds Has this been resolved for you? If not, please let me know what help you need.
c
Is there a way i can get realtime analytics about my calls? If not, i will have to build my own solution.
I don’t want to post process all the response (includes multiple assistants) and then get the data. I am looking for a more fine-grained search query. If not, i will have to store my data in a DB to get realtime analytics.
s
> Is there a way i can get realtime analytics about my calls? If not, i will have to build my own solution. You can use analytics API for this.
> I don’t want to post process all the response (includes multiple assistants) and then get the data. I am looking for a more fine-grained search query. If not, i will have to store my data in a DB to get realtime analytics. Totally agreed do let me know where you feel blocked using analytics api.
c
Can you share an example usage for a specific assistantId passed as a parameter to the API to fetch this?
s
curl --location 'https://api.vapi.ai/analytics' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer f35fe0645' \ --data '{ "queries": [ { "name": "getAnalyticsByAssistantID", "table": "call", "timeRange": { "start": "2024-01-01T00:00:00Z", "end": "2024-12-31T23:59:59Z", "step": "year" }, "operations": [ { "operation": "sum", "column": "cost" } ], "groupBy": [ "assistantId", "endedReason" ] } ] }' @ChasingClouds you can use this example to get started which gives you cost by assistantId and grouped with endedReason. Soon will write a complete docs on this.
c
Yup this can be the workaround but not a complete solution which I want. Just see the output: { "name": "getAnalyticsByAssistantId", "timeRange": { "start": "2024-01-01T00:00:00.000Z", "end": "2025-01-30T15:04:00.000Z", "step": "year", "timezone": "UTC" }, "result": [ { "date": "2024-01-01T00:00:00.000Z", "assistantId": "d753855a-10e9-4334-a2df-675fdcdda02a", "endedReason": "assistant-forwarded-call", "sumCost": 0.42843999999999993 }, { "date": "2024-01-01T00:00:00.000Z", "assistantId": "d753855a-10e9-4334-a2df-675fdcdda02a", "endedReason": "customer-ended-call", "sumCost": 0.17787999999999998 }, { "date": "2024-01-01T00:00:00.000Z", "assistantId": "3a9e0733-6004-4995-b54d-f38af0701bfc", "endedReason": "customer-ended-call", "sumCost": 0.04864 }, { "date": "2025-01-01T00:00:00.000Z", "assistantId": "00000000-0000-0000-0000-000000000000", "endedReason": "customer-did-not-give-microphone-permission", "sumCost": 0.005 }, { "date": "2025-01-01T00:00:00.000Z", "assistantId": "00000000-0000-0000-0000-000000000000", "endedReason": "assistant-forwarded-call", "sumCost": 0.0317 }, { "date": "2025-01-01T00:00:00.000Z", "assistantId": "3a9e0733-6004-4995-b54d-f38af0701bfc", "endedReason": "customer-ended-call", "sumCost": 0.0593 }
There are different assistantIds i get.
So for each assistantId, if I want to update the call count for each component, I can't keep making these api request and then filter by assistantId right.
Is there no endpoint that makes call taking specific assistant id?
Okay
I am able to reduce it to some extent by making queries on column "id".
However, that will give me all the assistantId and not any specific id. But the data size will be less. Still very rough solution. Because, each assistant will have a different creation date, so the timeRange in the request will be different.
Best idea seems to be able to store them in a DB
s
As of now, but will add this an Feature request.
Because analytics are stored with a different POV with comparison to records keeping.
2 Views