Skip to content

Commit

Permalink
Merge pull request #6474 from grzesiek2010/COLLECT-6472
Browse files Browse the repository at this point in the history
Track referrer for INSTANCE_UPLOAD action
  • Loading branch information
seadowg authored Nov 4, 2024
2 parents 1a10357 + d821fa1 commit 700594f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;

import org.odk.collect.android.activities.FormFillingActivity;
Expand Down Expand Up @@ -177,7 +178,7 @@ private void init(Bundle savedInstanceState) {
instanceUploaderTask = new InstanceUploaderTask();

if (url != null) {
instanceUploaderTask.setCompleteDestinationUrl(url + OpenRosaConstants.SUBMISSION);
instanceUploaderTask.setCompleteDestinationUrl(url + OpenRosaConstants.SUBMISSION, getReferrerUri(), true);

if (deleteInstanceAfterUpload != null) {
instanceUploaderTask.setDeleteInstanceAfterSubmission(deleteInstanceAfterUpload);
Expand Down Expand Up @@ -376,7 +377,7 @@ public void updatedCredentials() {
// TODO: is this really needed here? When would the task not have gotten a server set in
// init already?
if (url != null) {
instanceUploaderTask.setCompleteDestinationUrl(url + OpenRosaConstants.SUBMISSION, false);
instanceUploaderTask.setCompleteDestinationUrl(url + OpenRosaConstants.SUBMISSION, getReferrerUri(), false);
}
instanceUploaderTask.setRepositories(instancesRepository, formsRepository, settingsProvider);
instanceUploaderTask.execute(instancesToSend);
Expand All @@ -386,4 +387,14 @@ public void updatedCredentials() {
public void cancelledUpdatingCredentials() {
finish();
}

private String getReferrerUri() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
Uri referrerUri = getReferrer();
if (referrerUri != null) {
return referrerUri.toString();
}
}
return "unknown";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class InstanceUploaderTask extends AsyncTask<Long, Integer, InstanceUploa
// Custom submission URL, username and password that can be sent via intent extras by external
// applications
private String completeDestinationUrl;
private String referrer;
private String customUsername;
private String customPassword;
private InstancesRepository instancesRepository;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Outcome doInBackground(Long... instanceIdsToUpload) {
publishProgress(i + 1, instancesToUpload.size());

if (completeDestinationUrl != null) {
Analytics.log(AnalyticsEvents.INSTANCE_UPLOAD_CUSTOM_SERVER);
Analytics.log(AnalyticsEvents.INSTANCE_UPLOAD_CUSTOM_SERVER, "label", referrer != null ? referrer : "");
}

try {
Expand Down Expand Up @@ -202,12 +203,9 @@ public void setRepositories(InstancesRepository instancesRepository, FormsReposi
this.settingsProvider = settingsProvider;
}

public void setCompleteDestinationUrl(String completeDestinationUrl) {
setCompleteDestinationUrl(completeDestinationUrl, true);
}

public void setCompleteDestinationUrl(String completeDestinationUrl, boolean clearPreviousConfig) {
public void setCompleteDestinationUrl(String completeDestinationUrl, String referrer, boolean clearPreviousConfig) {
this.completeDestinationUrl = completeDestinationUrl;
this.referrer = referrer;
if (clearPreviousConfig) {
setTemporaryCredentials();
}
Expand Down

0 comments on commit 700594f

Please sign in to comment.