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

# Go

> Set up your Telemetree Go SDK

<img className="block dark:hidden" src="https://mintcdn.com/telemetree/akp6XNv3V6IKBA56/images/tele-hero-light.svg?fit=max&auto=format&n=akp6XNv3V6IKBA56&q=85&s=c92236583b01bcf1c327de87393c9b11" alt="Hero Light" width="700" height="320" data-path="images/tele-hero-light.svg" />

<img className="hidden dark:block" src="https://mintcdn.com/telemetree/akp6XNv3V6IKBA56/images/tele-hero-dark.svg?fit=max&auto=format&n=akp6XNv3V6IKBA56&q=85&s=6c753a4fcf02917cda0ae770ed798fe5" alt="Hero Dark" width="700" height="320" data-path="images/tele-hero-dark.svg" />

<Note> [Github](https://github.com/Telemetree/telemetree-go) </Note>
Telemetree is a comprehensive free analytics tool designed specifically for **Telegram Mini Apps**. With our SDKs, developers, marketers, and product managers can easily track and optimize user engagement, making data-driven decisions to boost user acquisition and retention. Telemetree simplifies **Analytics for Telegram Mini Apps** by delivering insights into user behaviors, acquisition channels, and in-app interactions.

## Installation

Install analytics-go using go get:

```shell theme={null}
go get github.com/TONSolutions/telemetree-go
```

## Quick Start

Create a Telemetree SDK client by providing the Project ID and API Key.

```go theme={null}
client, err := telemetree.NewClient(
	"YOUR_PROJECT_ID",
	"YOUR_API_KEY",
)

if err != nil {
	// handle error
}
```

## Event Tracking

Send an event with user and event data.

```go theme={null}

err = client.Track(telemetree.Event{
	TelegramID: 112294972,     // User's Telegram ID (required)
	EventType:  "web",         // Event type (required)
	IsPremium:  true,          // Premium status flag (optional)


	Username:     "username",  // Username
	Firstname:    "firstname", // First name
	Lastname:     "Lastname",  // Last name
	Language:     "en",        // User's language
	ReferrerType: "web",       // Traffic source type
	Referrer:     "0",         // Traffic source
})

if err != nil {
	fmt.Println("Error track event:", err)
	return
}
```

## Errors handling

The client returns typed errors, which are specifically defined in the `github.com/Telemetree/telemetree-go/telemetree/errors` package.
These custom error types provide more detailed information about specific error scenarios, making error handling more precise and informative.

The following error types are defined in the `github.com/Telemetree/telemetree-go/telemetree/errors` package:

* `ClientInitializationError`: Represents errors occurring during client initialization, with an associated reason.
* `EventValidationError`: Represents validation errors for event fields, with the specific field that failed validation.
* `EventPreparationError`: Represents errors during event preparation, including a description of the failure.
* `EventSendError`: Represents errors encountered when sending events, with a description of the error.

You can use type assertion or `errors.As` to handle these errors in a type-safe manner and access the underlying details.

### Encryption

The SDK uses RSA encryption to secure event data before sending it to the Telemetree service, ensuring data privacy. The `publicKey` is fetched automatically from the Telemetree configuration service during initialization, so there’s no need to manually set it.

## Key Features

* **Real-Time Analytics**: Monitor user activity within your Telegram Mini App in real-time.
* **User Retention Metrics**: Track returning users and pinpoint which features encourage app retention.
* **Web3 data**: discover web3 metrics associated with your users.
* **Seamless Integration**: Our SDKs are lightweight and integrate easily with auto event mapping.
* **Telegram-native**: Telemetree is built natively for Telegram.
* **User segmentation**: API for personalized notifications based on cohorts, completed actions. web3 data and more.
* **Free tier** with wide limits

## Resources

Consider visiting our resources for more info about the state of the Telegram Mini Apps ecosystem and Telegram analytics.

* [Website](https://www.telemetree.io/)
* [Twitter](https://x.com/telemetree_HQ)
* [Telegram channel](https://t.me/telemetree_en)
* [LinkedIn](https://linkedin.com/company/telemetree)
* [Medium](https://medium.com/@telemetree)
* [Documentation](https://docs.telemetree.io/)
