Skip to content

Analytics: Track feature adoption with setting values and a config snapshot - #1370

Open
gabrielcld2 wants to merge 8 commits into
developfrom
feature/WPP-1242-feature-adoption-analytics
Open

gabrielcld2 wants to merge 8 commits into
developfrom
feature/WPP-1242-feature-adoption-analytics

Conversation

@gabrielcld2

@gabrielcld2 gabrielcld2 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Makes feature adoption measurable: which delivery features each install runs, and with which values.

The problem

  • settings_saved only carries changed_keys, not the values.
  • Features left at their defaults are never saved, so they are never reported.
  • As a result there is no way to tell what share of installs use lazy loading, responsive images, AVIF or adaptive streaming.

Approach

Feature configuration, shared by both events

  • An allowlist, Analytics::FEATURE_SETTINGS, keyed by settings page, lists the image, video, lazy loading and responsive image settings whose values may be sent. Everything else, including the connection string, is never sent.
  • Values are sent as flat fields named after the plugin's settings, and normalised: toggles to booleans, numbers to ints. A missing value is left out rather than reported as off.
  • Dropdown and radio values are only sent when they are one of the setting's own options, and as other otherwise. Those fields are only sanitised as text, and filters can return anything, so this keeps stored free text from being sent.
  • The lazy-loading threshold is a free-text field, so it is only sent when it is a CSS length such as 100px (lowercased).
  • The free transformation fields (image_freeform, video_freeform) can contain public IDs, overlay text or URLs, so they are only sent as a presence boolean.
  • crop_sizes is sent as the number of image sizes with a custom crop.
  • breakpoints ("Max images") is sent as the count the settings page shows, derived from the breakpoint distance and the min/max widths (2048 / 200 / 200 gives 10). The page calculates that field and only stores it once it is saved, and the stored value isn't used for delivery.

settings_saved

  • Every save of a feature page (image, video, lazy loading, responsive) now carries the full feature configuration as it stands after the save, next to page and changed_keys, so each such save is a baseline and changed_keys shows what was deliberately overridden.
  • Saves of other pages (connection, sync, gallery, extensions) can't change the feature configuration, so they keep sending only page and changed_keys.
  • Values are read after the save, so they reflect any cloudinary_settings_save_setting filters rather than what was submitted.
{
  "event_name": "settings_saved",
  "page": "image_settings",
  "changed_keys": ["image_quality"],
  "image_delivery": true, "image_format": "auto", "image_quality": "80",
  "use_lazy_load": true, "dpr": "2X",
  "enable_breakpoints": false, "pixel_step": 200, "breakpoints": 10,
  "video_delivery": true, "video_quality": "auto"
}

(Abridged: every allowlisted setting is included.)

