# SDKs

> Call the Analytics Server API from your application.

Use an official SDK to query playback reports, export data, and manage your Analytics Server from your backend. SDKs are available for TypeScript, Python, PHP, and Go, for both hosted and self-hosted servers.

To collect playback events in the browser, use the [player analytics tracker](/docs/integration/analytics). To manage Chunkify Assets or saved analytics connections, use the [Chunkify API SDKs](/docs/integration/sdk).

## Connect to your server

Create a **Read-only API key** in your hosted Analytics Server's **Keys** tab. For a self-hosted server, follow [Setup](/docs/integration/analytics/server/setup#connect-it-to-chunkify) to create a read-only key.

Set `CHUNKIFY_ANALYTICS_SECRET_KEY` in your backend environment to this key. All four SDKs read it automatically. Keep private keys on your backend and return only the results your frontend needs.

The examples use `https://analytics.chunkify.dev`. For a self-hosted server, replace it with your server's base URL, without `/v1`. The SDK adds the API path to each request.

## Install and query a report

Each example reads a summary for one video. Replace the example ID with the `videoId` sent by your player. Omit the video filter to read totals for the whole analytics project.

<tabs>
    <tab title="TypeScript">
        The SDK also supports server-side JavaScript. See the [runtime requirements](https://github.com/chunkifydev/chunkify-analytics-typescript#requirements).

        ```sh
        npm install @chunkify/analytics
        ```

        Save this as `example.mjs`:

        ```javascript
        import ChunkifyAnalytics from '@chunkify/analytics';

        const client = new ChunkifyAnalytics({
            baseURL: 'https://analytics.chunkify.dev',
        });

        const summary = await client.summary.retrieve({
            video_id: 'ast_3Ljtoej7c3Y1plabZoElbQwdwLh',
        });

        console.log(summary);
        ```

        ```sh
        node example.mjs
        ```

        [SDK documentation on GitHub](https://github.com/chunkifydev/chunkify-analytics-typescript)
    </tab>
    <tab title="Python">
        Requires Python 3.9 or later.

        ```sh
        python -m pip install chunkify-analytics-sdk
        ```

        Save this as `example.py`:

        ```python
        from chunkify_analytics import ChunkifyAnalytics

        client = ChunkifyAnalytics(
            base_url="https://analytics.chunkify.dev",
        )

        summary = client.summary.retrieve(
            video_id="ast_3Ljtoej7c3Y1plabZoElbQwdwLh",
        )

        print(summary)
        ```

        ```sh
        python example.py
        ```

        [SDK documentation on GitHub](https://github.com/chunkifydev/chunkify-analytics-python)
    </tab>
    <tab title="PHP">
        Requires PHP 8.1 or later and Composer.

        ```sh
        composer require chunkify/chunkify-analytics-php
        ```

        Save this as `example.php`:

        ```php
        <?php

        use ChunkifyAnalytics\Client;

        require_once __DIR__ . '/vendor/autoload.php';

        $client = new Client(
            baseUrl: 'https://analytics.chunkify.dev',
        );

        $summary = $client->summary->retrieve(
            videoID: 'ast_3Ljtoej7c3Y1plabZoElbQwdwLh',
        );

        print_r($summary);
        ```

        ```sh
        php example.php
        ```

        [SDK documentation on GitHub](https://github.com/chunkifydev/chunkify-analytics-php)
    </tab>
    <tab title="Go">
        Requires Go 1.22 or later. In your application's Go module, install the SDK:

        ```sh
        go get github.com/chunkifydev/chunkify-analytics-go
        ```

        Save this as `example.go`:

```go
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/chunkifydev/chunkify-analytics-go"
	"github.com/chunkifydev/chunkify-analytics-go/option"
)

func main() {
	client := chunkifyanalytics.NewClient(
		option.WithBaseURL("https://analytics.chunkify.dev"),
	)

	summary, err := client.Summary.Get(
		context.Background(),
		chunkifyanalytics.SummaryGetParams{
			VideoID: chunkifyanalytics.String("ast_3Ljtoej7c3Y1plabZoElbQwdwLh"),
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(summary.RawJSON())
}
```

        ```sh
        go run example.go
        ```

        [SDK documentation on GitHub](https://github.com/chunkifydev/chunkify-analytics-go)
    </tab>
</tabs>

The summary returns `views`, `unique_viewers`, and `total_playing_time_ms`.

## Credentials for other operations

The SDKs cover the full Analytics Server API. Choose credentials for the operations your application needs:

| Operation | Credential |
| --- | --- |
| Read reports, events, and sessions; create CSV exports | Private read-only key. |
| Send events | Public ingestion key. Use the player analytics tracker for browser playback. |
| Manage an analytics project's settings and keys | Full-access private key for that analytics project. |
| Create analytics projects or recover their keys | Installation admin key for a self-hosted server. |

Chunkify Project and Team access tokens belong to the main Chunkify API and cannot authenticate Analytics Server requests. See [Administration](/docs/integration/analytics/server/maintenance) for key management.

## Next steps

- [Query reports](/docs/integration/analytics/server/query-analytics): understand results, apply filters, and export CSV data.
- [API reference](/docs/integration/analytics/server/api-reference): check the reference status and access the OpenAPI specification.
- [Connect with MCP](/docs/integration/analytics/server/mcp): explore reports with an AI client.
