# Getting Started

## Sign Up and Create a License Key

To start using ContextSDK, sign up in our [ContextSDK Dashboard](https://dashboard.contextsdk.com/) and create a license key for your app. This key is required to authenticate your integration with ContextDecision or ContextPush.

{% hint style="info" %}
If your app has a different bundle ID or package name for different environments, register each one of them separately, as each environment will have a unique license key that should be used.
{% endhint %}

## SDK Integration

Once you have your license key, integrate ContextSDK into your app. The following sections provide step-by-step instructions for iOS, Android, Flutter, Unity, and React Native.

{% tabs %}
{% tab title="iOS" %}
**Installation**

{% tabs %}
{% tab title="Swift Package Manager (SPM)" %}
Add `https://github.com/context-sdk/context-sdk-releases.git` as a dependency in Xcode Package Dependencies or in your `Package.swift` file:

```swift
dependencies: [
    .package(url: "https://github.com/context-sdk/context-sdk-releases", .upToNextMajor(from: "5.15.0")),
]
```

{% endtab %}

{% tab title="CocoaPods" %}
Add the following dependency to your `Podfile` and run `pod install` :

{% code title="Podfile" %}

```ruby
pod "ContextSDK"
```

{% endcode %}
{% endtab %}

{% tab title="Manually" %}

1. Download the latest version of ContextSDK: [ContextSDK.zip](https://storage.googleapis.com/de73e410-context-sdk-releases/latest/ContextSDK.zip)
2. In Xcode, drag `ContextSDK.xcframework` into the Project Navigator.
3. Open your project settings, navigate to `Frameworks, Libraries, and Embedded Content`, add `ContextSDK.xcframework`, and set it to `Embed & Sign`.

To download a specific version, replace `latest` in the download URL with the desired version number. For example, to download version 5.15.0:

<https://storage.googleapis.com/de73e410-context-sdk-releases/5.15.0/ContextSDK.zip>
{% endtab %}
{% endtabs %}

**SDK Initialization**

{% tabs %}
{% tab title="UIKit" %}

<pre class="language-swift" data-title="AppDelegate.swift" data-overflow="wrap"><code class="lang-swift">import ContextSDK

class AppDelegate: NSObject, UIApplicationDelegate {
    // …
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        // …
<strong>        ContextManager.applicationDidFinishLaunchingWithOptions(launchOptions, licenseKey: "YOUR_LICENSE_KEY")
</strong>        // …
    }
}
</code></pre>

{% endtab %}

{% tab title="SwiftUI" %}

1. Create an `AppDelegate` class if you don't have one yet:

{% code title="AppDelegate.swift" overflow="wrap" %}

```swift
import ContextSDK

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        ContextManager.applicationDidFinishLaunchingWithOptions(launchOptions, licenseKey: "YOUR_LICENSE_KEY")
        return true
    }
}
```

{% endcode %}

2. If you didn't have an `AppDelegate` class yet, add a `UIApplicationDelegateAdaptor` property wrapper to your `App` scene:

{% code title="YourApp.swift" %}

```swift
struct YourApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    // …
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Android" %}
**Installation**

{% hint style="warning" %}
**Note:** Android support is currently in beta. To obtain a license key, contact us at <support@contextsdk.com>
{% endhint %}

{% tabs %}
{% tab title="Kotlin" %}
Add the ContextSDK Maven repository in your project-level `settings.gradle.kts`:

{% code title="settings.gradle.kts" %}

```java
dependencyResolutionManagement {
    repositories {
        // …
        // Add the ContextSDK Maven repo:
        maven {
            url = uri("https://storage.googleapis.com/fc4073e9-contextsdk-maven/")
        }
    }
}
```

{% endcode %}

Add the ContextSDK dependency in your module-level `build.gradle.kts`:

{% code title="build.gradle.kts" %}

```java
dependencies {
    // …
    implementation("com.contextsdk:contextsdk:1.0.0")
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
Add the ContextSDK Maven repository in your project-level `settings.gradle`:

<pre class="language-java" data-title="settings.gradle"><code class="lang-java"><strong>dependencyResolutionManagement {
</strong>    repositories {
        // …
        // Add the ContextSDK maven repo:
        maven {
            url 'https://storage.googleapis.com/fc4073e9-contextsdk-maven/'
        }
    }
}
</code></pre>

Add the ContextSDK dependency in your module-level `build.gradle`:

{% code title="build.gradle" %}

```java
dependencies {
    // …
    implementation 'com.contextsdk:contextsdk:1.0.0'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

**SDK Initialization**

{% tabs %}
{% tab title="Kotlin" %}
In your `Application` subclass, initialize ContextSDK by calling `setup` with your license key:

```kotlin
class MainApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        ContextSDK.setup(this, "YOUR_LICENSE_KEY")
    }
}
```

In your primary `Activity` subclass, or in every `Activity` in your application, allow ContextSDK to attach and detach:

```kotlin
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ContextSDK.attachToActivity(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        ContextSDK.detachFromActivity(this)
    }
}
```

{% endtab %}

{% tab title="Java" %}
In your `Application` subclass, initialize ContextSDK by calling `setup` with your license key:

```java
public class MainApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ContextSDK.Companion.setup(this, "YOUR_LICENSE_KEY", new ContextSDKConfiguration());
    }
}
```

2. In your primary `Activity` subclass, or in every `Activity` in your application, allow ContextSDK to attach and detach:

```java
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ContextSDK.Companion.attachToActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ContextSDK.Companion.detachFromActivity(this);
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
The `Activity` must conform to `LifecycleOwner`, such as `AppCompatActivity`. Standard `Activity` subclasses are not supported.

