Skip to content

Commit

Permalink
Adding ability to set user properties during init
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis committed Aug 5, 2022
1 parent 634f148 commit f85e42e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 22.02.0
* Fixed notification trampoline restrictions in Android 12 using reverse activity trampolining implementation.
* Fixed notification trampoline restrictions in Android 12 using reverse activity trampolining implementation.
* Adding a call to provide user properties during initialization.

## 21.11.2
* Fixed bug that caused crashes when migrating from older versions that don't have a device ID type stored. When migrating from no device ID and no type, SDK will fall back to a generated ID. When migrating from device ID and no type, SDK will set id type to 'DEVELOPER_SUPPLIED' if a custom ID was provided during init. Otherwise the new type will be 'OPEN_UDID'. Adding handling for additional edge cases.
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/ly/count/android/demo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public void onCreate() {
customCrashSegmentation.put("EarBook", "3.5");
customCrashSegmentation.put("AdGiver", "6.5");

//properties that we want to sent at init time
Map<String, Object> customUserProperties = new HashMap<>();
customUserProperties.put("A", 1);

CountlyConfig config = (new CountlyConfig(this, COUNTLY_APP_KEY, COUNTLY_SERVER_URL)).setIdMode(DeviceIdType.OPEN_UDID)//.setDeviceId("67567")
.setLoggingEnabled(true)
.setLogListener(new ModuleLog.LogCallback() {
Expand Down Expand Up @@ -202,7 +206,10 @@ public void callback(String error) {

//.setMetricOverride(metricOverride)

.setEnableAttribution(true);
.setEnableAttribution(true)


.setUserProperties(customUserProperties);

Countly.sharedInstance().init(config);
//Log.i(demoTag, "After calling init. This should return 'true', the value is:" + Countly.sharedInstance().isInitialized());
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/main/java/ly/count/android/sdk/Countly.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ public synchronized Countly init(CountlyConfig config) {
moduleDeviceId = new ModuleDeviceId(this, config);
moduleCrash = new ModuleCrash(this, config);
moduleEvents = new ModuleEvents(this, config);
moduleUserProfile = new ModuleUserProfile(this, config);//this has to be set before the session module so that we can update remote config before sending anything session related
moduleViews = new ModuleViews(this, config);
moduleRatings = new ModuleRatings(this, config);
moduleSessions = new ModuleSessions(this, config);
Expand All @@ -522,14 +523,14 @@ public synchronized Countly init(CountlyConfig config) {
moduleLocation = new ModuleLocation(this, config);
moduleFeedback = new ModuleFeedback(this, config);
moduleAttribution = new ModuleAttribution(this, config);
moduleUserProfile = new ModuleUserProfile(this, config);

modules.clear();
modules.add(moduleRequestQueue);
modules.add(moduleConsent);
modules.add(moduleDeviceId);
modules.add(moduleCrash);
modules.add(moduleEvents);
modules.add(moduleUserProfile);//this has to be set before the session module so that we can update remote config before sending anything session related
modules.add(moduleViews);
modules.add(moduleRatings);
modules.add(moduleSessions);
Expand All @@ -538,7 +539,7 @@ public synchronized Countly init(CountlyConfig config) {
modules.add(moduleLocation);
modules.add(moduleFeedback);
modules.add(moduleAttribution);
modules.add(moduleUserProfile);


if(config.testModuleListener != null) {
modules.add(config.testModuleListener);
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 @@ -35,6 +35,8 @@ public class CountlyConfig {

protected boolean checkForNativeCrashDumps = true;

protected Map<String, Object> providedUserProperties = null;

//used to deliver this object to connection queue
//protected DeviceId deviceIdInstance = null;

Expand Down Expand Up @@ -876,4 +878,14 @@ public synchronized CountlyConfig setIndirectAttribution(Map<String, String> att
iaAttributionValues = attributionValues;
return this;
}

/**
* Used to provide user properties that would be sent as soon as possible
*
* @return Returns the same config object for convenient linking
*/
public synchronized CountlyConfig setUserProperties(Map<String, Object> userProperties) {
providedUserProperties = userProperties;
return this;
}
}
13 changes: 11 additions & 2 deletions sdk/src/main/java/ly/count/android/sdk/ModuleUserProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,24 @@ void setPropertiesInternal(@NonNull Map<String, Object> data) {
}

void saveInternal() {
Countly.sharedInstance().L.w("[ModuleUserProfile] saveInternal");
Countly.sharedInstance().L.d("[ModuleUserProfile] saveInternal");
Countly.userData.save();
}

void clearInternal() {
Countly.sharedInstance().L.w("[ModuleUserProfile] clearInternal");
Countly.sharedInstance().L.d("[ModuleUserProfile] clearInternal");
Countly.userData.clear();
}

@Override
void initFinished(@NonNull final CountlyConfig config) {
if(config.providedUserProperties != null) {
L.i("[ModuleUserProfile] Custom user properties were provided during init [" + config.providedUserProperties.size() + "]");
setPropertiesInternal(config.providedUserProperties);
saveInternal();
}
}

@Override
void halt() {
userProfileInterface = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public void onReceive(Context context, Intent broadcast) {
* @return token string or null if no token is currently available.
*/
private static String getToken(Context context, Countly.CountlyMessagingProvider prov, ModuleLog L) {
//todo this seems to be broken
if (prov == Countly.CountlyMessagingProvider.FCM) {
try {
Object instance = UtilsMessaging.reflectiveCall(FIREBASE_INSTANCEID_CLASS, null, "getInstance", L);
Expand Down

0 comments on commit f85e42e

Please sign in to comment.