Skip to content

Commit

Permalink
Send fundraising banner opt-in state in app_donor_experience stream. (#…
Browse files Browse the repository at this point in the history
…4885)

* Fix blocked message in Suggested Edits, and use coroutines.

* Fix tests.

* Check for banner opt-in.

* Plug it in.

* Plug it in.

* Invert check.

* Harden check.

---------

Co-authored-by: Cooltey Feng <[email protected]>
  • Loading branch information
dbrant and cooltey authored Aug 21, 2024
1 parent 279c224 commit f086945
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wikipedia.analytics.eventplatform

import org.wikipedia.WikipediaApp
import org.wikipedia.settings.Prefs

class DonorExperienceEvent {

Expand All @@ -15,7 +16,7 @@ class DonorExperienceEvent {
submit(
action,
activeInterface,
campaignId?.let { "campaign_id: $it, " }.orEmpty(),
campaignId?.let { "campaign_id: $it, " }.orEmpty() + "banner_opt_in: ${Prefs.donationBannerOptIn}",
wikiId
)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/wikipedia/dataclient/mwapi/UserInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wikipedia.dataclient.mwapi

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
import org.wikipedia.dataclient.mwapi.MwServiceError.BlockInfo
import org.wikipedia.util.DateUtil
import java.util.*
Expand Down Expand Up @@ -52,5 +53,6 @@ class UserInfo : BlockInfo() {
@Serializable
class Options {
@SerialName("watchdefault") val watchDefault: Int = 0
@SerialName("centralnotice-display-campaign-type-fundraising") val fundraisingOptIn: JsonElement? = null
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/org/wikipedia/settings/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ object Prefs {
get() = PrefsIoUtil.getString(R.string.preference_key_user_contrib_filter_lang_code, WikipediaApp.instance.appOrSystemLanguageCode)!!
set(value) = PrefsIoUtil.setString(R.string.preference_key_user_contrib_filter_lang_code, value)

var donationBannerOptIn
get() = PrefsIoUtil.getBoolean(R.string.preference_key_donation_banner_opt_in, true)
set(value) = PrefsIoUtil.setBoolean(R.string.preference_key_donation_banner_opt_in, value)

var importReadingListsNewInstallDialogShown
get() = PrefsIoUtil.getBoolean(R.string.preference_key_import_reading_lists_new_install_dialog_shown, true)
set(value) = PrefsIoUtil.setBoolean(R.string.preference_key_import_reading_lists_new_install_dialog_shown, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import kotlinx.coroutines.withContext
import okhttp3.Request
import okhttp3.Response
import okhttp3.internal.closeQuietly
import org.wikipedia.WikipediaApp
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.dataclient.okhttp.OkHttpConnectionFactory.client
import org.wikipedia.recurring.RecurringTask
import org.wikipedia.util.log.L
Expand Down Expand Up @@ -32,6 +34,12 @@ class RemoteConfigRefreshTask : RecurringTask() {
} finally {
response?.closeQuietly()
}

val userInfo = ServiceFactory.get(WikipediaApp.instance.wikiSite).getUserInfo()
// This clumsy comparison is necessary because the field is an integer value when enabled, but an empty string when disabled.
// Since we want the default to lean towards opt-in, we check very specifically for an empty string, to make sure the user has opted out.
val fundraisingOptOut = userInfo.query?.userInfo?.options?.fundraisingOptIn?.toString()?.replace("\"", "")?.isEmpty()
Prefs.donationBannerOptIn = fundraisingOptOut != true
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<string name="preference_key_edit_monospace_font">editMonospaceFont</string>
<string name="preference_key_edit_line_numbers">editLineNumbers</string>
<string name="preference_key_edit_typing_suggestions">editTypingSuggestions</string>
<string name="preference_key_donation_banner_opt_in">donationBannerOptIn</string>
<string name="preference_key_reading_lists_share_url_shorten">useUrlShortenerForSharing</string>
<string name="preference_key_reading_lists_share_survey_dialog_shown">readingListShareSurveyDialogShown</string>
<string name="preference_key_reading_lists_share_survey_mode">readingListShareSurveyMode</string>
Expand Down

0 comments on commit f086945

Please sign in to comment.