Update analytics api, report acqusition

pull/14/head
Sam Bosley 13 years ago
parent 3956b340d3
commit 4581501063

@ -42,6 +42,7 @@ import com.todoroo.astrid.opencrx.OpencrxCoreUtils;
import com.todoroo.astrid.producteev.ProducteevUtilities; import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.reminders.ReminderStartupReceiver; import com.todoroo.astrid.reminders.ReminderStartupReceiver;
import com.todoroo.astrid.service.abtesting.ABChooser; import com.todoroo.astrid.service.abtesting.ABChooser;
import com.todoroo.astrid.service.abtesting.ABTestInvoker;
import com.todoroo.astrid.utility.AstridPreferences; import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.widget.TasksWidget.WidgetUpdateService; import com.todoroo.astrid.widget.TasksWidget.WidgetUpdateService;
@ -85,6 +86,8 @@ public class StartupService {
@Autowired ABChooser abChooser; @Autowired ABChooser abChooser;
@Autowired ABTestInvoker abTestInvoker;
/** /**
* bit to prevent multiple initializations * bit to prevent multiple initializations
*/ */
@ -177,6 +180,8 @@ public class StartupService {
// For any uninitialized ab test, make sure an option is chosen // For any uninitialized ab test, make sure an option is chosen
abChooser.makeChoicesForAllTests(latestSetVersion == 0, taskService.getUserActivationStatus()); abChooser.makeChoicesForAllTests(latestSetVersion == 0, taskService.getUserActivationStatus());
abTestInvoker.reportAcquisition();
// perform startup activities in a background thread // perform startup activities in a background thread
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {

@ -18,6 +18,8 @@ import org.json.JSONObject;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.RestClient; import com.todoroo.andlib.service.RestClient;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.service.StatisticsService;
/** /**
* Invoker for communicating with the Astrid Analytics server * Invoker for communicating with the Astrid Analytics server
@ -28,16 +30,37 @@ import com.todoroo.andlib.service.RestClient;
public class ABTestInvoker { public class ABTestInvoker {
/** NOTE: these values are development values and will not work on production */ /** NOTE: these values are development values and will not work on production */
private static final String URL = "http://analytics.astrid.com/api/1/retention"; private static final String URL = "http://analytics.astrid.com/api/2/ab_retention";
private static final String ACQ_URL = "http://analytics.astrid.com/api/2/aquisition";
private static final String API_KEY = "ryyubd"; private static final String API_KEY = "ryyubd";
private static final String API_SECRET = "q9ef3i"; private static final String API_SECRET = "q9ef3i";
private static final String PREF_REPORTED_ACQUISITION = "p_reported_acq";
@Autowired private RestClient restClient; @Autowired private RestClient restClient;
public ABTestInvoker() { public ABTestInvoker() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
} }
public void reportAcquisition() {
if (!Preferences.getBoolean(PREF_REPORTED_ACQUISITION, false) &&
!StatisticsService.dontCollectStatistics()) {
new Thread(new Runnable() {
@Override
public void run() {
try {
HttpEntity postData = createPostData(null);
restClient.post(ACQ_URL, postData);
Preferences.setBoolean(PREF_REPORTED_ACQUISITION, true);
} catch (IOException e) {
// Ignored
}
}
}).start();
}
}
/** /**
* Posts the payload to the analytics server * Posts the payload to the analytics server
* @param payload - JSONArray of data points. Created by the * @param payload - JSONArray of data points. Created by the
@ -70,7 +93,9 @@ public class ABTestInvoker {
private HttpEntity createPostData(JSONArray payload) throws IOException { private HttpEntity createPostData(JSONArray payload) throws IOException {
List<NameValuePair> params = new ArrayList<NameValuePair>(); List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("apikey", API_KEY)); params.add(new BasicNameValuePair("apikey", API_KEY));
params.add(new BasicNameValuePair("payload", payload.toString()));
if (payload != null)
params.add(new BasicNameValuePair("payload", payload.toString()));
StringBuilder sigBuilder = new StringBuilder(); StringBuilder sigBuilder = new StringBuilder();
for(NameValuePair entry : params) { for(NameValuePair entry : params) {

Loading…
Cancel
Save