Skip to content
StudyFetch API

API Documentation

Chat Analytics

Overview

The Chat Analytics component is an embeddable dashboard for one Chat component. It helps educators and administrators understand usage patterns, identify popular topics, measure engagement levels, and make data-driven decisions to improve the learning experience.

To read the same analytics from your server instead, use the Chat Analytics API.

Creating a Chat Analytics Component

chatComponentId must be the chat component's _id (the 24-character database ID returned when you created it), not its chat_… componentId.

JavaScript

import StudyfetchSDK from '@studyfetch/sdk';

const client = new StudyfetchSDK({
  apiKey: 'your-api-key',
  baseURL: 'https://studyfetchapi.com',
});

const analyticsComponent = await client.v1.components.create({
  name: 'Platform Chat Analytics Dashboard',
  type: 'chat_analytics',
  config: {
    chatComponentId: '6650f1c2a9b3e4d5f6a7b8c9', // The chat component's _id
    dateRange: 30,
    autoRefresh: true,
    refreshInterval: 5,
    enableExport: true,
    showSummary: true,
    showTopics: true,
    showUserStats: true,
  },
});

console.log('Chat Analytics component created:', analyticsComponent._id);

Python

from studyfetch_sdk import StudyfetchSDK

client = StudyfetchSDK(
    api_key="your-api-key",
    base_url="https://studyfetchapi.com",
)

analytics_component = client.v1.components.create(
    name="Platform Chat Analytics Dashboard",
    type="chat_analytics",
    config={
        "chat_component_id": "6650f1c2a9b3e4d5f6a7b8c9",  # The chat component's _id
        "date_range": 30,
        "auto_refresh": True,
        "refresh_interval": 5,
        "enable_export": True,
        "show_summary": True,
        "show_topics": True,
        "show_user_stats": True,
    },
)

print(f"Chat Analytics component created: {analytics_component.api_id}")

Java

import com.studyfetch.javasdk.client.StudyfetchSdkClient;
import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
import com.studyfetch.javasdk.models.v1.components.ComponentResponse;
import com.studyfetch.javasdk.models.v1.components.ComponentCreateParams;

public class CreateChatAnalyticsComponent {
    public static void main(String[] args) {
        StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
            .fromEnv()
            .baseUrl("https://studyfetchapi.com")
            .build();

        ComponentCreateParams params = ComponentCreateParams.builder()
            .name("Platform Chat Analytics Dashboard")
            .type(ComponentCreateParams.Type.CHAT_ANALYTICS)
            .config(ComponentCreateParams.Config.ChatAnalyticsConfigDto.builder()
                .chatComponentId("6650f1c2a9b3e4d5f6a7b8c9") // The chat component's _id
                .dateRange(30.0)
                .autoRefresh(true)
                .refreshInterval(5.0)
                .enableExport(true)
                .showSummary(true)
                .showTopics(true)
                .showUserStats(true)
                .build())
            .build();

        ComponentResponse component = client.v1().components().create(params);
        System.out.println("Chat Analytics component created: " + component._id());
    }
}

C#

using StudyfetchSDK;
using StudyfetchSDK.Models.V1.Components;
using System;
using System.Threading.Tasks;

public class CreateChatAnalyticsComponent
{
    public static async Task CreateChatAnalytics()
    {
        var client = new StudyfetchSDKClient()
        {
            APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
            BaseUrl = new Uri("https://studyfetchapi.com")
        };

        var analyticsComponent = await client.V1.Components.Create(new()
        {
            Name = "Platform Chat Analytics Dashboard",
            Type = StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.Type.ChatAnalytics,
            Config = new StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.ConfigProperties.ChatAnalyticsConfigDto()
            {
                ChatComponentID = "6650f1c2a9b3e4d5f6a7b8c9", // The chat component's _id
                DateRange = 30,
                AutoRefresh = true,
                RefreshInterval = 5,
                EnableExport = true,
                ShowSummary = true,
                ShowTopics = true,
                ShowUserStats = true
            }
        });

        Console.WriteLine($"Chat Analytics component created: {analyticsComponent._ID}");
    }
}

Configuration Parameters

name

string · required

Name of the chat analytics component

type

string · required

Must be chat_analytics

config

object · required