One-time feature_config_snapshot event (category features)

  • Sends the same feature configuration, including defaults that were never saved, for sites that never save their settings.
  • Fires on the first admin page load by an administrator once the site is connected, never from admin-ajax requests. An autoloaded option stores the cloud name it was sent for, so it is sent again whenever the connected account changes (only the last account is kept, so switching A → B → A sends three) and checking it costs no query.
  • A trigger field tells the cases apart:
    • upgrade: the site was already connected the first time this version ran. This is the baseline backfill for existing installs.
    • setup: the site was freshly installed, or seen unconnected by this version, before being connected, including through the CLOUDINARY_CONNECTION_STRING constant. Account switches also count as setup.
    • A site connected through the constant before any admin page loads is only recognised as setup on a fresh install. A reinstall after the uninstall clean-up (which keeps the plugin's DB version) and subsites of a network activation report upgrade instead.
  • The option holds an empty string while the site isn't set up. Claiming the send goes through add_option() or update_option(), so concurrent requests can't both send it.
  • It doesn't fire while analytics are disabled through cloudinary_analytics_enabled, so it is still sent if they are turned on later.
  • The one-time analytics flags (this one and the existing first_api_consumption one) are removed by the uninstall clean-up, so a reinstall sends a new snapshot.

Configured vs in effect

The values are what is configured, not necessarily what is in effect:

  • Settings keep their values when their parent feature is off, e.g. image_format: "avif" with image_delivery: false, or pixel_step with enable_breakpoints: false. The parent toggles are in the same payload, so reports should filter on them.
  • Values changed through cloudinary_setting_get_value are reported as filtered, since they are read through the settings API.
  • Custom code that turns a feature off without changing its setting can't be detected. That covers site-wide filters (cloudinary_is_{feature}_active, which are meant for front-end requests) and per-image ones (cloudinary_lazy_load_bypass, cloudinary_skip_responsive_breakpoints, cloudinary_is_deliverable). These should be rare.

QA notes

  • npm run test:unit -- --filter Test_Analytics_Feature covers:
    • the allowlist and each kind of normalisation, including unknown dropdown values;
    • the "Max images" count;
    • the snapshot rules: once per account change, re-sent after an account switch, setup vs upgrade, not sent while disconnected, with analytics off, for non-administrators or from admin-ajax, and only one of several concurrent requests sending it.
  • tests/e2e/settings-analytics.spec.js checks the values on a save of each feature page (image, video, lazy loading and responsive), and that the other feature pages' settings are included. tests/e2e/features-analytics.spec.js checks that a gallery save doesn't carry the configuration.
  • tests/e2e/features-analytics.spec.js checks the snapshot's admin wiring. It is tagged @serial because its one-time flag is shared by the whole site.
  • Manual check:
    1. On a connected site, run wp option delete _cloudinary_feature_snapshot_emitted.
    2. Load any admin page twice. There should be exactly one feature_config_snapshot event, with trigger: "upgrade" and the current feature values.
    3. Connect a different Cloudinary account and load an admin page. There should be a new snapshot with trigger: "setup". (On a fresh install, the first snapshot after connecting is also setup.)
    4. Change settings on the Image, Video, Lazy loading and Responsive pages. Each settings_saved event should list the changed keys and carry the full feature configuration with the new values.
    5. Save the connection page. Its settings_saved event should carry only page and changed_keys, and no connection details should appear in any event.

…fig snapshot

`settings_saved` only reported which keys changed, and features left at
their defaults were never reported at all, so adoption of lazy loading,
responsive images, formats or adaptive streaming couldn't be measured.

- `settings_saved` now carries `changed_values` for an allowlist of image,
  lazy loading, responsive and video settings. Anything outside the list,
  including the connection string, is never sent.
- Values are normalised: toggles to booleans, numbers to ints, free-text
  transformations to a presence flag, and crop sizes to a count of custom
  crops.
- A one-time `feature_config_snapshot` sends the full feature config on
  the first admin load once connected, once per cloud name. It covers
  wizard setups, constant-based connections, account switches and
  existing installs upgrading.
- Send the snapshot only on admin page loads by administrators, never from
  admin-ajax requests or for other roles.
- Autoload the one-time flag so checking it costs no query, and gate the
  first send with add_option() so concurrent requests can't both send it.
- Leave missing setting values out instead of reporting them as off.
- Send the lazy-loading threshold only when it is a CSS length; it is a
  free-text field.
- Allowlist feature settings per settings page.
- Report `changed_values` as read back after the save, so they reflect
  any save filters.
- Remove the analytics one-time flags on uninstall.
…e feature snapshot

The feature_config_snapshot event now carries a trigger param: setup when
the site was installed or seen unconnected by this version before being
connected (or switched account), upgrade when it was already connected.
Account switches also go through the same one-request-only gate.

"Max images" is derived by the settings page from the breakpoint distance
and the min/max widths, and only stored once that page is saved, so the
snapshot now reports the count the page shows.
Every settings save now carries the whole allowlisted feature
configuration as flat fields, the same as feature_config_snapshot, next to
page and changed_keys. Each save is then a baseline, and changed_keys shows
which settings were deliberately overridden. This replaces the nested
changed_values object.
- Select and radio values are only sent when they are one of the
  setting's options, and as "other" otherwise, since they are only
  sanitised as text and filters can return anything.
- The lazy-loading threshold is lowercased, so "100PX" is kept.
- "Max images" is marked as derived in the allowlist, since the stored
  value is never sent.
- settings_saved no longer builds the feature configuration while
  analytics are disabled.
- The concurrency test for the first snapshot now really reaches the
  add_option() gate.
- The snapshot docs now say it is re-sent on every account change, and
  where the setup/upgrade trigger can be wrong.
@gabrielcld2
gabrielcld2 marked this pull request as ready for review November 23, 2026 08:44

@utkarshcloudinary utkarshcloudinary left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ✅

Comment thread php/class-admin.php Outdated
Comment on lines +496 to +504
$params = array_merge(
$analytics->get_feature_snapshot(),
array(
'page' => $submission,
'changed_keys' => $changed_keys,
)
);

$analytics->track( 'settings_saved', 'settings', null, $params );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: This does not match the ticket contract for settings_saved. The ticket asks for the changed keys as key→value pairs (like sync_settings_changed). This sends the full feature snapshot (about 30 keys) on every save, also for pages that are not feature pages (connect, sync, gallery, extensions). Two results:

  • On a save, the event does not show which value changed. The collector must compare changed_keys with the flat snapshot keys. For keys that are not in the allowlist, no value is sent.
  • Each save of a non-feature page sends the full feature config again. This adds noise to the settings_saved adoption counts and makes the event payload bigger.

If this design is intentional, get approval from the data team and update the Event Tracking Spec and the collector schema for these extra params. If it is not, send changed_values (key → normalised value) for the changed keys that are in the allowlist, and send nothing more when $submission is not a key of Analytics::FEATURE_SETTINGS.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The full config is intentional: We decided in a sync after the ticket was written to send a flat map of all feature settings with each save, rather than only the changed values, so every save is a complete baseline. changed_keys still says what changed, and each changed allowlisted key has its new value at the top level. We'll update the Event Tracking Spec once the payloads are final.

You're right about non-feature pages, though: they can't change the feature config, so it was just noise. Fixed in 9051498: only saves of the image, video, lazy-loading and responsive pages carry it now, and the others send only page and changed_keys.

Comment thread php/class-analytics.php
Comment on lines +255 to +263
$claimed = false === $sent
? add_option( self::FEATURE_SNAPSHOT_FLAG, $cloud, '', true )
: update_option( self::FEATURE_SNAPSHOT_FLAG, $cloud, true );
if ( ! $claimed ) {
return;
}

$params = $this->get_feature_snapshot();
$params['trigger'] = false === $sent ? 'upgrade' : 'setup';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: In one race, trigger can be upgrade when it should be setup. Request A reads the flag as missing, so its notoptions cache marks the flag as missing. Then request B (still unconnected) writes ''. Then A, now connected, calls add_option(). add_option() does not check again because notoptions has the flag, so the INSERT ... ON DUPLICATE KEY UPDATE replaces '', returns true, and A sends trigger: upgrade. This needs a concurrent unconnected admin load at the moment of connection, so it is rare. Add this case to the list of known limits in the docblock at L212-223.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, confirmed. It's rare and only mislabels the trigger (still a single snapshot), so I've added it to the known limits in the docblock (9051498).

Comment thread php/class-analytics.php Outdated
return;
}

