Skip to content

Commit

Permalink
Send Person data with conversation creation, instead of later. This e…
Browse files Browse the repository at this point in the history
…nables surveys to be targeted to person custom data right from the first launch of the app.
  • Loading branch information
skykelsey committed Apr 13, 2014
1 parent 139e172 commit d7831a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,9 @@ private static void fetchConversationToken(Context context) {
ConversationTokenRequest request = new ConversationTokenRequest();

// Send the Device and Sdk now, so they are available on the server from the start.
Device device = DeviceManager.storeDeviceAndReturnIt(context);
request.setDevice(device);
Sdk sdk = SdkManager.storeSdkAndReturnIt(context);
request.setSdk(sdk);
request.setDevice(DeviceManager.storeDeviceAndReturnIt(context));
request.setSdk(SdkManager.storeSdkAndReturnIt(context));
request.setPerson(PersonManager.storePersonAndReturnIt(context));

// TODO: Allow host app to send a user id, if available.
ApptentiveHttpResponse response = ApptentiveClient.getConversationToken(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ public static Person storePersonAndReturnDiff(Context context) {
return null;
}

/**
* Provided so we can be sure that the person we send during conversation creation is 100% accurate. Since we do not
* queue this person up in the payload queue, it could otherwise be lost.
*/
public static Person storePersonAndReturnIt(Context context) {
Person current = generateCurrentPerson();

CustomData customData = loadCustomPersonData(context);
current.setCustomData(customData);

String email = loadPersonEmail(context);
if (email == null) {
email = loadInitialPersonEmail(context);
}
current.setEmail(email);

storePerson(context, current);
return current;
}

public static CustomData loadCustomPersonData(Context context) {
SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
String personDataString = prefs.getString(Constants.PREF_KEY_PERSON_DATA, null);
Expand Down

0 comments on commit d7831a0

Please sign in to comment.