> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kleep.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Mobile SDK - Android

**Repository:** [https://github.com/KlipFit/kleep-android](https://github.com/KlipFit/kleep-android)

## Installatie

***

Dit proces hoeft slechts één keer te worden doorlopen, de eerste keer dat u de SDK in uw project installeert. Raadpleeg de sectie **Update** voor de instructies bij volgende updates.

1. Voeg in uw *gradle.properties* dit token toe:

   `authToken=jp_9ibcequhrjtge3cmavt2k4sq6a`

2. Voeg in uw *settings.gradle of settings.gradle.kts* de volgende regels toe:

```groovy theme={null}
// for *settings.gradle*

dependencyResolutionManagement {
*// ...*
    repositories {
        *// ...*
~~~~        maven {
            url "https://jitpack.io"
            credentials { username authToken }
        }
    }
}
```

```kotlin theme={null}
// for *settings.gradle.kts*

*dependencyResolutionManagement {
// ...
    repositories {
	      // ... 
        maven {
            url = uri("https://jitpack.io")
            credentials(PasswordCredentials::class) {
                val authToken: String by settings
                username = authToken*
            }
        *}
    }
}*
```

1. Voeg in het bestand *build.gradle* of *build.gradle.kts* van uw module de volgende regels toe om de afhankelijkheid te maken:

```groovy theme={null}
// *build.gradle*
dependencies {
	implementation 'com.github.KlipFit:kleep-android:version'
}
```

```kotlin theme={null}
// *build.gradle.kts*
dependencies {
	implementation("com.github.KlipFit:kleep-android:version")
}
```

## **Initialisatie**

***

Bewerk uw aangepaste klasse `Application` en geef `applicationContext` op voor initialisatie.

```kotlin theme={null}
import com.kleep.sdk.KleepResult
import com.kleep.sdk.Kleep

class CustomApplication: Application() {

    override fun onCreate() {
        super.onCreate()
        Kleep.init(applicationContext)
    }
}
```

Vergeet niet uw Application-klasse toe te voegen aan **`Manifest.xml`**

```kotlin theme={null}
<application
        android:name=".CustomApplication"
        ...
        >
...
</application>
```

## Import

***

U kunt de module handmatig importeren aan het begin van uw **`MainActivity.kt`**

```kotlin theme={null}
import com.kleep.sdk.KleepResult
import com.kleep.sdk.Kleep
```

## Gebruik

***

De SDK wordt geleverd met 3 methoden:

| methode                   | laadtijd            |
| ------------------------- | ------------------- |
| `show`                    | Eerste start: 250ms |
| Volgende starts: 50-250ms |                     |
| `requestSize`             | 250ms               |
| `track`                   | 250ms               |

### Methode 1: `requestSize`

Deze methode maakt het mogelijk om de logica van de CTA te implementeren.

**Logisch schema**

Dit schema legt uit hoe de CTA die Kleep opent bijgewerkt moet worden.

[https://www.figma.com/board/BlurZ01lR3JBQZeTUU98TE/Mobile---CTA-Logic?node-id=0-1\&t=ccXWciNziIdfhgew-1](https://www.figma.com/board/BlurZ01lR3JBQZeTUU98TE/Mobile---CTA-Logic?node-id=0-1\&t=ccXWciNziIdfhgew-1)

**Implementatievoorbeeld**

```kotlin theme={null}
Kleep.builder(this, onResult = {
	when (it) {
	    is KleepResult.NotSupported -> {
	        // Handle the NotSupported case
	    }
	
	    is KleepResult.NoRecommendationYet -> {
	        // Handle the NoRecommendationYet case
	    }
	
	    is KleepResult.RecommendationFound -> {
	        val resultText = it.size
	        val variantId = it.variantId
	        Toast.makeText(this, resultText, Toast.LENGTH_SHORT).show()         
      }

      else -> {

      }
    }
})
	.setPackageName(packageName)         // optional
	.setLang(DEFAULT_LANGUAGE)           // required: "fr", "en", "es", "it", "pt", "nl"
	.setProductId("1234")                // required
	.setRetailer("retailer_name")        // required
	.setTrackingId("uuid")               // empty if non-existent 
	.setCustomerId("unique_customer_id") // optional
	.requestSize()
```

```kotlin theme={null}
package com.kleep.sdk

/**
 * Interface with the Kleep SDK in order to compute the recommended size of a product given some user information
 */
interface KleepDialogBuilder {
    /**
     * Set the package name, not required
     * @return interface of the SDK builder
     */
    fun setPackageName(packageName: String): KleepDialogBuilder
    
    /**
     * Set the language to use: required (default to FR)
     * Values supported: "fr", "en", "es", "it", "pt", "nl"
     * @return interface of the SDK builder
     */
    fun setLang(lang: String): KleepDialogBuilder

    /**
     * Set product ID, required to compute the recommended size.
     * @return interface of the SDK builder
     */
    fun setProductId(productId: String): KleepDialogBuilder

    /**
     * Set tracking id, required. Should represent unique tracking id.
     * Should be an empty string if the tracking id does not exist.
     *
     * @return interface of the SDK builder
     */
    fun setTrackingId(tracking_id: String): KleepDialogBuilder

    /**
     * Set customer id, optonal. Should represent customer id linked to backend.
     * Should be an empty string if the tracking id does not exist.
     *
     * @return interface of the SDK builder
     */
    fun setCustomerId(customer_id: String): KleepDialogBuilder
    
    /**
     * Set retail name (mandatory), required for stock/similar_products requests.
     *
     * @return interface of the SDK builder
     */
    fun setRetailer(retailerName: String): KleepDialogBuilder
    
    /**
     * Sets the stock availability for items.
     * Providing an empty map or omitting this function disables stock checking.
     *
     * @return interface of the SDK builder
     */
    fun setStocks(stocks: Map<String, Boolean>): KleepDialogBuilder

    /**
     * Display the Kleep UI inside a BottomSheet, so the user can fill a survey or take 2 pictures
     * in order to compute and display the recommended size to the user
     */
    fun show()

    /**
     * Get the latest recommended size for the last viewed user.
     * As it's an async process and take several seconds,
		 * the result will be give by the onResult listener , provided to the SDK builder
     */
    fun requestSize()
}
```

### Methode 2: `show`

Deze methode wordt aangeroepen wanneer op de CTA wordt geklikt. Hiermee kunnen de verschillende schermen worden geladen. **De ontwikkelaar die de SDK integreert, moet ze in een bottom sheet insluiten.**

| parameter                                                                                                                    | prioriteit  | beschrijving                                                    |
| ---------------------------------------------------------------------------------------------------------------------------- | ----------- | --------------------------------------------------------------- |
| **productID**                                                                                                                | *verplicht* | Uw product-ID                                                   |
| **retailer**                                                                                                                 | *verplicht* | Naam van de retailer                                            |
| **customerID**                                                                                                               | *optioneel* | CRM-identificator, gebruikt voor analyse                        |
| **trackingID**                                                                                                               | *optioneel* | ID gebruikt door externe trackingprovider                       |
| stocks                                                                                                                       | *optioneel* | Een map van variant-ID's van artikelen naar hun voorraadstatus. |
| `true` voor op voorraad, `false` (standaard) voor niet op voorraad, emptyMap of niet opgegeven om de controle over te slaan. |             |                                                                 |

```kotlin theme={null}
Kleep.builder(this, onResult = {
	when (it) {
	    is KleepResult.NotSupported -> {
	        // Handle the NotSupported case
	    }
	
	    is KleepResult.NoRecommendationYet -> {
	        // Handle the NoRecommendationYet casem
	    }
	
	    is KleepResult.RecommendationFound -> {
	        val resultText = it.size
	        val variantId = it.variantId
	        // addToCart(variantId)
	        
	        Toast.makeText(this, resultText, Toast.LENGTH_SHORT).show()
      }

      else -> {

      }
    }
})
	.setPackageName(packageName)         // optional
	.setLang(DEFAULT_LANGUAGE)           // required: "fr", "en", "es", "it", "pt", "nl"
	.setProductId("1234")                // required
	.setRetailer("retailer_name")        // required
	.setTrackingId("tracking_id")        // optional
	.setCustomerId("unique_customer_id") // optional
	.setStocks(stocks: Map<String, Boolean>) // optional
	.show()
```

### Methode 3: `track`

Deze methode maakt het mogelijk om aangepaste gebeurtenissen bij te houden.

```kotlin theme={null}
Kleep.track(eventName: String, eventInfo: Map<String, String>)
```

We willen 3 gebeurtenissen bijhouden:

| eventName               | Trigger                                                 |
| ----------------------- | ------------------------------------------------------- |
| `product_viewed`        | Wanneer de PDP wordt bekeken                            |
| `product_added_to_cart` | Wanneer een product aan de winkelwagen wordt toegevoegd |
| `checkout_completed`    | Bij orderbevestiging na de betaling                     |

**`product_viewed`**

[Parameters (CSV)](/images/android/Untitled%202c68bfd3e84981db82a9f924cf43673d.csv)

**Voorbeeld**

```jsx theme={null}
{
		productId: str
}
```

**`product_added_to_cart`**

[Parameters (CSV)](/images/android/Untitled%202c68bfd3e8498100baf9d17e8b7df5e0.csv)

**Voorbeeld**

```jsx theme={null}
{
    productId: str,
    variantId: str,
    cart: [
	    {
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
				sku: "XYZ",
		    size: "S",
		    quantity: 2,
		    price: {
						amount: "50",
				    currencyCode: "EUR"		    
		    }
	    },
	    {
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
		    sku: "XYZ",
		    size: "S",
		    quantity: 1,
		    price: {
				    amount: "40",
				    currencyCode: "USD"
				}
	    }
	    ...
    ],
}
```

**`checkout_completed`**

[Parameters (CSV)](/images/android/Untitled%202c68bfd3e84981b0bdecd417ba621e4e.csv)

**Voorbeeld**

```jsx theme={null}
{
    orderId: "000001",
    cart: [
	    {
		    lineItemId: "000001#1",
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
				sku: "XYZ",
		    size: "S",
		    quantity: 2,
		    price: {
						amount: "50",
				    currencyCode: "EUR"		    
		    }
	    },
	    {
			  lineItemId: "000000#2",
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
		    sku: "XYZ",
		    size: "S",
		    quantity: 1,
		    price: {
				    amount: "40",
				    currencyCode: "USD"
				}
	    }
	    ...
    ],
}
```
