Add sampling by country options to QuickSurvey.
Precursors
An example survey will be necessary for us to build and test this survey.
Why?
- Sometimes we only need data from a specific country or region and sampling from all requests to get enough number of responses from the region is not an option (we will be asking a lot of users to provide data that we won't use.)
What's already there?
Client-side country information is available under window.Geo.country
Acceptance criteria
- A survey can be configured to target an editor in a certain country (or countries)
Notes about Implementation
- Targeting a survey to a particular country requires including that country's two-character code in the configuration. It must be capitalized -- e.g., if you want to include the United States, you must have countries include "US"; none of "us" or "Us" or "USA" would work.
- Not including countries in the configuration means country is not considered when targeting the survey
- Including no countries in the configuration (i.e. "countries" => []) means no country is targeted (and therefore no one sees the survey)
- Including one country in the configuration (e.g. "countries" => ["US"]) means that only users whose IP geocodes them to that country will be included
- Including multiple countries in the configuration (e.g. "countries" => ["US", "CA"]) means that users from all of those countries can be shown the survey
The applicable two-letter country codes can be found in several places:
- They come from: https://dev.maxmind.com/geoip/legacy/codes/iso3166/
- They are processed via CentralNotice -- see https://github.com/wikimedia/mediawiki-extensions-CentralNotice/blob/master/includes/GeoTarget.php
- Practically, checking the codes in webrequest (geocoded_data) or geoeditors (country_code) tables ensures you are using an appropriate code
- You can check what country you are considered to be in by navigating to a Wikipedia article, opening your web console, and looking what value window.Geo has
Sign off steps
We want to avoid the problem where when this survey goes live there is a problem with the implementation. We will want to sign this off with research carefully to avoid this happening.
Developer notes
Window.Geo is defined in the CentralNotice extension:
CentralNotice/modules/ext.centralNotice.bannerController/bannerController.js
QA steps
- Test on DESKTOP
- A survey has been setup to only show for users from America and France
- Visit https://reading-web-staging.wmflabs.org/wiki/Test_the_diff
- confirm survey doesn't show
- In your developer console make yourself "American" by running:
$.cookie( 'GeoIP', 'US:CO:Denver:39.6762:-104.887:v4' )
- confirm survey shows
- Make yourself Spanish:
$.cookie( 'GeoIP', 'ES:Catalonia:Barcelona:39.6762:-104.887:v4' )
- confirm survey doesn't show
- make yourself French
$.cookie( 'GeoIP', 'FR:Lille:39.6762:-104.887:v4' )
- confirm survey is showing again
QA Results
Status | Details |
✅ Passed | T213847#5028896 |