Campaign metrics are returned for at most one post per stats request

Aperta Adatta ai principianti
#4,854 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php, wordpress
Ambito
analytics, backend

Direzione di ricerca

Inizia da src/rest-api/stats/class-endpoint-posts.php, in Endpoint_Posts::fetch_campaign_data(), intorno alla riga 507, poi leggi il flusso dell’endpoint delle statistiche dei post e la logica di corrispondenza delle risposte delle campagne. Riproduci il problema con la richiesta documentata con due post e una risposta simulata che restituisce per primo il secondo post. Il lavoro è completato quando ogni post riceve le metriche della campagna corrispondenti, senza avvisi per chiavi non definite o offset nulli.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Feature: Engagement Boost wp-parsely

Describe the bug

Endpoint_Posts::fetch_campaign_data() finds each post's campaign data with array_filter(), which keeps the original keys, and then reads the match as $campaign_post[0] (src/rest-api/stats/class-endpoint-posts.php:507). That only works for the post whose data is the first item of the campaign response, so at most one post per request gets its campaign metrics.

For every other post, $campaign_post[0] is undefined, all four campaign metrics become null, and GET /wp-parsely/v2/stats/posts returns "campaign": [] for it. The Engagement Boost dashboard reads campaign.views for its "+N" smart-link views and its "BOOSTED" percentage (src/content-helper/dashboard-page/components/posts-table/components/single-post-row.tsx:106), so neither appears for those posts.

To Reproduce

  1. Request GET /wp-parsely/v2/stats/posts?campaign_id=wp-parsely&campaign_medium=smart-link&period_start=30d for two posts that both have smart-link views, as the Engagement Boost dashboard does.
  2. Have the campaign request return the second post first. Mocking the API with pre_http_request makes this deterministic.

The post whose campaign data comes second gets "campaign": []. PHP raises Undefined array key 0 at class-endpoint-posts.php:507, followed by eight Trying to access array offset on null warnings at :510–:513.

Expected behavior

Each post gets the campaign metrics that match its link, wherever they appear in the campaign response.

Environment

wp-parsely 3.26.1 and current develop, PHP 8.3. PHP 7.4 raises notices instead of warnings.

Additional context

Possible fixes: take the match with reset(), or index the campaign response by link once before the loop, which also avoids filtering the whole response for every post.

Lingua principale
PHP
Stelle
67
Fork
38
Merge medio
1g 5h
PR unite (30g)
79

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Parsely/wp-parsely

Tutte le issue di Parsely/wp-parsely

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.