# Launchdarkly

### Integrate Luciq with Launchdarkly

With the integration, you will be able to monitor and control your feature flags from within Luciq in addition to various automations that can be set up on feature flags.

### SDK Setup

Whenever you use a feature flag in Launchdarkly, make sure to call Luciq’s addFeatureFlag API, explained here. This ensures that any feature flags in any session are correctly counted and monitored from both within Luciq and Launchdarkly.

Example of the code snippet

{% code title="Kotlin" %}

```kotlin
LDClient.init(application, ldConfig, context)

// Boolean flag
val BOOLEAN_FLAG_KEY = "sample-flag"

val featureEnabled = LDClient.get().boolVariation(BOOLEAN_FLAG_KEY, false)
if (featureEnabled) {
    Luciq.addFeatureFlag(LCQFeatureFlag(BOOLEAN_FLAG_KEY))
    // logic to execute if flag enabled
} else {
    Luciq.removeFeatureFlag(BOOLEAN_FLAG_KEY)
}

// Multivariats flag
val STRING_FLAG_KEY = "sample-string-flag"

val stringFlag = LDClient.get().stringVariation(STRING_FLAG_KEY, null)

if (stringFlag != null) {
    Luciq.addFeatureFlag(LCQFeatureFlag(STRING_FLAG_KEY, stringFlag))
} else {
    Luciq.removeFeatureFlag(STRING_FLAG_KEY)
}
```

{% endcode %}

Another approach would be using the following snippet which allows Luciq to listen to all feature flags coming of Launchdarkly’s client. However, this may result in inaccurate data if you are not using the same enabled feature flags in you code.

{% code title="Kotlin" %}

```kotlin
LDClient.init(application, ldConfig, context)
// Get all mobile enabled feature flags
for ((key, value) in LDClient.get().allFlags()) {
    if (value.type == LDValueType.BOOLEAN && value.booleanValue()) {
        Luciq.addFeatureFlag(LCQFeatureFlag(key))
    } else if (value.type == LDValueType.STRING || value.type == LDValueType.NUMBER) {
        Luciq.addFeatureFlag(LCQFeatureFlag(key, value.toString().replace("\"", "")))
    }
}
```

{% endcode %}

## Dashboard Setup

Within the Settings tab, you will find Launchdarkly integration in the list of integrations available.

{% stepper %}
{% step %}
**Add Launchdarkly integration token**

Get your LaunchDarkly integration token and add it.

<figure><img src="/files/gFf6XXKKouqQRMZiOnMP" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Select project and environment**

Select your project and environment that you want to control feature flags in.

<figure><img src="/files/ocKCdEe9vtrk1VJYr8L4" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Test your integration**

At this point, we just need to test your integration so that we're sure everything is working smoothly.

<figure><img src="/files/Go7IvBP2HSaMrBBiZGnl" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Name and finish**

All done! Your integration is now set up, just give your integration a name and you're ready to go.

<figure><img src="/files/nskZT5c94pPrsMzkBV9h" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### Control Feature Flags

After the setup, you can now create rules on a specific feature flag to turn it off whenever it passes a certain threshold of a specific metric.

<figure><img src="/files/VyURMn9C6iBT35alfyxm" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Notes:

* To use the action of Turn off using Launchdarkly, you must add a condition of feature flag names.
* The action of Turn off using launchdarkly sends a value of OFF to Launchdarkly for the specific feature flag that passed the threshold added.
  {% endhint %}

### Get Launchdarkly API token

{% stepper %}
{% step %}
Go to Settings → Authorization page: <https://app.launchdarkly.com/settings/authorization>

From Access Tokens section, click create token.

<figure><img src="/files/nMLCk1D2DcqRDCO7bgwY" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Enter the integration name, make sure to select Writer role, and select API version to 20240415, then Save.

<figure><img src="/files/LTvjRVb2smKGQHKukLn2" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Copy the generated token before leaving the page, to use it in integration step.
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luciq.ai/product-guides-and-integrations/integrations/launchdarkly.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
