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

# Chat Analytics

> Track and visualize chat usage patterns and user engagement metrics

## Overview

The Chat Analytics component provides comprehensive insights into how users interact with chat components across your platform. It helps educators and administrators understand usage patterns, identify popular topics, measure engagement levels, and make data-driven decisions to improve the learning experience.

## Creating a Chat Analytics Component

<CodeGroup>
  ```javascript JavaScript theme={null}
  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: 'chat-comp-123',
      autoRefresh: true,
      dateRange: 30,
      enableExport: true,
      refreshInterval: 5,
      showSummary: true,
      showTopics: true,
      showUserStats: true
    }
  });

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

  ```python Python theme={null}
  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={
          "chatComponentId": "chat-comp-123",
          "autoRefresh": True,
          "dateRange": 30,
          "enableExport": True,
          "refreshInterval": 5,
          "showSummary": True,
          "showTopics": True,
          "showUserStats": True
      }
  )

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

  ```java Java theme={null}
  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;
  import java.util.List;

  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("chat-comp-123")
                  .autoRefresh(true)
                  .dateRange(30.0)
                  .enableExport(true)
                  .refreshInterval(5.0)
                  .showSummary(true)
                  .showTopics(true)
                  .showUserStats(true)
                  .build())
              .build();

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

  ```csharp C# theme={null}
  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 = "chat-comp-123",
                  AutoRefresh = true,
                  DateRange = 30,
                  EnableExport = true,
                  RefreshInterval = 5,
                  ShowSummary = true,
                  ShowTopics = true,
                  ShowUserStats = true
              }
          });

          Console.WriteLine($"Chat Analytics component created: {analyticsComponent._ID}");
      }
  }
  ```
</CodeGroup>

## Configuration Parameters

<ParamField body="name" type="string" required>
  Name of the chat analytics component
</ParamField>

<ParamField body="type" type="string" required>
  Must be `chat_analytics`
</ParamField>

<ParamField body="config" type="object" required>
  Configuration options for the chat analytics component

  <Expandable title="config properties">
    <ParamField body="chatComponentId" type="string" required>
      ID of the chat component to analyze
    </ParamField>

    <ParamField body="autoRefresh" type="boolean" default="true">
      Enable auto-refresh of analytics data
    </ParamField>

    <ParamField body="dateRange" type="number" default="30">
      Default date range in days for analytics display
    </ParamField>

    <ParamField body="enableExport" type="boolean" default="true">
      Enable CSV export functionality
    </ParamField>

    <ParamField body="refreshInterval" type="number" default="5">
      Refresh interval in minutes (minimum: 1, maximum: 60)
    </ParamField>

    <ParamField body="showSummary" type="boolean" default="true">
      Show summary section in analytics dashboard
    </ParamField>

    <ParamField body="showTopics" type="boolean" default="true">
      Show top topics analysis section
    </ParamField>

    <ParamField body="showUserStats" type="boolean" default="true">
      Show user statistics and activity patterns
    </ParamField>
  </Expandable>
</ParamField>

## Response

```json theme={null}
{
  "_id": "comp_123abc",
  "name": "Platform Chat Analytics Dashboard",
  "type": "chat_analytics",
  "status": "active",
  "config": {
    "chatComponentId": "chat-comp-123",
    "autoRefresh": true,
    "dateRange": 30,
    "enableExport": true,
    "refreshInterval": 5,
    "showSummary": true,
    "showTopics": true,
    "showUserStats": true
  },
  "createdAt": "2024-01-15T10:00:00Z",
  "updatedAt": "2024-01-15T10:00:00Z",
  "organizationId": "org_456def",
  "usage": {
    "interactions": 0,
    "lastUsed": null
  }
}
```

## Embedding This Component

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

### Generate Embed URL

<CodeGroup>
  ```javascript JavaScript theme={null}
  const embedResponse = await client.v1.components.generateEmbed(analyticsComponent._id, {
    // User tracking
    userId: 'user-456',
    studentName: 'Jane Smith',  // Student name for display
    groupIds: ['class-101', 'class-102'],
    sessionId: 'session-789',
    

    
    // Dimensions
    width: '100%',
    height: '800px',
    
    // Token expiry
    expiryHours: 24
  });
  ```

  ```python Python theme={null}
  embed_response = client.v1.components.generateEmbed(
      component_id=analytics_component._id,
      userId="user-456",
      student_name="Jane Smith",  # Student name for display
      groupIds=["class-101", "class-102"],
      sessionId="session-789",

      width="100%",
      height="800px",
      expiryHours=24
  )
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedParams;
  import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedResponse;

  StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
      .fromEnv()
      .baseURL("https://studyfetchapi.com")
      .build();

  ComponentGenerateEmbedParams params = ComponentGenerateEmbedParams.builder()
      .id(analyticsComponent._id())
      // User tracking
      .userId("user-456")
      .studentName("Jane Smith")  // Student name for display
      .groupIds(List.of("class-101", "class-102"))
      .sessionId("session-789")
      

      
      // Dimensions
      .width("100%")
      .height("800px")
      
      // Token expiry
      .expiryHours(24)
      .build();

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

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Components;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;

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

          var embedResponse = await client.V1.Components.GenerateEmbed(new()
          {
              ID = "component_123abc", // Replace with your component ID
              UserID = "user-456",
              StudentName = "Jane Smith",  // Student name for display
              GroupIDs = new List<string> { "class-101", "class-102" },
              Width = "100%",
              Height = "600px"
          });

          Console.WriteLine($"Embed URL: {embedResponse.EmbedURL}");
          Console.WriteLine($"Token: {embedResponse.Token}");
      }
  }
  ```
</CodeGroup>

### Embed in Your HTML

```html theme={null}
<iframe 
  src="https://embed.studyfetch.com/component/comp_123abc?token=..."
  width="100%"
  height="800px"
  frameborder="0"
  allow="clipboard-write"
  style="border: 1px solid #e5e5e5; border-radius: 8px;">
</iframe>
```
