# SDK quickstart

Go from a new Aplyna application to a real event in Charts. No store credentials are required for this first integration.

## Before you begin

- An Aplyna account and Admin access to your organization.
- An iOS app using Swift 6 / iOS 16+, or an Android app using API 23+ and JDK 17.
- A place to persist an anonymous installation ID and a consent decision.
- Network access to https://aplyna.com over HTTPS.

## 1. Create your application

1. Sign in and choose the workspace where your app belongs.
2. Open the application selector and choose Add app. Enter the name, platform, category and app identifier.
3. Save. Aplyna opens Apps with the new app selected.
4. Copy the one-time SDK key before dismissing it. Keep it with this application's configuration; never use Apple .p8 credentials in the SDK.

> **Keep the selected app consistent**
> The app that issued your SDK key must also own the flow IDs and dashboard data you use. Changing a workspace classification does not change the application's identity.

## 2. Install your platform SDK

- [Install on iOS](https://aplyna.com/docs/ios): Download the local Swift package and add the Aplyna library to your target.
- [Install on Android](https://aplyna.com/docs/android): Download the source module and add it to your Gradle project.

## 3. Configure and send an event

Create one client for your app integration. Persist the installation ID before initialization and reuse it on every launch. Execute Swift calls from an async context; execute Kotlin network methods on a background thread.

### Swift

```
import Foundation
import Aplyna

// Create once and persist; reuse this ID across app launches.
let defaults = UserDefaults.standard
let installationID = defaults.string(forKey: "aplyna.installationID")
    ?? UUID().uuidString
defaults.set(installationID, forKey: "aplyna.installationID")

let client = AplynaClient(
    baseURL: URL(string: "https://aplyna.com")!,
    apiKey: "YOUR_APP_SDK_KEY",
    installationID: installationID
)

// Run in an async context, after your consent flow permits tracking.
try await client.setConsent(true)
try await client.track(name: "app_opened")
try await client.flush()
```

### Kotlin

```
import com.aplyna.sdk.AplynaClient
import java.util.UUID

val prefs = context.getSharedPreferences("aplyna", 0)
val installationId = prefs.getString("installation_id", null)
    ?: UUID.randomUUID().toString().also {
        prefs.edit().putString("installation_id", it).apply()
    }
val client = AplynaClient(
    baseUrl = "https://aplyna.com",
    apiKey = "YOUR_APP_SDK_KEY",
    installationId = installationId,
    storageDirectory = context.filesDir
)

// After consent; call networking methods off the main thread.
client.setConsent(true)
client.track(name = "app_opened")
client.flush()
```

> **Consent is an application decision**
> Call setConsent(true) only after your application has determined tracking is permitted. SDK consent defaults to false when the client is constructed.

## 4. Verify delivery

1. Confirm flush completes without an error. Track first: an empty queue sends no request.
2. Open Aplyna and select the exact application that issued your SDK key.
3. Open Charts and inspect SDK activity for the time period containing your event.
4. Check the installation count and timestamps. A single installation can send many events.
5. If delivery fails, inspect the HTTP error before repeating the request.

- [Troubleshoot event delivery](https://aplyna.com/docs/troubleshooting): Check scope, consent, event IDs, timestamps and network failures.

## Next steps

- [Instrument your onboarding](https://aplyna.com/docs/existing-onboarding): Register a flow and track visible steps and completion.
- [Learn the event contract](https://aplyna.com/docs/events): Names, IDs, payload limits, retries and deduplication.
