> ## 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.

# Flutter SDK

> Track events from Flutter apps with the Mixpanel Flutter SDK

## Installation

<Steps>
  <Step title="Add dependency">
    Add to `pubspec.yaml`:

    ```yaml theme={null}
    dependencies:
      mixpanel_flutter: ^1.x.x
    ```
  </Step>

  <Step title="Install packages">
    ```bash theme={null}
    flutter pub get
    ```
  </Step>

  <Step title="Initialize Mixpanel">
    ```dart theme={null}
    import 'package:mixpanel_flutter/mixpanel_flutter.dart';

    class _YourClassState extends State<YourClass> {
      Mixpanel mixpanel;

      @override
      void initState() {
        super.initState();
        initMixpanel();
      }

      Future<void> initMixpanel() async {
        mixpanel = await Mixpanel.init(
          "YOUR_PROJECT_TOKEN",
          trackAutomaticEvents: false
        );
      }
    }
    ```
  </Step>
</Steps>

## Flutter Web Support

Add to `web/index.html` inside `<head>`:

```html theme={null}
<script src="./assets/packages/mixpanel_flutter/assets/mixpanel.js"></script>
```

## Track Events

```dart theme={null}
mixpanel.track('Button Clicked', {
  'button_name': 'Sign Up',
  'screen': 'Landing Page'
});
```

### Timing Events

```dart theme={null}
mixpanel.timeEvent('Image Upload');

// 20 seconds later
mixpanel.track('Image Upload');
```

### Flush Events

```dart theme={null}
mixpanel.flush();
```

## Identify Users

```dart theme={null}
mixpanel.track('sign in');
mixpanel.identify('12345');
```

### Reset on Logout

```dart theme={null}
mixpanel.track('log out');
mixpanel.reset();
```

## User Profiles

```dart theme={null}
mixpanel.identify('12345');
mixpanel.getPeople().set('Plan', 'Premium');

// Set multiple properties
mixpanel.getPeople().set({
  'name': 'John',
  'email': 'john@example.com'
});
```

<Tabs>
  <Tab title="setOnce()">
    ```dart theme={null}
    mixpanel.getPeople().setOnce('name', 'John');
    mixpanel.getPeople().setOnce('location', 'US');
    ```
  </Tab>

  <Tab title="increment()">
    ```dart theme={null}
    mixpanel.getPeople().increment('age', 1);
    mixpanel.getPeople().increment('login_count', 1);
    ```
  </Tab>

  <Tab title="append()">
    ```dart theme={null}
    mixpanel.getPeople().append('roles', 'admin');
    ```
  </Tab>

  <Tab title="union()">
    ```dart theme={null}
    mixpanel.getPeople().union('skills', 'Flutter');
    ```
  </Tab>
</Tabs>

## Super Properties

```dart theme={null}
mixpanel.registerSuperProperties({
  'app_version': '2.0.1',
  'platform': 'Flutter'
});

mixpanel.registerSuperPropertiesOnce({
  'first_launch': DateTime.now().toIso8601String()
});
```

## Group Analytics

```dart theme={null}
// Assign to group
mixpanel.setGroup('company', 'Acme Inc');

// Track event
mixpanel.track('feature_used');

// Set group properties
mixpanel.getGroup('company', 'Acme Inc').set('industry', 'Technology');
```

## Privacy Controls

### Opt Out

```dart theme={null}
mixpanel.optOutTracking();

// Initialize with opt-out
mixpanel = await Mixpanel.init(
  "YOUR_PROJECT_TOKEN",
  trackAutomaticEvents: false,
  optOutTrackingDefault: true
);
```

### EU/India Data Residency

```dart theme={null}
// EU
mixpanel.setServerURL('https://api-eu.mixpanel.com');

// India
mixpanel.setServerURL('https://api-in.mixpanel.com');
```

### Disable Geolocation

```dart theme={null}
mixpanel.setUseIpAddressForGeolocation(false);
```

## Debug Mode

```dart theme={null}
mixpanel.setLoggingEnabled(true);
```

## Platform Considerations

* Works on iOS, Android, and Web
* Events flush every 60 seconds
* Supports hot reload during development
* Legacy auto-track events available but not recommended
* Web requires additional script tag

## Resources

* [Full API Reference](https://mixpanel.github.io/mixpanel-flutter)
* [GitHub Repository](https://github.com/mixpanel/mixpanel-flutter)
* [Example App](https://github.com/mixpanel/mixpanel-flutter/tree/main/example)
