# Quick-start

### Installation

You will find all instructions in [installation](https://docs.abtasty.com/server-side/sdks/ios/ios/swift-installation-beta) topic

### Flagship Usage

#### Start SDK

The first call you should make is to start the SDK by calling `start` the method through the Flagship singleton.

```groovy
import Flagship

// Step 1 - Start the Flagship sdk with default configuration.

Task {
      try await Flagship.sharedInstance.start(envId: "_ENV_ID_", apiKey: "_API_KEY_")
    }
        
```

In *step 1*, the SDK needs to start the `environmentId` and `apiKey`. By default the flagship starts with `Decision Mode` For more details on custom configuration, go to Advanced Configuration.

{% hint style="info" %}
📘 API Key & Environment ID required

*You can find your apiKey and your environmentId on your Flagship account, in Parameters > Environment & Security.*
{% endhint %}

#### Create Visitor

The second step after starting the SDK is [visitor](https://docs.abtasty.com/server-side/sdks/ios-1/swift-reference#visitor-class) creation. This object allows you to manage visitor's context, experiments, and track events.

```groovy
// Step 2 - Create visitor with context "isVip" : true
let visitor = Flagship.sharedInstance.newVisitor(visitorId: "visitorId", hasConsented: true).withContext(context: ["isVip": true]).build()

```

In *Step 2* We create a visitor providing his [consent](https://docs.abtasty.com/server-side/sdks/ios/swift-reference-beta#setconsent-method) and his [context](#create-visitor). Go to[ builder methods](https://docs.abtasty.com/server-side/sdks/ios/swift-reference-beta#visitor-builder-methods) to learn more about visitor creation.

#### Getting flags

Once we have created our visitor instance, we need to fetch flags. Go to [Flag](https://docs.abtasty.com/server-side/sdks/ios/swift-reference-beta#flag-class) to learn more about.

```groovy
// Step 3 - Fetch flags
visitor.fetchFlags {
  
    // Fetch completed
  
    // Step 4 - Get Flag key
    let flag = visitor.getFlag(key: "flagKey")
      
    // Step 5 - Read Flag value
    let value = flag.value(defaultValue: "defaultValue")
}
```

When flag fetching completes in step 3 its inner code block is executed. In step 4, we are ready to process visitor's flags and read their [values](https://docs.abtasty.com/server-side/sdks/ios/swift-reference-beta#getvalue-method) in step 5.

Note: SDK will [report exposition](https://docs.abtasty.com/server-side/sdks/ios/swift-reference-beta#visitorexposed-method) by default when reading a Flag value.

#### Tracking hits

Then sending events tracking will allows you to validate objectives in your campaign reporting.

```groovy
// Step 6 - Send Event
visitor.sendHit(FSEvent(eventCategory: .Action_Tracking, eventAction: "event_action"))
```

{% hint style="info" %}
📘 Information

In order to see your events in your campaign reporting you must define objectives kpis beforehand in the campaign configuration.
{% endhint %}

In *step 6* Flagship is on charge of sending the *event\_action* event through the function `sendHit`. Go to [tracking](https://docs.abtasty.com/server-side/sdks/ios/swift-reference-beta#hit-tracking) for more information.

You should see your hit using [hitStream](https://app.gitbook.com/s/PLcJUpntQruhbI1jQ2kr/reporting/verifying-your-hit-setup) feature, then on your campaign [report](https://app.gitbook.com/s/PLcJUpntQruhbI1jQ2kr/reporting).

#### Emotion AI

If you want to collect users's interactions of your application, just call the `collectEmotionsAIEvents` function, make sure you call this function

* After starting and creating the visitor instance
* If your application starts with a splashScreen make sure to avoid this screen