// Autoloaded, so this check costs no query on later admin loads.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This comment is not always correct. When the site is connected, the flag is missing, and cloudinary_analytics_enabled returns false, the method returns at L248 before it writes the flag. Then get_option() misses alloptions and runs a SELECT on each admin load (there is no persistent object cache). Change the comment, or write the flag before the is_enabled() check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks.
I kept the behaviour, because writing the flag there would lose both the deferred send and the upgrade trigger, and corrected the comment to say that case costs one option query per admin load (9051498).

Comment on lines +185 to +197
foreach ( $values as $key => $value ) {
$original[ $key ] = $settings->get_value( $key );
$settings->get_setting( $key )->set_value( $value );
}

$snapshot = $this->analytics->get_feature_snapshot();

$settings->get_setting( 'pixel_step' )->set_value( 500 );
$coarser = $this->analytics->get_breakpoint_count();

foreach ( $original as $key => $value ) {
$settings->get_setting( $key )->set_value( $value );
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This test changes the shared in-memory settings on the plugin singleton and restores them only on the success path. If get_feature_snapshot() or get_breakpoint_count() throws, the next tests run with max_width=2048, pixel_step=500 and so on. Put the restore loop in finally, or in tear_down().

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, the restore now runs in a finally block (9051498).

… saves

Saves of the connection, sync, gallery or extensions pages can't change
the feature configuration, so their settings_saved events no longer carry
it. Also documents one more race where the snapshot trigger can be
upgrade instead of setup, corrects the comment on the flag's query cost,
and restores shared settings in a finally block in the breakpoints test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants