|
2 | 2 |
|
3 | 3 | ## Introduction |
4 | 4 |
|
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. |
6 | 6 |
|
7 | | -## Coordinates |
| 7 | +## Including the SDK |
| 8 | + |
| 9 | +To include the ExPlat SDK in your project, add the following dependency to your build configuration: |
8 | 10 |
|
9 | 11 | ```groovy |
10 | 12 | dependencies { |
11 | | - implementation 'com.automattic.tracks:experimentation:{recent_release}' |
| 13 | + implementation 'com.automattic.tracks:experimentation:<recent_release_version_here>' |
12 | 14 | } |
13 | 15 | ``` |
14 | 16 |
|
15 | 17 | ## Usage |
16 | 18 |
|
17 | 19 | ### Initialization |
18 | 20 |
|
| 21 | +To begin using the SDK, initialize the `VariationsRepository` with a set of experiments: |
| 22 | + |
19 | 23 | ```kotlin |
20 | 24 | val experiments = setOf( |
21 | 25 | Experiment("experiment_1"), |
22 | 26 | Experiment("experiment_2") |
23 | 27 | ) |
24 | 28 |
|
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 |
26 | 30 | val repository: VariationsRepository = VariationsRepository.create( |
27 | 31 | experiments = experiments |
28 | | - /* see KDoc documentation for detailed description of parameters */ |
| 32 | + // Refer to KDoc for a detailed description of the other parameters |
29 | 33 | ) |
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") |
32 | 38 | ``` |
33 | 39 |
|
34 | 40 | ### Getting variation |
35 | 41 |
|
| 42 | +Retrieve the specific variation for an experiment as follows: |
| 43 | + |
36 | 44 | ```kotlin |
37 | 45 | val variation = repository.getVariation("experiment_1") |
38 | 46 |
|
39 | 47 | when (variation) { |
40 | 48 | is Control -> { |
41 | | - // continue with control group |
| 49 | + // Proceed with the control group behavior |
42 | 50 | } |
43 | 51 | is Treatment -> { |
44 | 52 | println("Treatment group: ${variation.value}") |
45 | | - // apply treatment changes |
| 53 | + // Implement the treatment variation |
46 | 54 | } |
47 | 55 | } |
48 | 56 | ``` |
49 | 57 |
|
50 | | -### User logs out |
| 58 | +### Handling user logs out |
| 59 | + |
| 60 | +Upon user logout, clear the repository like this: |
51 | 61 |
|
52 | 62 | ```kotlin |
53 | 63 | repository.clear() |
54 | 64 | ``` |
55 | 65 |
|
56 | 66 | ### Different user logs in |
57 | 67 |
|
| 68 | +When a different user logs in, re-initialize the repository with the new user's ID: |
| 69 | + |
58 | 70 | ```kotlin |
59 | 71 | repository.initialize(anonymousId = "new_user_id") |
60 | 72 | ``` |
61 | 73 |
|
62 | 74 | ## 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. |
0 commit comments