Configuration options for the chat analytics component. Unknown keys are rejected with 400; unlike other components, this one does not accept materials or folders.

config properties

These properties go inside config.

chatComponentId

string · required

_id of the chat component to analyze. It isn't checked when the component is created, so an invalid ID only shows up as an error when the dashboard loads.

dateRange

number · default: 30

Default date range in days for the dashboard

autoRefresh

boolean · default: false

Refresh the dashboard automatically. Only takes effect when refreshInterval is also set.

refreshInterval

number

Refresh interval in minutes, from 1 to 60. Required for autoRefresh to work; there is no default.

enableExport

boolean · default: true

Show the CSV export button

showSummary

boolean · default: true

Show the summary section

showTopics

boolean · default: true

Show the top topics section

showUserStats

boolean · default: true

Show user statistics and activity patterns

Response

{
  "_id": "6651a2b3c4d5e6f7a8b9c0d1",
  "componentId": "chat_analytics_V1StGXR8_Z",
  "name": "Platform Chat Analytics Dashboard",
  "type": "chat_analytics",
  "status": "active",
  "origin": "api",
  "organization": "64f0a1b2c3d4e5f6a7b8c9d0",
  "materials": [],
  "folders": [],
  "config": {
    "chatComponentId": "6650f1c2a9b3e4d5f6a7b8c9",
    "dateRange": 30,
    "autoRefresh": true,
    "refreshInterval": 5,
    "enableExport": true,
    "showSummary": true,
    "showTopics": true,
    "showUserStats": true
  },
  "usageCount": 0,
  "createdAt": "2026-10-06T10:00:00.000Z",
  "updatedAt": "2026-10-06T10:00:00.000Z"
}

Embedding This Component

Once you've created a Chat Analytics component, you can embed it on your website using the embedding API. The component must be active.

Generate Embed URL

JavaScript

// Organization-wide dashboard: no userId
const embedResponse = await client.v1.components.generateEmbed(analyticsComponent._id, {
  studentName: 'Dr. Patel',  // Name for display
  width: '100%',
  height: '800px',
});

console.log(embedResponse.embedUrl);

Python

# Organization-wide dashboard: no user_id
embed_response = client.v1.components.generate_embed(
    analytics_component.api_id,
    student_name="Dr. Patel",  # Name for display
    width="100%",
    height="800px",
)

print(embed_response.embed_url)

Java

import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedParams;
import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedResponse;

// Organization-wide dashboard: no userId
ComponentGenerateEmbedParams params = ComponentGenerateEmbedParams.builder()
    .id(analyticsComponent._id())
    .studentName("Dr. Patel")  // Name for display
    .width("100%")
    .height("800px")
    .build();

ComponentGenerateEmbedResponse embedResponse = client.v1().components()
    .generateEmbed(params);

System.out.println(embedResponse.embedUrl());

C#

using StudyfetchSDK;
using StudyfetchSDK.Models.V1.Components;
using System;
using System.Threading.Tasks;

public class GenerateChatAnalyticsEmbed
{
    public static async Task GenerateEmbed(string analyticsComponentId)
    {
        var client = new StudyfetchSDKClient()
        {
            APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
            BaseUrl = new Uri("https://studyfetchapi.com")
        };

        // Organization-wide dashboard: no UserID
        var embedResponse = await client.V1.Components.GenerateEmbed(new()
        {
            ID = analyticsComponentId,
            StudentName = "Dr. Patel",  // Name for display
            Width = "100%",
            Height = "800px"
        });

        Console.WriteLine($"Embed URL: {embedResponse.EmbedURL}");
        Console.WriteLine($"Token: {embedResponse.Token}");
    }
}

The response contains embedUrl, token, expiresAt, componentId (the component's _id), componentType, and options (width and height, defaulting to 100% and 600px). The dashboard's settings come from the component's config; it doesn't use any features settings.

Embed in Your HTML

Use the embedUrl from the response as the iframe source. The host can differ per organization, so don't build the URL yourself.

<iframe
  src="EMBED_URL_FROM_RESPONSE"
  width="100%"
  height="800px"
  frameborder="0"
  allow="clipboard-write"
  style="border: 1px solid #e5e5e5; border-radius: 8px;">
</iframe>

The React Native SDK does not include a Chat Analytics component; use the iframe embed.