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

# Go SDK

> Track events from Go servers with the Mixpanel server-side SDK

## Installation

```bash theme={null}
go get github.com/mixpanel/mixpanel-go
```

## Initialize

```go theme={null}
import "github.com/mixpanel/mixpanel-go"

mp := mixpanel.NewApiClient("YOUR_PROJECT_TOKEN")
```

### Configuration

```go theme={null}
mp := mixpanel.NewApiClient(
  "YOUR_PROJECT_TOKEN",
  mixpanel.ServiceAccount(7282615, "service_account_name", "service_account_secret")
)
```

## Track Events

<Warning>
  You must provide a `distinct_id` for all events.
</Warning>

```go theme={null}
ctx := context.Background()

err := mp.Track(ctx, []*mixpanel.Event{
  mp.NewEvent("Purchase", "12345", map[string]any{
    "product": "Premium Subscription",
    "amount": 49.99,
    "currency": "USD",
  }),
})

if err != nil {
  log.Fatal(err)
}
```

## Import Historical Events

For events older than 5 days:

```go theme={null}
ctx := context.Background()

event := mp.NewEvent("Old Purchase", mixpanel.EmptyDistinctID, nil)
event.AddTime(time.Now().AddDate(0, 0, -10))
event.AddInsertID("unique_insert_id")

importEvents := []*mixpanel.Event{event}

err := mp.Import(ctx, importEvents, mixpanel.ImportOptionsRecommend)
if err != nil {
  log.Fatal(err)
}
```

## User Profiles

```go theme={null}
ctx := context.Background()

user := mixpanel.NewPeopleProperties("12345", map[string]any{
  "name": "John Doe",
  "email": "john@example.com",
  "plan": "Premium",
  "$ip": 0, // Disable geolocation
})

err := mp.PeopleSet(ctx, []*mixpanel.PeopleProperties{user})
```

<Tabs>
  <Tab title="PeopleSetOnce()">
    ```go theme={null}
    user := mixpanel.NewPeopleProperties("12345", map[string]any{
      "First Purchase": "2024-01-01",
      "$ip": 0,
    })

    err := mp.PeopleSetOnce(ctx, []*mixpanel.PeopleProperties{user})
    ```
  </Tab>

  <Tab title="PeopleIncrement()">
    ```go theme={null}
    err := mp.PeopleIncrement(ctx, "12345", map[string]int{
      "login_count": 1,
      "age": 1,
    })
    ```
  </Tab>

  <Tab title="PeopleAppendListProperty()">
    ```go theme={null}
    err := mp.PeopleAppendListProperty(ctx, "12345", map[string]any{
      "transactions": []string{"purchase_123"},
    })
    ```
  </Tab>

  <Tab title="PeopleUnionProperty()">
    ```go theme={null}
    err := mp.PeopleUnionProperty(ctx, "12345", map[string]any{
      "skills": []string{"Go", "Microservices"},
    })
    ```
  </Tab>
</Tabs>

## Group Analytics

### Send Events

```go theme={null}
ctx := context.Background()

err := mp.Track(ctx, []*mixpanel.Event{
  mp.NewEvent("Feature Used", "12345", map[string]any{
    "company": "Acme Inc",
    "feature": "Reports",
  }),
})
```

### Set Group Properties

```go theme={null}
err := mp.GroupSet(ctx, "company", "Acme Inc", map[string]any{
  "name": "Acme Inc",
  "industry": "Technology",
  "employees": 500,
})
```

<Tabs>
  <Tab title="GroupSetOnce()">
    ```go theme={null}
    err := mp.GroupSetOnce(ctx, "company", "Acme Inc", map[string]any{
      "founded": "2010-01-01",
    })
    ```
  </Tab>

  <Tab title="GroupDeleteProperty()">
    ```go theme={null}
    err := mp.GroupDeleteProperty(ctx, "company", "Acme Inc", "temp_property")
    ```
  </Tab>

  <Tab title="GroupUnionListProperty()">
    ```go theme={null}
    err := mp.GroupUnionListProperty(ctx, "company", "Acme Inc", map[string]any{
      "features": []string{"Reports", "Analytics"},
    })
    ```
  </Tab>

  <Tab title="GroupRemoveListProperty()">
    ```go theme={null}
    err := mp.GroupRemoveListProperty(ctx, "company", "Acme Inc", map[string]any{
      "features": []string{"Beta Feature"},
    })
    ```
  </Tab>
</Tabs>

## Privacy Controls

### EU Data Residency

```go theme={null}
ctx := context.Background()

mp := mixpanel.NewApiClient(
  "YOUR_PROJECT_TOKEN",
  mixpanel.EuResidency()
)
```

### Disable Geolocation

```go theme={null}
// For events
err := mp.Track(ctx, []*mixpanel.Event{
  mp.NewEvent("event", "12345", map[string]any{
    "ip": "0",
  }),
})

// For profiles
user := mixpanel.NewPeopleProperties("12345", map[string]any{
  "name": "John",
  "$ip": 0,
})
err := mp.PeopleSet(ctx, []*mixpanel.PeopleProperties{user})
```

## Platform Considerations

<Warning>
  All server-side calls originate from your server's IP. Set `ip` to `0` to disable geolocation.
</Warning>

* Context-based API (use `context.Background()`)
* You manage `distinct_id` yourself
* No automatic identity management
* Use `.Import()` for historical events
* Type-safe API with Go generics
* Designed for high-performance Go services

## Resources

* [Full API Reference](https://pkg.go.dev/github.com/mixpanel/mixpanel-go)
* [GitHub Repository](https://github.com/mixpanel/mixpanel-go)
* [Examples](https://github.com/mixpanel/mixpanel-go/tree/main/examples)