If ContextSDK is not set up correctly, it will be unable to start or stop collecting accelerometer and gyroscope data.
{% endhint %}
{% endtab %}

{% tab title="Flutter" %}
**Installation**

Add `context_sdk` to your `pubspec.yaml`:

{% code title="pubspec.yaml" %}

```yaml
dependencies:
  context_sdk: ^latest_version
```

{% endcode %}

Ensure your project meets the [minimum-sdk-requirements](https://docs.contextsdk.com/other/minimum-sdk-requirements "mention") target by updating your `ios/Podfile`, e.g.:

{% code title="ios/Podfile" %}

```ruby
platform :ios, "14.0"
```

{% endcode %}

**SDK Initialization**

Add the following code to your app’s launch:

```dart
import 'package:context_sdk/context_sdk.dart';

final _contextSdkPlugin = ContextSdk();

_contextSdkPlugin.setup("YOUR_LICENSE_KEY");
```

{% endtab %}

{% tab title="Unity" %}
**Installation**

1. Download the latest version of ContextSDK: [ContextSDK.zip](https://storage.googleapis.com/de73e410-context-sdk-releases/latest/ContextSDK.zip).
2. In your Unity project, drag `ContextSDK.xcframework` into the `Assets/Plugins/iOS` folder.
3. Add the `ContextSDKBinding.cs` script in the same folder.

To download a specific version, replace `latest` in the download URL with the desired version number. For example, to download version 5.15.0:

<https://storage.googleapis.com/de73e410-context-sdk-releases/5.15.0/ContextSDK.zip>

**SDK Initialization**

Set up the `ContextManager` in the `Start()` method of a `MonoBehaviour` that runs early in your game, before accessing the SDK:

```csharp
using static ContextSDKBinding;

public class InitContextSDK : MonoBehaviour
{
    void Start()
    {
        ContextSDKBinding.SetupWithAPIBackend("YOUR_LICENSE_KEY");
    }
}
```

{% endtab %}

{% tab title="React Native" %}
**Installation**

Install ContextSDK using your preferred package manager:

```sh
npm install react-native-context-sdk@latest
```

or

```sh
yarn add react-native-context-sdk
```

Ensure your project meets the [minimum-sdk-requirements](https://docs.contextsdk.com/other/minimum-sdk-requirements "mention") target by updating your `ios/Podfile`, e.g.:

{% code title="ios/Podfile" %}

```ruby
platform :ios, "14.0"
```

{% endcode %}

**SDK Initialization**

Add the following code to your app’s launch:

```js
import { setup } from "react-native-context-sdk";

void setup("YOUR_LICENSE_KEY");
```

{% endtab %}
{% endtabs %}

## ContextDecision

ContextDecision optimizes conversion funnels by intelligently determining the best moments to present monetization or engagement opportunities. Now that you’ve integrated ContextSDK, to get started with ContextDecision, see [Logging Conversions](https://docs.contextsdk.com/context-decision/logging-conversions).

## ContextPush

ContextPush improves the timing of non-transactional push notifications by leveraging user's real-life context. To begin integrating ContextPush, see [integration](https://docs.contextsdk.com/context-push/integration "mention").
