Skip to content

Commit 04bd888

Browse files
HarshRaghavWingifysoftvar
authored andcommitted
feat(sdk): support for passing test key for retrieving variable value used in a particular campaign
1 parent 915a99a commit 04bd888

File tree

5 files changed

+387
-74
lines changed

5 files changed

+387
-74
lines changed

README.md

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
VWO Android SDK
2-
======================================
1+
# VWO Android SDK
2+
33
[![Status](https://travis-ci.org/wingify/vwo-android.svg)](https://travis-ci.org/wingify/vwo-android)
44

55

66
This open source library allows you to A/B Test your Android app.
77

8-
Getting Started
9-
---------------
8+
## Getting Started
9+
1010

1111
1. Download the latest [VWO Android SDK](https://github.com/wingify/vwo-android/releases).
1212
2. Have a look at [integrating SDK article](https://developers.vwo.com/reference/android-introduction)
@@ -23,73 +23,79 @@ Once there, you can add a new Android App, and use the generated app key in the
2323

2424

2525
## Setting up VWO account
26+
2627
* Sign Up for VWO account at https://vwo.com
2728
* Create a new android app from create menu
2829
* Use the app generated app key, while integrating SDK into android app.
2930
* Create and run campaigns.
3031

3132
## How to import in gradle:
32-
In your top level build.gradle file add the following code under repositories.
3333

34-
buildscript {
34+
In your top level `build.gradle` file add the following code under repositories.
35+
36+
```text
37+
buildscript {
38+
...
39+
repositories {
3540
...
36-
repositories {
37-
...
38-
}
3941
}
42+
}
4043
41-
allprojects {
42-
repositories {
43-
...
44-
mavenCentral()
45-
...
46-
}
44+
allprojects {
45+
repositories {
46+
...
47+
mavenCentral()
48+
...
4749
}
50+
}
51+
```
4852

49-
Add dependencies to app/build.gradle file
53+
Add dependencies to `app/build.gradle` file
5054

51-
dependencies {
52-
...
53-
implementation 'com.vwo:mobile:2.8.2@aar'
54-
implementation ('io.socket:socket.io-client:1.0.0') {
55-
// excluding org.json which is provided by Android
56-
exclude group: 'org.json', module: 'json'
57-
}
55+
```java
56+
dependencies {
57+
...
58+
implementation 'com.vwo:mobile:2.9.0@aar'
59+
implementation ('io.socket:socket.io-client:1.0.0') {
60+
// excluding org.json which is provided by Android
61+
exclude group: 'org.json', module: 'json'
62+
}
5863

59-
// Skip this if you are already including support library in your app.
60-
implementation 'com.android.support:support-core-utils:27.1.1'
61-
...
62-
}
64+
// Skip this if you are already including support library in your app.
65+
implementation 'com.android.support:support-core-utils:27.1.1'
66+
...
67+
}
68+
```
6369

6470
Update your project AndroidManifest.xml with following permissions:
6571

66-
```
72+
```xml
6773
<uses-permission android:name="android.permission.INTERNET"/>
6874
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
6975
```
7076

7177
## License
7278

7379
```text
74-
MIT License
75-
76-
Copyright (c) 2018-2022 Wingify Software Pvt. Ltd.
77-
78-
Permission is hereby granted, free of charge, to any person obtaining a copy
79-
of this software and associated documentation files (the "Software"), to deal
80-
in the Software without restriction, including without limitation the rights
81-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
82-
copies of the Software, and to permit persons to whom the Software is
83-
furnished to do so, subject to the following conditions:
84-
85-
The above copyright notice and this permission notice shall be included in all
86-
copies or substantial portions of the Software.
87-
88-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
89-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
90-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
91-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
92-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
93-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
94-
SOFTWARE.
80+
MIT License
81+
82+
Copyright (c) 2018-2022 Wingify Software Pvt. Ltd.
83+
84+
Permission is hereby granted, free of charge, to any person obtaining a copy
85+
of this software and associated documentation files (the "Software"), to deal
86+
in the Software without restriction, including without limitation the rights
87+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88+
copies of the Software, and to permit persons to whom the Software is
89+
furnished to do so, subject to the following conditions:
90+
91+
The above copyright notice and this permission notice shall be included in all
92+
copies or substantial portions of the Software.
93+
94+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
95+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
96+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
97+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
98+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
99+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
100+
SOFTWARE.
95101
```

demo/src/main/java/com/vwo/sampleapp/activities/MainActivity.java

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,65 @@ private void initVWO(String key, final boolean showProgress, @Nullable Map<Strin
262262
}
263263
VWOLog.setLogLevel(VWOLog.ALL);
264264
VWOConfig.Builder vwoConfigBuilder = new VWOConfig.Builder();
265-
// vwoConfigBuilder.disablePreview();
265+
266+
/* use the below line of code to disable preview mode
267+
268+
vwoConfigBuilder.disablePreview();
269+
**/
270+
266271
vwoConfigBuilder.setOptOut(false);
267-
// vwoConfigBuilder.isChinaCDN(false);
268-
vwoConfigBuilder.userID("userId");
269-
if (keys == null) {
270-
keys = new HashMap<>();
271-
}
272-
// keys.put("userType", "free");
273-
vwoConfigBuilder.setCustomVariables(keys);
274-
// if (!TextUtils.isEmpty(Constants.VWOKeys.CUSTOM_DIMENSION_KEY) && !TextUtils.isEmpty(Constants.VWOKeys.CUSTOM_DIMENSION_VALUE)) {
275-
// vwoConfigBuilder.setCustomDimension(Constants.VWOKeys.CUSTOM_DIMENSION_KEY, Constants.VWOKeys.CUSTOM_DIMENSION_VALUE);
276-
// }
277-
278-
// new Handler(Looper.getMainLooper()).postDelayed(() -> {
279-
// HashMap<String, String> args = new HashMap<>();
280-
// args.put("campaignKey", "491");
281-
// args.put("groupId", "10");
282-
// VWO.getCampaign("[email protected]", args);
283-
// }, 4000);
272+
273+
//vwoConfigBuilder.isChinaCDN(false);
274+
275+
/* use the below commented code to set userId
276+
277+
vwoConfigBuilder.userID("userId");
278+
**/
279+
280+
/* use below code to set customVariables
281+
282+
if (keys == null) {
283+
keys = new HashMap<>();
284+
}
285+
keys.put("userType", "free");
286+
vwoConfigBuilder.setCustomVariables(keys);
287+
**/
284288

285289
VWO.with(this, key).config(vwoConfigBuilder.build()).launch(new VWOStatusListener() {
286290
@Override
287291
public void onVWOLoaded() {
288-
HashMap<String, String> args = new HashMap<>();
289-
args.put("test_key", "TestKey");
290-
args.put("groupId", "4");
291-
// Log.d("ReturnCampaignKey",VWO.getCampaign("[email protected]", args)+" ");
292292

293-
Log.d("VariationNameForTestKey", VWO.getVariationNameForTestKey(VWO.getCampaign("[email protected]", args)));
293+
/* use the below commented code to use MEG functionality
294+
295+
HashMap<String, String> args = new HashMap<>();
296+
args.put("test_key", "TestKey");
297+
args.put("groupId", "4");
298+
Log.d("ReturnCampaignKey",VWO.getCampaign("[email protected]", args)+" ");
299+
Log.d("VariationNameForTestKey", VWO.getVariationNameForTestKey(VWO.getCampaign("[email protected]", args)));
300+
**/
301+
302+
/* use the below commented code to get the variationName and perform actions accordingly
303+
304+
String testKey = "Camp test 1";
305+
String variationName = VWO.getVariationNameForTestKey(testKey);
306+
if (variationName != null && variationName == "Control") {
307+
// TODO: code for Control
308+
} else if (variationName != null && variationName == "Variation-1") {
309+
// TODO: code for Variation-1
310+
} else {
311+
// TODO: default case
312+
}
313+
**/
314+
315+
/* use the below code to make visitor part of all campaigns who are using this TestVariable
316+
317+
int testVariable1 = VWO.getIntegerForKey("TestVariable1", 1);
318+
**/
319+
320+
/* use the below code to make visitor part of the specific campaign whose testKey we are using
321+
322+
int testVariable1 = VWO.getIntegerForKey(testKey, "TestVariable1", 1);
323+
**/
294324

295325
if (showProgress) {
296326
progressBar.setVisibility(View.GONE);

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
android.enableD8=true
22

3-
VERSION_NAME=2.9.0
4-
VERSION_CODE=29
3+
VERSION_NAME=2.10.0
4+
VERSION_CODE=30
55
GROUP=com.vwo
66

77
POM_DESCRIPTION=VWO mobile SDK for A/B Testing Android applications

0 commit comments

Comments
 (0)