Skip to content

Commit 7402e80

Browse files
authored
Merge pull request #247 from Automattic/experimentation_readme_fix
Hide `ExPlat` as implementation detail. Update README.md for experimentation.
2 parents 4656d85 + abf4219 commit 7402e80

5 files changed

Lines changed: 29 additions & 22 deletions

File tree

experimentation/README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,75 @@
22

33
## Introduction
44

5-
This module provides an SDK to communicate with Automattic-internal A/B testing service: ExPlat.
5+
This module provides an SDK for interfacing with the Automattic-internal A/B testing service, ExPlat.
66

7-
## Coordinates
7+
## Including the SDK
8+
9+
To include the ExPlat SDK in your project, add the following dependency to your build configuration:
810

911
```groovy
1012
dependencies {
11-
implementation 'com.automattic.tracks:experimentation:{recent_release}'
13+
implementation 'com.automattic.tracks:experimentation:<recent_release_version_here>'
1214
}
1315
```
1416

1517
## Usage
1618

1719
### Initialization
1820

21+
To begin using the SDK, initialize the `VariationsRepository` with a set of experiments:
22+
1923
```kotlin
2024
val experiments = setOf(
2125
Experiment("experiment_1"),
2226
Experiment("experiment_2")
2327
)
2428

25-
// If injected in a DI container, the repository should be a singleton
29+
// If using a DI container, ensure the repository is scoped as a singleton
2630
val repository: VariationsRepository = VariationsRepository.create(
2731
experiments = experiments
28-
/* see KDoc documentation for detailed description of parameters */
32+
// Refer to KDoc for a detailed description of the other parameters
2933
)
30-
// New variations will be available on the next application session. See KDoc for `VariationsRepository#getVariation`
31-
repository.configure(anonymousId = "currently_logged_in_user_id_or_random_uuid")
34+
35+
// New variations will be reachable during the next application session.
36+
// For more information, check the KDoc for `VariationsRepository#getVariation`
37+
repository.initialize(anonymousId = "currently_logged_in_user_id_or_random_uuid")
3238
```
3339

3440
### Getting variation
3541

42+
Retrieve the specific variation for an experiment as follows:
43+
3644
```kotlin
3745
val variation = repository.getVariation("experiment_1")
3846

3947
when (variation) {
4048
is Control -> {
41-
// continue with control group
49+
// Proceed with the control group behavior
4250
}
4351
is Treatment -> {
4452
println("Treatment group: ${variation.value}")
45-
// apply treatment changes
53+
// Implement the treatment variation
4654
}
4755
}
4856
```
4957

50-
### User logs out
58+
### Handling user logs out
59+
60+
Upon user logout, clear the repository like this:
5161

5262
```kotlin
5363
repository.clear()
5464
```
5565

5666
### Different user logs in
5767

68+
When a different user logs in, re-initialize the repository with the new user's ID:
69+
5870
```kotlin
5971
repository.initialize(anonymousId = "new_user_id")
6072
```
6173

6274
## Testing
63-
The SDK offers `VariantionsRepository` interface, which can be doubled in tests.
75+
76+
The SDK provides a `VariationsRepository` interface for facilitating testing. This interface can be mocked or stubbed as required for unit or integration tests.

experimentation/api/experimentation.api

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
public final class com/automattic/android/experimentation/ExPlat : com/automattic/android/experimentation/VariationsRepository {
2-
public fun clear ()V
3-
public fun getVariation-98D7FEw (Ljava/lang/String;)Lcom/automattic/android/experimentation/domain/Variation;
4-
public fun initialize (Ljava/lang/String;Ljava/lang/String;)V
5-
}
6-
71
public final class com/automattic/android/experimentation/Experiment {
82
public static final synthetic fun box-impl (Ljava/lang/String;)Lcom/automattic/android/experimentation/Experiment;
93
public static fun constructor-impl (Ljava/lang/String;)Ljava/lang/String;
@@ -35,8 +29,8 @@ public abstract interface class com/automattic/android/experimentation/Variation
3529
}
3630

3731
public final class com/automattic/android/experimentation/VariationsRepository$Companion {
38-
public final fun create (Ljava/lang/String;Ljava/util/Set;Lcom/automattic/android/experimentation/ExperimentLogger;ZLjava/io/File;Lokhttp3/OkHttpClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/CoroutineDispatcher;)Lcom/automattic/android/experimentation/ExPlat;
39-
public static synthetic fun create$default (Lcom/automattic/android/experimentation/VariationsRepository$Companion;Ljava/lang/String;Ljava/util/Set;Lcom/automattic/android/experimentation/ExperimentLogger;ZLjava/io/File;Lokhttp3/OkHttpClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/CoroutineDispatcher;ILjava/lang/Object;)Lcom/automattic/android/experimentation/ExPlat;
32+
public final fun create (Ljava/lang/String;Ljava/util/Set;Lcom/automattic/android/experimentation/ExperimentLogger;ZLjava/io/File;Lokhttp3/OkHttpClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/CoroutineDispatcher;)Lcom/automattic/android/experimentation/VariationsRepository;
33+
public static synthetic fun create$default (Lcom/automattic/android/experimentation/VariationsRepository$Companion;Ljava/lang/String;Ljava/util/Set;Lcom/automattic/android/experimentation/ExperimentLogger;ZLjava/io/File;Lokhttp3/OkHttpClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/coroutines/CoroutineDispatcher;ILjava/lang/Object;)Lcom/automattic/android/experimentation/VariationsRepository;
4034
}
4135

4236
public final class com/automattic/android/experimentation/VariationsRepository$DefaultImpls {

experimentation/src/main/java/com/automattic/android/experimentation/ExPlat.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.automattic.android.experimentation.repository.AssignmentsRepository
88
import kotlinx.coroutines.CoroutineScope
99
import kotlinx.coroutines.launch
1010

11-
public class ExPlat internal constructor(
11+
internal class ExPlat internal constructor(
1212
private val platform: String,
1313
experiments: Set<Experiment>,
1414
private val logger: ExperimentLogger,

experimentation/src/main/java/com/automattic/android/experimentation/VariationsRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public interface VariationsRepository {
6767
okhttpClient: OkHttpClient = OkHttpClient(),
6868
coroutineScope: CoroutineScope,
6969
dispatcher: CoroutineDispatcher = Dispatchers.IO,
70-
): ExPlat {
70+
): VariationsRepository {
7171
return ExPlat(
7272
platform = platform,
7373
experiments = experiments,

experimentation/src/test/java/com/automattic/android/experimentation/ExPlatTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ internal class ExPlatTest {
120120
fun `initializing fetches assignments`() = runTest {
121121
enqueueSuccessfulNetworkResponse()
122122

123-
val exPlat = createExPlat()
123+
createExPlat()
124124

125125
assertThat(tempCache.latest).isEqualTo(testAssignment)
126126
}

0 commit comments

Comments
 (0)