Campaign metrics read visitors and avg_engaged, which sort=views responses omit

Open Beginner friendly
#4,855 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php, wordpress
Domain
analytics, backend

Research direction

Start in src/rest-api/stats/class-endpoint-posts.php, especially Endpoint_Posts::fetch_campaign_data() around lines 510–513, and compare its metric handling with the Post List Stats and Smart Linking requests mentioned in the issue. Reproduce the request without sort and inspect the campaign response. Done means the endpoint avoids undefined-key warnings and returns the campaign metrics the API provides.

Written by the indexing model from the issue text.

Description

Bug Feature: Engagement Boost wp-parsely

Describe the bug

Endpoint_Posts::fetch_campaign_data() copies four metrics from the campaign response without checking that they exist (src/rest-api/stats/class-endpoint-posts.php:510–:513). The Parse.ly API returns different metrics depending on sort: with sort=views, metrics holds only views and recirculation_rate, while visitors and avg_engaged need sort=avg_engaged. The plugin already works around this elsewhere, as Post List Stats and Smart Linking request sort=avg_engaged for that reason.

The Engagement Boost dashboard sends no sort, so the endpoint falls back to views for both the main and the campaign request. Reading visitors and avg_engaged then raises a warning for each post with campaign data, and the response never includes campaign.visitors or campaign.avgEngaged.

To Reproduce

  1. Request GET /wp-parsely/v2/stats/posts?campaign_id=wp-parsely&campaign_medium=smart-link&period_start=30d without sort, as the Engagement Boost dashboard does.
  2. Check the PHP error log.

PHP raises Undefined array key "visitors" at class-endpoint-posts.php:511 and Undefined array key "avg_engaged" at :513 for each post with campaign data. Each campaign object holds only views and recirculationRate.

Expected behavior

No warnings, and a campaign object that holds the metrics the API returned.

Environment

wp-parsely 3.26.1 and current develop, PHP 8.3. Confirmed against the live Parse.ly API: a sort=views request with these campaign parameters returns only views and recirculation_rate.

Additional context

The dashboard only reads campaign.views, so the visible effect today is the log noise. Possible fixes: copy only the metrics present, and request sort=avg_engaged for the campaign data if visitors and avg_engaged are needed.

Related: #4854, which affects the same block.

Dominant language
PHP
Stars
67
Forks
38
Avg merge
1d 5h
Merged PRs (30d)
79

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Parsely/wp-parsely

All issues in Parsely/wp-parsely

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.