Qonnect for KoboToolbox

By bgoddev

0+ active installationsVersion 0.1.0

Put KoboToolbox forms and results on your WordPress site: embed forms and show counts, tables and maps from only the fields you choose to share.

Description

Qonnect for KoboToolbox connects a WordPress site to a KoboToolbox account. You embed your Kobo forms on WordPress pages and show the results to visitors as counts, tables and maps. Nothing is public until you say so, and only the questions you pick ever leave KoboToolbox.

It is built for NGOs, research teams and public bodies that collect data with KoboToolbox and want to report it on their own website, without exporting spreadsheets by hand or exposing personal answers.

Qonnect for KoboToolbox is an independent plugin by Halal NumeriQ. It is not affiliated with or endorsed by Kobo, Inc.

How it works

  1. Connect your KoboToolbox account with its server address and your API token. The global and EU servers and self-hosted KoboToolbox servers over HTTPS all work. The plugin only reads from your Kobo account: it never creates, changes or deletes anything there.
  2. Import a form and choose, question by question, what may be shared. Every question starts blocked. Free-text, location, photo and other media questions, and questions named like a name, phone number, e-mail address or ID, are flagged, and you confirm each one before sharing it.
  3. Sync. The plugin copies the shared answers of each submission to your site’s database in the background, every hour by default (each form’s Sync every setting: from every 15 minutes to once a day). Blocked answers are dropped before anything is written, so they never reach your database, cache or logs.
  4. Publish. Each form has a “Publish data” switch, off by default. Until you turn it on, the form’s blocks show nothing to visitors and its data API answers “not found”.
  5. Add blocks to any page or post.

Blocks and shortcodes

  • Kobo Form: embeds a deployed form so visitors can fill it in on your page, with a link to open it in a new tab. Shortcode: [qonnect_form id=12].
  • Submission Count: shows how many submissions a form has, optionally filtered by a shared choice, number or date. Shortcode: [qonnect_count id=12 filters="district=north"].
  • Data Table: shows the shared fields as a table with paging, sorting and search. On phones each row stacks into labelled lines and a “Sort by” menu replaces the column headers. Shortcode: [qonnect_table id=12 fields="district,status" per_page=20].
  • Submissions Map: shows where submissions were made, from a shared location question, with popups listing the fields you choose. Leaflet is bundled, and tiles come from OpenStreetMap by default. Shortcode: [qonnect_map id=12 popup="district,status"].

Pages never call KoboToolbox when a visitor opens them. The blocks read the copy on your own site, so pages stay fast and your token stays on the server. Each block loads its scripts only on pages that use it.

Privacy and control

  • Default deny: only the questions you share are copied. Blocking a question later removes its stored answers at the next sync.
  • Privacy page: shows, for each form, what is stored, what is shared, and which shared questions may hold personal data.
  • Minimum group size: counts combine answers given by fewer than 5 people, so no small group can identify anyone. Raise it per form, up to 100; a filter lets you allow lower sizes (see the FAQ).
  • Aggregate only: a per-form switch so visitors see only summary counts, never single submissions.
  • Delete stored data: removes this site’s copy of a form’s submissions. Nothing is ever deleted in KoboToolbox.
  • Status page: shows each form’s last and next sync, failures and their reasons in plain words, the health of scheduled syncs, and how visitors are counted for the rate limit.
  • Debug log: off by default. When on, it records sync events and error reasons only, never tokens or answers.
  • Suggested privacy policy text in Settings, Privacy, covering the stored answers, the embedded form and map tiles.
  • Public data requests are cached and rate-limited per visitor.

Third-party services

This plugin connects to the following services. Nothing else is contacted.

KoboToolbox (your KoboToolbox server)

  • The API. When you add a connection, import a form, or a sync runs, your WordPress server sends requests to the KoboToolbox server you entered, with your API token. It only reads: it fetches your form definitions and submissions and copies only the questions you share, and it never creates, changes or deletes anything in your Kobo account. These requests go from your server, never from your visitors’ browsers.
  • The embedded form. When a page has a Kobo Form block, the visitor’s browser loads the form from KoboToolbox’s form server (Enketo) inside an iframe. KoboToolbox then receives the visitor’s IP address and browser details, along with whatever answers they submit.
  • KoboToolbox is a service of Kobo, Inc. For the hosted servers at kf.kobotoolbox.org and eu.kobotoolbox.org, see the Terms of Service and Privacy Notice. A self-hosted KoboToolbox server is covered by the terms of whoever runs it.

