From d7831a0fd6f3bc0b1376ab7f97338528b783c8d1 Mon Sep 17 00:00:00 2001 From: skykelsey Date: Sun, 13 Apr 2014 13:31:32 -0600 Subject: [PATCH] Send Person data with conversation creation, instead of later. This enables surveys to be targeted to person custom data right from the first launch of the app. --- .../apptentive/android/sdk/Apptentive.java | 7 +++---- .../android/sdk/storage/PersonManager.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apptentive-android-sdk/src/com/apptentive/android/sdk/Apptentive.java b/apptentive-android-sdk/src/com/apptentive/android/sdk/Apptentive.java index 6205c4533..24708ebe6 100755 --- a/apptentive-android-sdk/src/com/apptentive/android/sdk/Apptentive.java +++ b/apptentive-android-sdk/src/com/apptentive/android/sdk/Apptentive.java @@ -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); diff --git a/apptentive-android-sdk/src/com/apptentive/android/sdk/storage/PersonManager.java b/apptentive-android-sdk/src/com/apptentive/android/sdk/storage/PersonManager.java index 7277fe142..b4ea72b61 100644 --- a/apptentive-android-sdk/src/com/apptentive/android/sdk/storage/PersonManager.java +++ b/apptentive-android-sdk/src/com/apptentive/android/sdk/storage/PersonManager.java @@ -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);