diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index 9715929fb..84fbb7c55 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -42,6 +42,7 @@ import com.todoroo.astrid.opencrx.OpencrxCoreUtils; import com.todoroo.astrid.producteev.ProducteevUtilities; import com.todoroo.astrid.reminders.ReminderStartupReceiver; 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.Constants; import com.todoroo.astrid.widget.TasksWidget.WidgetUpdateService; @@ -85,6 +86,8 @@ public class StartupService { @Autowired ABChooser abChooser; + @Autowired ABTestInvoker abTestInvoker; + /** * bit to prevent multiple initializations */ @@ -177,6 +180,8 @@ public class StartupService { // For any uninitialized ab test, make sure an option is chosen abChooser.makeChoicesForAllTests(latestSetVersion == 0, taskService.getUserActivationStatus()); + abTestInvoker.reportAcquisition(); + // perform startup activities in a background thread new Thread(new Runnable() { public void run() { diff --git a/astrid/src/com/todoroo/astrid/service/abtesting/ABTestInvoker.java b/astrid/src/com/todoroo/astrid/service/abtesting/ABTestInvoker.java index 2334dd5a6..c27af25c7 100644 --- a/astrid/src/com/todoroo/astrid/service/abtesting/ABTestInvoker.java +++ b/astrid/src/com/todoroo/astrid/service/abtesting/ABTestInvoker.java @@ -18,6 +18,8 @@ import org.json.JSONObject; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; 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 @@ -28,16 +30,37 @@ import com.todoroo.andlib.service.RestClient; public class ABTestInvoker { /** 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_SECRET = "q9ef3i"; + private static final String PREF_REPORTED_ACQUISITION = "p_reported_acq"; + @Autowired private RestClient restClient; public ABTestInvoker() { 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 * @param payload - JSONArray of data points. Created by the @@ -70,7 +93,9 @@ public class ABTestInvoker { private HttpEntity createPostData(JSONArray payload) throws IOException { List params = new ArrayList(); 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(); for(NameValuePair entry : params) {