OpenStreetMap map tiles

  • When a page has a Submissions Map block, the visitor’s browser downloads map images (“tiles”) from tile.openstreetmap.org. The tile server receives the visitor’s IP address, browser details and the area of the map being viewed. No submission data is sent.
  • The tiles are run by the OpenStreetMap Foundation. See the Tile Usage Policy, Terms of Use and Privacy Policy.
  • The public tile servers are meant for light use. For a busy site, set your own tile provider (see the FAQ). This list of tile providers is a good place to start. Your visitors’ requests then go to that provider under its own terms.

Source code and build

The source code is public at github.com/bawanallahbilyaminu/qonnect-for-kobotoolbox, and the human-readable source of everything in the build folder also ships with the plugin, in assets/src:

  • build/blocks/<name>/index.js (the block editor script) and build/blocks/<name>/view.js (the front-end script, for the Data Table and Submissions Map) are built from assets/src/blocks/<name>/, for the count, form, map and table blocks, with the code they share from assets/src/blocks/shared/. The map’s view.js also bundles Leaflet from assets/src/vendor/leaflet/.
  • build/admin/index.js (the plugin’s admin screens) is built from assets/src/admin/.
  • The stylesheets next to them are built from the .scss files in the same folders.

The build configuration (package.json, package-lock.json, webpack.config.js and babel.config.js) is included too. The build uses @wordpress/scripts (webpack and Babel). To rebuild, install Node.js 22.22.2 or later (see engines in package.json), then run this in the plugin folder:

npm ci && npm run build

The plugin’s PHP code in src is not compiled.

Bundled third-party code

  • Leaflet 1.9.4, the map library of the Submissions Map block. BSD-2-Clause licence: leafletjs.com, source. Its source is in assets/src/vendor/leaflet and its licence in assets/src/vendor/leaflet/LICENSE and build/vendor/leaflet/LICENSE.

Installation

