Automattic / Automattic/safe-publish

Emit a shared import_completed event from both import paths

Open
#474 0 comments 0 reactions 0 assignees View on GitHub
Enhancement
Dominant language
PHP
Stars
3
Forks
1
Avg merge
1d 22h
Merged PRs (30d)
57

Description

**Summary**: There is no single event that answers "how many imports ran." Counting import activity requires unioning two events with incompatible units. A shared `import_completed` event emitted from both paths would make import volume a one-event query.

**Current state**: `safe_publish_single_import_completed` is emitted in exactly one place — `ajax_create_draft` (`includes/admin/class-admin-ajax-controller.php:1774`) — with `outcome` (`new`|`updated`) and `warning_count`. Bulk imports run through `ajax_bulk_import`, which loops `Post_Import_Service::import_post()` over the batch and emits one `safe_publish_bulk_import_completed` at the end (`:1944`) with `batch_size`, `successful`, `failed`, `has_failures`. The import service itself emits no completion event, so bulk never produces per-item single events and nothing double-counts.

**Desired state**: A single `import_completed` event emitted from both `ajax_create_draft` and `ajax_bulk_import`, in batch units on both paths, so import volume and failure rate are answerable without a union:

- `session_type` — `single`|`bulk`, reusing the existing `Telemetry_Events::SESSION_TYPE_*` enum from `import_item_failed`.
- `batch_size`, `successful`, `failed`, `has_failures` — as `bulk_import_completed` defines them today, with `batch_size = 1` on the single path.
- `outcome` — `success`|`partial`|`failed`, mirroring the bounded enum already used by `rollback_performed`. A partial bulk is a real state the current pair cannot express.

This requires emitting on the single path's failure branch too, before the `wp_send_json_error()` return, so the event means the same thing in both places.

We can remove the existing events at the same time.

Open questions for whoever picks this up:

2. **Where does `outcome` (`new`|`updated`) go?** It does not generalize to a batch. Either it stays on a slimmed `single_import_completed`, or it becomes a `created`/`updated` count pair on `import_completed` that works in both units.
3. **`warning_count`** is single-only today; on a batch it would need to be a sum, which changes what it measures.

Whatever lands, `docs/telemetry.md` is the source of truth for the catalog and needs the event table and the "Ran an import" segment definition updated in the same change. Properties stay bounded enums or counts — no titles, error messages, or URLs.

Contributor guide

Open the contributing guide

Research direction

Start with ajax_create_draft and ajax_bulk_import in includes/admin/class-admin-ajax-controller.php, then review Telemetry_Events and the existing event definitions. Resolve how single-only properties map to the shared event, emit it on success and failure paths, remove the old events, and update docs/telemetry.md and the "Ran an import" segment definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
analytics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.