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

# Flutter

<Prompt description="Use Cursor, Claude Code, or another AI to help you integrate the Flutter SDK." actions={["copy", "cursor"]}>
  You are an expert Flutter engineer helping me integrate the Appstack Flutter plugin into my app. You are running inside an IDE assistant such as Cursor or Claude Code and you can see my codebase.

  Use the reference below to fully wire the plugin. When I paste this prompt and share my Dart and platform files, you should:

  1. Provide the exact `pubspec.yaml` changes and `flutter pub` commands required, plus any iOS (`pod install`) and Android (repositories/Gradle) configuration, using the details below.
  2. Tell me exactly where to initialize the plugin in my Flutter app and generate idiomatic Dart code to do it, based on the snippets below.
  3. Validate my iOS and Android setup (versions, repositories, build settings) against the documentation and highlight anything missing.
  4. Summarize the full checklist (install, configure, platform setup, event tracking) so we can confirm that everything from the docs has been applied.

  ***

  ## Reference: Appstack Flutter plugin

  **Requirements**

  * iOS: 13.0+ (14.3+ recommended for Apple Ads), Xcode 14.0+
  * Android: Min SDK 21, Target SDK 34+
  * Flutter: 3.3.0+
  * Dart: 2.18.0+

  **pubspec.yaml & installation**

  ```bash theme={null}
  flutter pub add appstack_plugin
  flutter pub get
  ```

  (Or add `appstack_plugin` under `dependencies` in `pubspec.yaml` using the **current** version from [pub.dev/packages/appstack\_plugin](https://pub.dev/packages/appstack_plugin).)

  **iOS configuration**

  ```bash theme={null}
  cd ios && pod install
  ```

  * The iOS `AppstackSDK.xcframework` is bundled with the plugin; no extra dependencies required.

  **Android configuration**

  ```gradle theme={null}
  allprojects {
      repositories {
          google()
          mavenCentral()
          maven { url 'https://jitpack.io' }
      }
  }
  ```

  **Quickstart example**

  ```dart theme={null}
  import 'package:flutter/material.dart';
  import 'package:appstack_plugin/appstack_plugin.dart';
  import 'dart:io' show Platform;

  void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    
    // Configure the SDK
    final apiKey = Platform.isIOS 
        ? 'your-ios-api-key' 
        : 'your-android-api-key';
    
    await AppstackPlugin.configure(apiKey);
    
    // Enable Apple Ads attribution on iOS
    if (Platform.isIOS) {
      await AppstackPlugin.enableAppleAdsAttribution();
    }
    
    runApp(MyApp());
  }

  class MyApp extends StatelessWidget {
    void trackPurchase() {
      AppstackPlugin.sendEvent(
        EventType.purchase, 
        parameters: {'revenue': 29.99, 'currency': 'USD'}
      );
    }

    @override
    Widget build(BuildContext context) {
      // ... your app
    }
  }
  ```

  **Configuration parameters**

  ```dart theme={null}
  final success = await AppstackPlugin.configure('your-api-key-here');
  if (!success) {
    print('SDK configuration failed');
  }

  // With all parameters
  await AppstackPlugin.configure(
    'your-api-key-here',
    isDebug: true,
    logLevel: 0, // DEBUG
  );
  ```

  **Sending events**

  ```dart theme={null}
  // Track events without parameters
  await AppstackPlugin.sendEvent(EventType.signUp);
  await AppstackPlugin.sendEvent(EventType.levelComplete);

  // Track events with parameters (including revenue)
  await AppstackPlugin.sendEvent(
    EventType.purchase, 
    parameters: {'revenue': 29.99, 'currency': 'USD'}
  );
  await AppstackPlugin.sendEvent(
    EventType.subscribe, 
    parameters: {'revenue': 9.99, 'plan': 'monthly'}
  );

  // Custom events
  await AppstackPlugin.sendEvent(
    EventType.custom,
    eventName: 'user_attributes',
    parameters: {
      'email': 'test@example.com',
      'name': 'John Doe',
      'phone_number': '+33060000000',
      'date_of_birth': '2026-02-01',
    },
  );
  ```

  **EventType values (recommended standard events):**

  * Authentication: `EventType.login`, `EventType.signUp`, `EventType.register`
  * Monetization: `EventType.purchase`, `EventType.addToWishlist`, `EventType.initiateCheckout`, `EventType.startTrial`, `EventType.subscribe`
  * Games: `EventType.levelStart`, `EventType.levelComplete`
  * Engagement: `EventType.tutorialComplete`, `EventType.search`, `EventType.share`
  * Custom: `EventType.custom`

  **Enhanced app campaigns**

  * For revenue events, send:
    * `revenue` or `price` (number)
    * `currency` (e.g. `EUR`, `USD`)
  * To improve Meta matching, include when possible:
    * `email`
    * `name` (first + last name)
    * `phone_number`
    * `date_of_birth` (`YYYY-MM-DD`)
</Prompt>

## **Appstack ID and attribution params**

After `configure`, you can read the Appstack user ID and the attribution map for partner integrations (for example Superwall, RevenueCat).

```dart theme={null}
final String? appstackId = await AppstackPlugin.getAppstackId();
final Map<String, dynamic> attributionParams =
    await AppstackPlugin.getAttributionParams() ?? {};
```

* **`getAppstackId()`** — Appstack user identifier when a partner expects `$appstackId` or similar.
* **`getAttributionParams()`** — Attribution payload (campaign, media source, click IDs, device identifiers where available) to forward to partners.

## **pub.dev** **repository**

Here, you will find the [pub.dev appstack\_plugin documentation](https://pub.dev/packages/appstack_plugin). Please use the latest available version of the SDK.

## **Requirements**

### **iOS**

* **iOS version:** 13.0+ (14.3+ recommended for Apple Ads).
* **Xcode:** 14.0+

### **Android**

* **Minimum SDK:** Android 5.0 (API level 21).
* **Target SDK:** 34+

### **General**

* **Flutter:** 3.3.0+
* **Dart:** 2.18.0+

## **Initial setup**

<Steps>
  <Step title="Installation">
    From your project root:

    ```text theme={null}
    flutter pub add appstack_plugin
    flutter pub get
    ```

    Or add `appstack_plugin` under `dependencies` in `pubspec.yaml` using the **current** version from [pub.dev](https://pub.dev/packages/appstack_plugin), then run `flutter pub get`.

    **iOS Configuration**

    Run pod install:

    ```text theme={null}
    cd ios && pod install
    ```

    **Note:** The iOS AppstackSDK.xcframework is bundled with the plugin; no additional dependencies are needed.

    **Android Configuration**

    Add the repository to your `android/build.gradle`:

    ```dart theme={null}
    allprojects {
        repositories {
            google()
            mavenCentral()
            maven { url 'https://jitpack.io' }
        }
    }
    ```

    No additional configuration is needed for Android; the SDK will work automatically after installation.
  </Step>

  <Step title="Initialization">
    Follow these steps to get the API key:

    1. In Appstack, from the side menu, select **SDK** and ensure you are selecting the correct application.
    2. Select the **Production** environment.
    3. Copy the **API key**.

    Examples:

    ```dart theme={null}
    import 'package:flutter/material.dart';
    import 'package:appstack_plugin/appstack_plugin.dart';
    import 'dart:io' show Platform;

    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      
      // Configure the SDK
      final apiKey = Platform.isIOS 
          ? 'your-ios-api-key' 
          : 'your-android-api-key';
      
      await AppstackPlugin.configure(apiKey);
      
      // Enable Apple Ads attribution on iOS
      if (Platform.isIOS) {
        await AppstackPlugin.enableAppleAdsAttribution();
      }
      
      runApp(MyApp());
    }

    class MyApp extends StatelessWidget {
      void trackPurchase() {
        AppstackPlugin.sendEvent(
          EventType.purchase, 
          parameters: {'revenue': 29.99, 'currency': 'USD'}
        );
      }

      @override
      Widget build(BuildContext context) {
        // ... your app
      }
    }
    ```
  </Step>

  <Step title="Configuration parameters" stepNumber={3}>
    Initializes the SDK with your API key. Must be called before any other SDK methods.

    **Parameters:**

    * `apiKey` Your platform-specific API key from the Appstack dashboard.
    * `isDebug` Optional debug mode flag (default: false).
    * `endpointBaseUrl` Optional custom endpoint.
    * `logLevel` Optional log level: 0=DEBUG, 1=INFO, 2=WARN, 3=ERROR (default: 1).

    Returns: A future that resolves to `true` if configuration was successful.

    **Example:**

    ```dart theme={null}
    final success = await AppstackPlugin.configure('your-api-key-here');
    if (!success) {
      print('SDK configuration failed');
    }

    // With all parameters
    await AppstackPlugin.configure(
      'your-api-key-here',
      isDebug: true,
      logLevel: 0, // DEBUG
    );
    ```
  </Step>

  <Step title="Sending events" stepNumber={4}>
    Track user actions and revenue in your activities:

    ```dart theme={null}
    // Track events without parameters
    await AppstackPlugin.sendEvent(EventType.signUp);
    await AppstackPlugin.sendEvent(EventType.levelComplete);

    // Track events with parameters (including revenue)
    await AppstackPlugin.sendEvent(
      EventType.purchase, 
      parameters: {'revenue': 29.99, 'currency': 'USD'}
    );
    await AppstackPlugin.sendEvent(
      EventType.subscribe, 
      parameters: {'revenue': 9.99, 'plan': 'monthly'}
    );

    // Custom events
    await AppstackPlugin.sendEvent(
      EventType.custom,
      eventName: 'user_attributes',
      parameters: {
        'email': 'test@example.com',
        'name': 'John Doe',
        'phone_number': '+33060000000',
        'date_of_birth': '2026-02-01',
      },
    );
    ```

    **Available EventType values**

    It is recommended to use standard events for a smoother experience.

    <Note>
      `EventType.install` is tracked automatically on SDK initialization. Do not send it manually.
    </Note>

    * `EventType.login`/ `EventType.signUp`/ `EventType.register` Authentication
    * `EventType.purchase`/ `EventType.addToWishlist`/ `EventType.initiateCheckout`, `EventType.startTrial`/ `EventType.subscribe` Monetization
    * `EventType.levelStart`/ `EventType.levelComplete` Game progression
    * `EventType.tutorialComplete`/ `EventType.search`/ `EventType.share` Engagement
    * `EventType.custom` For application-specific events

    Tracks custom events with optional parameters:

    * `eventType` - Event type from the EventType enum (required).
    * `eventName` - Event name for custom events (optional, required when eventType is custom).
    * `parameters` - Optional map of parameters (e.g., `{'revenue': 29.99, 'currency': 'USD'}`).

    Returns: A future that resolves to `true` if event was sent successfully.

    **Enhanced app campaigns**

    <Tip>
      When running enhanced app campaigns (EACs), it is highly recommended to send multiple parameters with the in-app event to improve matching quality.
    </Tip>

    For any event that represents revenue, we recommend sending:

    1. `revenue` or `price` (number).
    2. `currency`(string, e.g. `EUR`, `USD`).

    ```dart theme={null}
    await AppstackPlugin.sendEvent(
      EventType.purchase,
      parameters: {'revenue': 4.99, 'currency': 'EUR'},
    );
    ```

    To improve matching quality on Meta, send events including the following parameters if you can fulfill them:

    1. `email`.
    2. `name` (first + last name in the same field).
    3. `phone_number`.
    4. `date_of_birth` (recommended format: `YYYY-MM-DD`).
  </Step>
</Steps>

## **Advanced usage**

### **Environment-based configuration**

Set up different API keys for different environments:

```dart theme={null}
// Use environment variables or configuration
final apiKey = Platform.isIOS 
    ? const String.fromEnvironment('APPSTACK_IOS_API_KEY')
    : const String.fromEnvironment('APPSTACK_ANDROID_API_KEY');

await AppstackPlugin.configure(apiKey);
```

## **Platform-specific considerations**

### **iOS**

**Apple Ads attribution:**

* Only works on iOS 14.3+
* Requires app installation from App Store or TestFlight.
* Attribution data appears within 24-48 hours.
* User consent may be required for detailed attribution (iOS 14.5+).

```text theme={null}
if (Platform.isIOS) {
  await AppstackPlugin.enableAppleAdsAttribution();
}
```

### **Android**

**Play Store Attribution**

* Install referrer data collected automatically.
* Attribution available immediately for Play Store installs.
* Works with Android 5.0+ (API level 21).

### **Cross-platform best practices**

```dart theme={null}
Future<void> initializeSDK() async {
  final apiKey = Platform.isIOS 
      ? 'your-ios-api-key' 
      : 'your-android-api-key';

  final configured = await AppstackPlugin.configure(apiKey);
  
  if (configured && Platform.isIOS) {
    await AppstackPlugin.enableAppleAdsAttribution();
  }
```

## **Limitations**

### **Attribution timing**

* **iOS:** Apple Ads attribution data appears within 24-48 hours after install.
* **Android:** Install referrer data available immediately for Play Store installs.
* Attribution only available for apps installed from official stores.

### **Platform constraints**

* **iOS:** Requires iOS 14.3+
* **Android:** Minimum API level 21 (Android 5.0).
* **Flutter:** 3.3.0+
* Some Apple Ads features may not work in development/simulator environments.

### **Event tracking**

* Event names are case-sensitive and standardized.
* For revenue events, always pass a `revenue` (or `price`) and a `currency` parameter.
* The SDK must be initialized before any tracking calls.
* `enableAppleAdsAttribution()` only works on iOS and returns false on Android.
* Network connectivity required for event transmission (events are queued offline).

## **Superwall**

To start using the Superwall integration, [click here](/Integrations/superwall) to see the correct SDK documentation.

## **Apple Ads**

To start using the Apple Ads integration, [click here](/Integrations/apple-ads) to see the correct SDK documentation.

## **Support**

For questions or issues:

1. Check the [GitHub Repository](https://github.com/appstack-tech/appstack-flutter-sdk).
2. Contact our support team at [support@appstack.tech](mailto:support@appstack.tech)
3. Open an issue in the repository.

<Prompt description="Use Cursor, Claude Code, or another AI to validate your existing Appstack Flutter plugin integration." actions={["copy", "cursor"]}>
  You are an expert Flutter engineer reviewing my existing Appstack Flutter plugin integration. You are running inside an IDE assistant such as Cursor or Claude Code and you can see my Dart and platform-specific code.

  Your goal is to **validate that my integration fully matches the official Flutter SDK documentation** and identify any missing or incorrect steps. When I paste this prompt and share my project files, you should:

  1. **Dependencies & environment**
     * Inspect my `pubspec.yaml` and lockfile to confirm:
       * The `appstack_plugin` dependency is present at a **current** version (check pub.dev rather than assuming a fixed constraint).
       * My environment meets the requirements (Flutter 3.3.0+, Dart 2.18.0+, iOS 13.0+ / 14.3+ for Apple Ads, Android min SDK 21, target SDK 34+).
     * Suggest exact `flutter pub` commands and any version adjustments needed if something is out of spec.

  2. **iOS configuration (Pods)**
     * Check that:
       * `cd ios && pod install` has been run and the plugin is integrated.

  3. **Android configuration**
     * Review my Android build files to verify:
       * Repositories include `google()` and `mavenCentral()` (and `jitpack.io` if required).
       * Min/target SDK and other settings match the documented requirements.
     * Note that the plugin should not require extra Android setup beyond repository configuration, but flag any obvious misconfigurations that could break the SDK.

  4. **SDK initialization (Dart)**
     * Locate where I call `AppstackPlugin.configure(...)` and verify:
       * It is called before any events (typically in `main()` before `runApp`, or in an explicit initialization layer).
       * Platform-specific API keys are used correctly (e.g. different keys for iOS and Android via `Platform.isIOS` checks or environment variables).
       * Optional parameters (`isDebug`, `logLevel`, `endpointBaseUrl`) are used appropriately for development vs production when present.
     * Propose idiomatic Dart initialization code if my current setup is missing, duplicated, or fragile.

  5. **Event tracking implementation**
     * Find all uses of `AppstackPlugin.sendEvent(...)` and verify:
       * Standard `EventType` values are used where appropriate (e.g. `EventType.purchase`, `EventType.signUp`, `EventType.subscribe`, `EventType.levelComplete`, etc.).
       * Revenue events send `revenue` (or `price`) and `currency` in the `parameters` map.
       * Custom events use `EventType.custom` with a descriptive `eventName` and, for EAC / Meta, rich attributes such as `email`, `name`, `phone_number`, and `date_of_birth`.
     * Highlight missing or inconsistent event usage and suggest concrete `sendEvent` calls that fit my app’s flows.

  6. **Platform-specific behavior & limitations**
     * Validate that my code:
       * Only calls `enableAppleAdsAttribution()` on iOS (guarded by `Platform.isIOS`).
       * Respects documented limitations around attribution timing, official store installs, and simulator behavior.
       * Initializes the SDK before tracking calls and does not reconfigure it on every screen unnecessarily.
     * Flag any code patterns that could conflict with these assumptions.

  7. **Validation report & checklist**
     * Produce a clear summary of:
       * What is correctly implemented and safe to ship.
       * What is missing, misconfigured, or risky, with specific Dart and platform file changes.
</Prompt>
