Skip to content

Commit

Permalink
Merge pull request #182 from Countly/auto-rc-enroll
Browse files Browse the repository at this point in the history
Adding auto enroll to AB flag
  • Loading branch information
ArtursKadikis authored Sep 5, 2023
2 parents 29492f9 + 060baa6 commit b02675e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/ly/count/android/demo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ public boolean filterCrash(String crash) {
})

.enableAutomaticViewTracking()
.setGlobalViewSegmentation(automaticViewSegmentation)
.setAutomaticViewTrackingExclusions(new Class[] { ActivityExampleCustomEvents.class })
// uncomment the line below to enable auto enrolling the user to AB experiments when downloading RC data
//.enrollABOnRCDownload()
.setAutoTrackingUseShortName(true)
.setAutomaticViewSegmentation(automaticViewSegmentation)
.setAutoTrackingExceptions(new Class[] { ActivityExampleCustomEvents.class })


.setPushIntentAddMetadata(true)

Expand Down
7 changes: 6 additions & 1 deletion sdk/src/main/java/ly/count/android/sdk/ConnectionQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public String prepareRemoteConfigRequestLegacy(@Nullable String keysInclude, @Nu
return data;
}

public String prepareRemoteConfigRequest(@Nullable String keysInclude, @Nullable String keysExclude, @NonNull String preparedMetrics) {
public String prepareRemoteConfigRequest(@Nullable String keysInclude, @Nullable String keysExclude, @NonNull String preparedMetrics, boolean autoEnroll) {
String data = prepareCommonRequestData()
+ "&method=rc"
+ "&device_id=" + UtilsNetworking.urlEncodeString(deviceIdProvider_.getDeviceId());
Expand All @@ -723,6 +723,11 @@ public String prepareRemoteConfigRequest(@Nullable String keysInclude, @Nullable
data += "&omit_keys=" + UtilsNetworking.urlEncodeString(keysExclude);
}

// if auto enroll was enabled add oi=1 to the request
if(autoEnroll){
data += "&oi=1";
}

return data;
}

Expand Down
12 changes: 12 additions & 0 deletions sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public class CountlyConfig {

protected boolean enableRemoteConfigAutomaticDownloadTriggers = false;

protected boolean enableAutoEnrollFlag = false;

boolean enableRemoteConfigValueCaching = false;
protected RemoteConfigCallback remoteConfigCallbackLegacy = null;

Expand Down Expand Up @@ -552,6 +554,16 @@ public synchronized CountlyConfig enableRemoteConfigAutomaticTriggers() {
return this;
}

/**
* Calling this would enable automatic enrollment of the user to the available experiments when RC is downloaded.
*
* @return Returns the same config object for convenient linking
*/
public synchronized CountlyConfig enrollABOnRCDownload() {
enableAutoEnrollFlag = true;
return this;
}

/**
* If this option is not enabled then when the device ID is changed without merging, remote config values are cleared
* If this option is enabled then the previous values are not cleared but they are marked as not from the current user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class ModuleRemoteConfig extends ModuleBase {
//if set to true, it will automatically download remote configs on module startup
boolean automaticDownloadTriggersEnabled;

// if set to true we should add 'oi=1' to our RC download call
boolean autoEnrollEnabled;

boolean remoteConfigValuesShouldBeCached = false;

List<RCDownloadCallback> downloadCallbacks = new ArrayList<>(2);
Expand All @@ -39,9 +42,10 @@ public class ModuleRemoteConfig extends ModuleBase {
metricOverride = config.metricOverride;
iRGenerator = config.immediateRequestGenerator;

L.d("[ModuleRemoteConfig] Setting if remote config Automatic triggers enabled, " + config.enableRemoteConfigAutomaticDownloadTriggers + ", caching enabled: " + config.enableRemoteConfigValueCaching);
L.d("[ModuleRemoteConfig] Setting if remote config Automatic triggers enabled, " + config.enableRemoteConfigAutomaticDownloadTriggers + ", caching enabled: " + config.enableRemoteConfigValueCaching + ", auto enroll enabled: " + config.enableAutoEnrollFlag);
automaticDownloadTriggersEnabled = config.enableRemoteConfigAutomaticDownloadTriggers;
remoteConfigValuesShouldBeCached = config.enableRemoteConfigValueCaching;
autoEnrollEnabled = config.enableAutoEnrollFlag;

downloadCallbacks.addAll(config.remoteConfigGlobalCallbackList);

Expand Down Expand Up @@ -88,7 +92,7 @@ void updateRemoteConfigValues(@Nullable final String[] keysOnly, @Nullable final
if (useLegacyAPI) {
requestData = requestQueueProvider.prepareRemoteConfigRequestLegacy(preparedKeys[0], preparedKeys[1], preparedMetrics);
} else {
requestData = requestQueueProvider.prepareRemoteConfigRequest(preparedKeys[0], preparedKeys[1], preparedMetrics);
requestData = requestQueueProvider.prepareRemoteConfigRequest(preparedKeys[0], preparedKeys[1], preparedMetrics, autoEnrollEnabled);
}
L.d("[ModuleRemoteConfig] RemoteConfig requestData:[" + requestData + "]");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface RequestQueueProvider {

String prepareRemoteConfigRequestLegacy(@Nullable String keysInclude, @Nullable String keysExclude, @NonNull String preparedMetrics);

String prepareRemoteConfigRequest(@Nullable String keysInclude, @Nullable String keysExclude, @NonNull String preparedMetrics);
String prepareRemoteConfigRequest(@Nullable String keysInclude, @Nullable String keysExclude, @NonNull String preparedMetrics, boolean autoEnroll);

String prepareEnrollmentParameters(@NonNull String[] keys);

Expand Down

0 comments on commit b02675e

Please sign in to comment.