Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-9638 - Add handlers for notifying customer app of a newly created Anon userid #809

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading