-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track referrer for INSTANCE_UPLOAD action #6474
Conversation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { | ||
Uri referrerUri = getReferrer(); | ||
if (referrerUri != null) { | ||
return referrerUri.getHost(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we definitely just want the host here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked a bit deeper into this and it looks like the referrer extra needs to be explicitly set: https://developer.android.com/reference/android/content/Intent#EXTRA_REFERRER It sounds like it's set automatically when the referrer is a web app but not when it's an Android app. We may get all nulls but I still think we should try it.
Can we just return referrerUri.toString
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good:
If the launching Intent contains an Intent.EXTRA_REFERRER, that will be returned as-is; otherwise, if known, an android-app: referrer URI containing the package name that started the Intent will be returned. This may return null if no referrer can be identified -- it is neither explicitly specified, nor is it known which application package was involved.
-- https://developer.android.com/reference/android/app/Activity#getReferrer()
I thought I was losing my mind for a minute there, I could have sworn I saw more certainty that it would be set.
Still, referrerUri.toString
seems like the best thing to return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I changed it to referrerUri.toString if you prefer it.
It sounds like it's set automatically when the referrer is a web app but not when it's an Android app. We may get all nulls but I still think we should try it.
I tested it with Collect Intents Tester and it didn't return nulls.
c68977d
to
5d606e9
Compare
@@ -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, "referrer", referrer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lognaturel logging like this limits us to viewing a max of 200 distinct values right? As far as I'm aware there isn't another way to log custom data though (other than a user property which isn't really appropriate).
Also assuming we do want to do an event. It needs to be setup on Firebase as far as I can remember.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 200 limit is right and I'll be absolutely flabbergasted if there are more than 5-10 uniques!!
It needs to be setup on Firebase as far as I can remember.
Ooh, good call. I don't remember that part at all. Would you be ok doing it when you have some time (no big rush)?
Looks great to me! 🙏 |
@@ -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, "referrer", referrer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a limit on how many custom parameters we have, so I think we should use the existing generic "label" here rather than add "referrer".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, that's a good call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
e581a6c
to
d04e75c
Compare
@@ -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 = "org.odk.collect.android"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the back and forth, but I just caught this. Why do we set this to "org.odk.collect.android"
? Surely it only gets used if completeDestinationUrl
is set (which it's set with) so we can just leave it unassigned.
Just want to make sure we're only logging in cases where the custom URL is being used here and that I'm not missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right it was redundant.
741f517
to
d821fa1
Compare
@@ -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 : ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
referrer shouldn't be null here but I added that check just in case to avoid errors as Analytics.log
expects non-null strings.
Closes #6472
Why is this the best possible solution? Were any other approaches considered?
getReferrer was added in API 22 so it won't work for API 21 which is the lowest version we support but I don't think this is a problem.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
It doesn't require testing.
Do we need any specific form for testing your changes? If so, please attach one.
No.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
./gradlew connectedAndroidTest
(or./gradlew testLab
) and confirmed all checks still passDateFormatsTest