# Quick-start

### Installation

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

### Flagship Usage

#### Start SDK

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

```groovy
import Flagship

// Step 1 - Start the Flagship sdk with default configuration.
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 start with `Decision Mode` for more details on custom configuration go to [Advanced Configuration](https://docs.abtasty.com/server-side/sdks/ios/swift-reference#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/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#setconsent-method) and his [context](https://docs.abtasty.com/server-side/sdks/ios/swift-reference#updatecontext-method). Go to[ builder methods](https://docs.abtasty.com/server-side/sdks/ios/swift-reference#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#flag-class) to learn more about it.

```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 visitors' flags and read their [values](https://docs.abtasty.com/server-side/sdks/ios/swift-reference#getvalue-method) in step 5.

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

#### Tracking hits

Then sending event tracking will allow 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" %}
📘

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 in charge of sending the *event\_action* event through the function `sendHit`. Go to [tracking](https://docs.abtasty.com/server-side/sdks/ios/swift-reference#hit-tracking) for more information.

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