Skip to content

Commit

Permalink
feat(meg): add support for advanced algo i.e. weights and priority
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabin Niroula authored and softvar committed May 12, 2023
1 parent fb62c88 commit 1f9955b
Show file tree
Hide file tree
Showing 13 changed files with 1,135 additions and 164 deletions.
40 changes: 25 additions & 15 deletions demo/src/main/java/com/vwo/sampleapp/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

import androidx.annotation.CheckResult;
Expand Down Expand Up @@ -289,24 +290,32 @@ private void initVWO(String key, final boolean showProgress, @Nullable Map<Strin
@Override
public void onVWOLoaded() {

/* Use the below code to print the different sdk-init duration after enabling the benchmarking
if (vwoConfigBuilder.isEnableBenchmarking()) {
String initDuration = "Time taken to before api call -> " + TimeTracker.getBeforeApiInitDuration() + " ms." + " \n" +
"Time taken to load URL response -> " + TimeTracker.getApiInitDuration() + " ms." + " \n" +
"Time taken to after api call -> " + TimeTracker.getAfterApiInitDuration() + " ms." + " \n" +
"Time taken to reach callback -> " + TimeTracker.getTotalInitDuration() + " ms." + " \n";
System.out.println("VWODACDN: load success!!! -> ");
/* Use the below code to print the different sdk-init duration after enabling the benchmarking
if (vwoConfigBuilder.isEnableBenchmarking()) {
String initDuration = "Time taken to before api call -> " + TimeTracker.getBeforeApiInitDuration() + " ms." + " \n" +
"Time taken to load URL response -> " + TimeTracker.getApiInitDuration() + " ms." + " \n" +
"Time taken to after api call -> " + TimeTracker.getAfterApiInitDuration() + " ms." + " \n" +
"Time taken to reach callback -> " + TimeTracker.getTotalInitDuration() + " ms." + " \n";
VWOLog.v("LoadTime", initDuration);
VWOLog.v("LoadTime", initDuration);
}
**/

long start = System.nanoTime();
// use the below commented code to use MEG functionality
HashMap<String, String> args = new HashMap<>();
args.put("test_key", "demo_two");
// args.put("groupId", "3");

String c = VWO.getCampaign("mark181@facebook.com", args);
String vnftk = VWO.getVariationNameForTestKey(c);
if (vnftk != null && c != null) {
Log.d("VariationNameForTestKey", "vn: " + vnftk + " c: " + c);
}
**/
long end = System.nanoTime();
Log.d("meg", "onVWOLoaded: time taken ms -> " + TimeUnit.NANOSECONDS.toMillis(end - start));

/* use the below commented code to use MEG functionality
HashMap<String, String> args = new HashMap<>();
args.put("test_key", "TestKey");
args.put("groupId", "4");
Log.d("ReturnCampaignKey",VWO.getCampaign("mark@facebook.com", args)+" ");
Log.d("VariationNameForTestKey", VWO.getVariationNameForTestKey(VWO.getCampaign("mark@facebook.com", args)));
**/

/* use the below commented code to get the variationName and perform actions accordingly
String testKey = "Camp test 1";
Expand Down Expand Up @@ -339,6 +348,7 @@ public void onVWOLoadFailure(String s) {
if (showProgress) {
progressBar.setVisibility(View.GONE);
}
System.out.println("VWODACDN: failed -> " + s);
loadFragments();
}
});
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
android.enableD8=true

VERSION_NAME=2.12.0
VERSION_CODE=32
VERSION_NAME=2.14.0
VERSION_CODE=34
GROUP=com.vwo

POM_DESCRIPTION=VWO mobile SDK for A/B Testing Android applications
Expand Down
243 changes: 143 additions & 100 deletions library/src/debug/java/com/vwo/mobile/v3/MockServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,106 +9,149 @@ public class MockServerResponse {

public static void replaceWithApiV3EuModificationResponse(StringBuilder data) {
if (!BuildConfig.SHOULD_USE_MOCK_DATA_IN_DEBUG) return;
String collectionPrefix = " \"collectionPrefix\": \"eu01\",";
String json = "{" +
" \"api-version\": 3," +
// collectionPrefix +
" \"groups\": {" +
" \"1\": {" +
" \"campaigns\": [" +
" 7," +
" 5" +
" ]," +
" \"name\": \"Group 1\"" +
" }," +
" \"2\": {" +
" \"campaigns\": [" +
" 8," +
" 9" +
" ]," +
" \"name\": \"HimanshuGroup 1\"" +
" }" +
" }," +
" \"campaignGroups\": {" +
" \"7\": 1," +
" \"5\": 1" +
" }," +
" \"campaigns\": [" +
" {" +
" \"name\": \"Campaign 5\"," +
" \"version\": 4," +
" \"type\": \"VISUAL_AB\"," +
" \"goals\": [" +
" {" +
" \"identifier\": \"kjh\"," +
" \"id\": 1," +
" \"type\": \"CUSTOM_GOAL\"" +
" }" +
" ]," +
" \"test_key\": \"k\"," +
" \"count_goal_once\": 1," +
" \"pc_traffic\": 100," +
" \"segment_object\": {" +
" \"segmentSettings\": {}," +
" \"partialSegments\": [" +
" {" +
" \"rOperandValue\": \"jhg\"," +
" \"operator\": 11," +
" \"type\": \"6\"" +
" }," +
" {" +
" \"rOperandValue\": \"jh\"," +
" \"prevLogicalOperator\": \"AND\"," +
" \"operator\": 11," +
" \"type\": \"11\"" +
" }" +
" ]," +
" \"event\": null," +
" \"type\": \"custom\"" +
" }," +
" \"variations\": {" +
" \"changes\": {}," +
" \"name\": \"Control\"," +
" \"id\": \"1\"," +
" \"weight\": 50" +
" }," +
" \"_t\": 1675079440," +
" \"id\": 5," +
" \"status\": \"RUNNING\"," +
" \"track_user_on_launch\": false," +
" \"clickmap\": 1," +
" \"pgre\": true" +
" }," +
" {" +
" \"config_segment_dsl\": {}," +
" \"name\": \"Campaign 7\"," +
" \"version\": 4," +
" \"segment_dsl\": {}," +
" \"goals\": [" +
" {" +
" \"identifier\": \"Goal1\"," +
" \"id\": 1," +
" \"type\": \"CUSTOM_GOAL\"" +
" }" +
" ]," +
" \"test_key\": \"SwapnilCampaign\"," +
" \"count_goal_once\": 1," +
" \"pc_traffic\": 100," +
" \"_t\": 1678861982," +
" \"variations\": {" +
" \"changes\": {}," +
" \"name\": \"Control\"," +
" \"id\": \"1\"," +
" \"weight\": 50" +
" }," +
" \"track_user_on_launch\": true," +
" \"id\": 7," +
" \"status\": \"RUNNING\"," +
" \"pgre\": true," +
" \"clickmap\": 1," +
" \"type\": \"VISUAL_AB\"" +
" }" +
" ]" +
String json = "{\n" +
" \"api-version\": 3,\n" +
" \"campaigns\": [\n" +
" {\n" +
" \"pc_traffic\": 100,\n" +
" \"version\": 4,\n" +
" \"type\": \"VISUAL_AB\",\n" +
" \"_t\": 1682681997,\n" +
" \"status\": \"RUNNING\",\n" +
" \"id\": 31,\n" +
" \"pgre\": true,\n" +
" \"variations\": {\n" +
" \"id\": \"2\",\n" +
" \"changes\": {},\n" +
" \"weight\": 50,\n" +
" \"name\": \"Variation-1\"\n" +
" },\n" +
" \"name\": \"Campaign 31\",\n" +
" \"track_user_on_launch\": false,\n" +
" \"clickmap\": 1,\n" +
" \"test_key\": \"demo_one\",\n" +
" \"goals\": [\n" +
" {\n" +
" \"id\": 1,\n" +
" \"identifier\": \"goal_demo_one\",\n" +
" \"type\": \"CUSTOM_GOAL\"\n" +
" }\n" +
" ],\n" +
" \"count_goal_once\": 1\n" +
" },\n" +
" {\n" +
" \"pc_traffic\": 100,\n" +
" \"version\": 4,\n" +
" \"type\": \"VISUAL_AB\",\n" +
" \"_t\": 1682682025,\n" +
" \"status\": \"RUNNING\",\n" +
" \"id\": 32,\n" +
" \"pgre\": true,\n" +
" \"variations\": {\n" +
" \"id\": \"0\",\n" +
" \"changes\": {},\n" +
" \"weight\": 50,\n" +
" \"name\": \"Control\"\n" +
" },\n" +
" \"name\": \"Campaign 32\",\n" +
" \"track_user_on_launch\": false,\n" +
" \"clickmap\": 1,\n" +
" \"test_key\": \"demo_two\",\n" +
" \"goals\": [\n" +
" {\n" +
" \"id\": 1,\n" +
" \"identifier\": \"goal_two\",\n" +
" \"type\": \"CUSTOM_GOAL\"\n" +
" }\n" +
" ],\n" +
" \"count_goal_once\": 1\n" +
" },\n" +
" {\n" +
" \"pc_traffic\": 100,\n" +
" \"version\": 4,\n" +
" \"type\": \"VISUAL_AB\",\n" +
" \"_t\": 1682682100,\n" +
" \"status\": \"RUNNING\",\n" +
" \"id\": 33,\n" +
" \"pgre\": true,\n" +
" \"variations\": {\n" +
" \"id\": \"1\",\n" +
" \"changes\": {},\n" +
" \"weight\": 50,\n" +
" \"name\": \"Control\"\n" +
" },\n" +
" \"name\": \"Campaign 33\",\n" +
" \"track_user_on_launch\": false,\n" +
" \"clickmap\": 1,\n" +
" \"test_key\": \"demo_three\",\n" +
" \"goals\": [\n" +
" {\n" +
" \"id\": 1,\n" +
" \"identifier\": \"goal_three\",\n" +
" \"type\": \"CUSTOM_GOAL\"\n" +
" }\n" +
" ],\n" +
" \"count_goal_once\": 1\n" +
" }\n" +
" ],\n" +
" \"groups\": {\n" +
" \"1\": {\n" +
" \"et\": 2,\n" +
" \"campaigns\": [\n" +
" 22,\n" +
" 25,\n" +
" 24\n" +
" ],\n" +
" \"p\": [\n" +
" 25,\n" +
" 24\n" +
" ],\n" +
" \"wt\": {\n" +
" \"22\": 50\n" +
" },\n" +
" \"name\": \"Group 1\"\n" +
" },\n" +
" \"2\": {\n" +
" \"campaigns\": [\n" +
" 27,\n" +
" 26,\n" +
" 28\n" +
" ],\n" +
" \"name\": \"Group 2\"\n" +
" },\n" +
" \"3\": {\n" +
" \"et\": 1,\n" +
" \"campaigns\": [\n" +
" 33,\n" +
" 31,\n" +
" 32\n" +
" ],\n" +
" \"p\": [\n" +
" 27,\n" +
" 28,\n" +
" 11,\n" +
" 222,\n" +
" 31,\n" +
" 32\n" +
" ],\n" +
" \"wt\": {\n" +
" \"31\": 30,\n" +
" \"33\": 70\n" +
" },\n" +
" \"name\": \"Group 3\"\n" +
" }\n" +
" },\n" +
" \"campaignGroups\": {\n" +
" \"22\": 1,\n" +
" \"24\": 1,\n" +
" \"25\": 1,\n" +
" \"26\": 2,\n" +
" \"27\": 2,\n" +
" \"28\": 2,\n" +
" \"31\": 3,\n" +
" \"32\": 3,\n" +
" \"33\": 3\n" +
" }\n" +
"}";
data.delete(0, data.length());
data.append(json);
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/vwo/mobile/VWO.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.vwo.mobile.utils.VWOUrlBuilder;
import com.vwo.mobile.utils.VWOUtils;
import com.vwo.mobile.v3.EUManager;
import com.vwo.mobile.v3.MEGManager;
import com.vwo.mobile.meg.MEGManager;
import com.vwo.mobile.v3.MockServerResponse;
import com.vwo.mobile.v3.ServerResponse;

Expand Down
Loading

0 comments on commit 1f9955b

Please sign in to comment.