Skip to content

Commit

Permalink
MOB-9638 - Add handlers for notifying customer app of a newly created…
Browse files Browse the repository at this point in the history
… Anon userid
  • Loading branch information
megha-iterable committed Sep 30, 2024
1 parent 804a3a2 commit 92938d8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.EditText;
import com.iterable.iterableapi.CommerceItem;
import com.iterable.iterableapi.IterableAnonUserHandler;
import com.iterable.iterableapi.IterableApi;
import com.iterable.iterableapi.IterableConfig;
import com.iterable.iterableapi.IterableConstants;
import com.iterable.iterableapi.IterableIdentityResolution;
import com.iterable.iterableapi.testapp.R;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -22,14 +21,14 @@
import java.util.List;
import java.util.Map;

public class AnonTrackingTestActivity extends AppCompatActivity {
public class AnonTrackingTestActivity extends AppCompatActivity implements IterableAnonUserHandler {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

IterableConfig iterableConfig = new IterableConfig.Builder().setEnableAnonTracking(true).build();
IterableConfig iterableConfig = new IterableConfig.Builder().setEnableAnonTracking(true).setIterableAnonUserHandler(this).build();

// clear data for testing
SharedPreferences sharedPref = getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Expand Down Expand Up @@ -137,4 +136,9 @@ public void printAllSharedPreferencesData(Context context) {
Log.d("SharedPref", entry.getKey() + ": " + entry.getValue().toString());
}
}

@Override
public void onAnonUserCreated(String userId) {
Log.d("userId", userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ private void createKnownUser(String criteriaId) {
//track anon session with new user
iterableApi.apiClient.trackAnonSession(getCurrentTime(), userId, userDataJson, updateUserTrack, data -> {
// success handler
if (IterableApi.getInstance().config.iterableAnonUserHandler != null) {
IterableApi.getInstance().config.iterableAnonUserHandler.onAnonUserCreated(userId);
}
IterableApi.getInstance().setAnonUser(userId);
syncEvents();
}, (reason, data) -> handleTrackFailure(data));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.iterable.iterableapi;

public interface IterableAnonUserHandler {
void onAnonUserCreated(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class IterableConfig {
*/
final IterableAuthHandler authHandler;


final IterableAnonUserHandler iterableAnonUserHandler;

/**
* Duration prior to an auth expiration that a new auth token should be requested.
*/
Expand Down Expand Up @@ -124,6 +127,7 @@ private IterableConfig(Builder builder) {
enableEmbeddedMessaging = builder.enableEmbeddedMessaging;
eventThresholdLimit = builder.eventThresholdLimit;
identityResolution = builder.identityResolution;
iterableAnonUserHandler = builder.iterableAnonUserHandler;
}

public static class Builder {
Expand All @@ -146,6 +150,13 @@ public static class Builder {
private boolean enableEmbeddedMessaging = false;
private int eventThresholdLimit = 100;
private IterableIdentityResolution identityResolution = new IterableIdentityResolution();
private IterableAnonUserHandler iterableAnonUserHandler;

@NonNull
public Builder setIterableAnonUserHandler(@NonNull IterableAnonUserHandler iterableAnonUserHandler) {
this.iterableAnonUserHandler = iterableAnonUserHandler;
return this;
}

public Builder() {}

Expand Down

0 comments on commit 92938d8

Please sign in to comment.