The plugin needs MySQL 5.7.8 or later, or MariaDB 10.2.3 or later. SQLite, which WordPress Playground uses, is not supported.

  1. In WordPress, go to Plugins, Add New, search for “Qonnect for KoboToolbox”, then install and activate it. You can also upload the zip under Plugins, Add New, Upload Plugin.
  2. Go to Qonnect, Connections and add a connection: a name, your KoboToolbox server address (for example https://kf.kobotoolbox.org or https://eu.kobotoolbox.org) and your API token. The plugin checks the token before saving it.
  3. Go to Qonnect, Forms, import a form, and open Choose fields to share the questions you want to show.
  4. Wait for the first sync, or press Sync now on the Status page.
  5. Turn on Publish data for the form when you are ready for visitors to see the shared fields.
  6. Edit a page, add a Kobo Form, Submission Count, Data Table or Submissions Map block, and pick the form.

FAQ

Where do I find my KoboToolbox API token?

Log in to KoboToolbox, open your account settings and look under Security for the API key. Anyone with the token can read your projects, so keep it private. If you can, use an account that has access only to the projects you want on your site.

How is the token stored?

It is encrypted with libsodium before it is saved, using a key derived from your site’s secret keys in wp-config.php. You can set a dedicated key with define( 'QONNECT_ENCRYPTION_KEY', '…a long random string…' );. If you change your salts or that key later, re-enter the token. The token is never sent to the browser, shown on an admin page, or written to a log.

Which data is copied to my site?

Only the answers to the questions you share, plus each submission’s Kobo id, submission time and validation status. Blocked questions are removed before anything is saved. The Privacy page lists, for each form, exactly what is stored and shared.

What does “Publish data” do?

It decides whether visitors can see a form’s shared fields. While it is off (the default), the form’s blocks and shortcodes show nothing to visitors and its public API returns “not found”, even if you have shared fields and synced. Once it is on, anyone can read the shared fields on pages with a Qonnect block or through the site’s data API. Turning it off hides the data again at once.

Does deleting data here delete it in KoboToolbox?

No. The plugin only reads from your Kobo account. Delete stored data removes only the copy on your WordPress site. Your forms and submissions in KoboToolbox are never changed. The next sync copies the shared fields again.

Syncs are not running. What should I check?

Syncs use WP-Cron, which only runs when someone visits your site. On a quiet site, or if DISABLE_WP_CRON is set in wp-config.php, add a real cron job on your server. The Status page shows the exact line for your site, for example:

*/5 * * * * curl -fsS "https://example.org/wp-cron.php?doing_wp_cron" > /dev/null 2>&1

With WP-CLI you can use wp cron event run --due-now instead. The Status page warns you when scheduled syncs have stopped running.

My site is behind Cloudflare, a CDN or a reverse proxy. Do I need to change anything?

The rate limit on public data counts requests per visitor IP address. Behind a proxy, every visitor seems to come from the proxy’s address, so they share one limit. To fix this, list your proxies’ addresses or ranges in wp-config.php:

define( 'QONNECT_TRUSTED_PROXIES', '173.245.48.0/20, 10.0.0.0/8' );

The plugin then reads the visitor’s address from the X-Forwarded-For header, but only for requests that arrive from those proxies. Use your provider’s published list of ranges. The Status page shows which method is in use and warns about invalid entries.

Can I show groups smaller than 5?

Yes, with a filter. By default, counts combine answers given by fewer than 5 people, so no small group can identify anyone, and each form’s minimum group size can be raised up to 100 under Choose fields, Display settings. To let administrators choose a lower size, or 0 for no minimum, add this to your theme’s functions.php or a small plugin:

add_filter( 'qonnect_min_group_size_floor', fn() => 2 );

Small groups can identify people, so lower it only when that is acceptable for your data.

Can I change the other privacy defaults?

Yes, with filters. qonnect_confirm_sensitive_fields (true by default) decides whether sharing a question that may hold personal data needs its own confirmation: add_filter( 'qonnect_confirm_sensitive_fields', '__return_false' ); turns that step off, and the warning still shows. qonnect_rate_limit (60 by default) sets how many public data requests one visitor may make per minute; 0 removes the limit: add_filter( 'qonnect_rate_limit', fn() => 120 );.

What does “Aggregate only” do?

It is a switch in each form’s Display settings. When it is on, visitors see only summary counts of that form: Data Table and Submissions Map blocks show nothing, and a count can use one filter at most.

How often does a form sync?

Every hour by default. Each form has a Sync every setting under Choose fields, Display settings: every 15 or 30 minutes, every hour, every 6 or 12 hours, or once a day. Each sync run makes at most 60 requests to KoboToolbox; change that with the qonnect_request_budget filter (1 to 500):

add_filter( 'qonnect_request_budget', fn() => 120 );

Can I use a different map tile provider?

Yes, and busy sites should. OpenStreetMap’s public tile servers are run by volunteers, and their tile usage policy does not allow heavy use. To use another provider, return an HTTPS tile address containing {z}, {x} and {y}, and the provider’s attribution, from the qonnect_map_tiles filter in your theme’s functions.php or a small plugin:

add_filter( 'qonnect_map_tiles', fn() => [ 'url' => 'https://tiles.example.com/{z}/{x}/{y}.png', 'attribution' => '&copy; Example Tiles' ] );

An address that is not HTTPS or lacks {z}, {x} or {y} is ignored, and the map uses OpenStreetMap with its own attribution.

Can I add arguments to the embedded form’s address?

Yes, with the qonnect_form_embed_args filter. It receives an empty array and the form, and the key/value pairs you return are added, encoded, to the embedded form’s address and to its “Open the form in a new tab” link (never in the block editor). For example, to fill a question with a fixed value through Enketo’s d[/form_id/question] parameters (the form’s XForm ID and the question’s name):

add_filter( 'qonnect_form_embed_args', fn( $args, $form ) => $args + [ 'd[/my_survey/source]' => 'website' ], 10, 2 );

How long are public results cached?

Five minutes. A sync that changes a form’s data, or a change of its shared questions, replaces the cached results at once. Change the time with the qonnect_cache_ttl filter (30 to 86400 seconds):

add_filter( 'qonnect_cache_ttl', fn() => 900 );

Does uninstalling delete my data?

Yes: deleting the plugin removes its tables, settings and cached results from your site (never anything in KoboToolbox). To keep them, for example before reinstalling, add this before you delete the plugin:

add_filter( 'qonnect_keep_data_on_uninstall', '__return_true' );

Does it slow down my pages?

Pages read only your site’s own database and cache, never KoboToolbox. Scripts and styles load only on pages that use a Qonnect block. The map adds about 45 KB, compressed, including Leaflet.

Can visitors log in to Kobo through the embedded form?

If a form needs a KoboToolbox login, most browsers block that login inside the embedded frame. The editor warns you about this. Allow anonymous submissions for the form in KoboToolbox, or link to it with “Open the form in a new tab”.

Screenshots

Changelog

0.1.0

  • First release.
  • Connections to KoboToolbox servers with encrypted API tokens.
  • Form import and a Field Selector: every question blocked by default, with personal-data warnings and confirmation.
  • Background sync of shared answers only, every 15 minutes to once a day per form, with retry and back-off, re-reads of edited submissions, and removal of submissions deleted in KoboToolbox.
  • A “Publish data” switch for each form, off by default.
  • Kobo Form, Submission Count, Data Table and Submissions Map blocks, with matching shortcodes.
  • Privacy and Status pages, Delete stored data, an opt-in debug log, and suggested privacy policy text.