Skip to content

fix(pinterest): keep analytics within the 90-day window#1665

Open
giladresisi wants to merge 1 commit into
mainfrom
fix/pinterest-analytics-90-day-window
Open

fix(pinterest): keep analytics within the 90-day window#1665
giladresisi wants to merge 1 commit into
mainfrom
fix/pinterest-analytics-90-day-window

Conversation

@giladresisi

Copy link
Copy Markdown
Collaborator

Problem

Production logs show, for every Pinterest post:

Error fetching Pinterest post analytics: ApplicationFailure: Unknown Error

with Pinterest's underlying message: "You can only get data from the last 90 days."

Pinterest's analytics endpoints (/v5/pins/{pin_id}/analytics, /v5/user_account/analytics) only serve the last 90 days (evaluated in UTC). But postAnalytics() requested start_date 2 years ago (dayjs().subtract(2, 'year')), so the call failed every time. The generic Unknown Error is just BadBody's default message — Pinterest's real reason was in the failure details.

Introduced in 5cca81e0 ("feat: post analytics").

Changes

  • postAnalyticsstart_date is now 89 days back instead of 2 years. Pinterest doesn't expose pin metrics older than 90 days, so 89 days is the maximum obtainable. Using 89 rather than 90 avoids an off-by-one when the server's local date leads UTC.
  • analytics (account level) — clamps the requested period to Math.min(date, 89) so a longer UI selection can't trip the same error.
  • handleErrors — maps "only get data from the last 90 days" to a clear, user-facing message instead of the generic Unknown Error.

Note / trade-off

This is a Pinterest limitation, not something we can widen: pin metrics older than ~90 days simply aren't available from their API. Posts older than that will return only the recent-window data — expected behavior. After this change the error logs stop and analytics populate for in-window posts.

🤖 Generated with Claude Code

Pinterest analytics endpoints only serve the last 90 days (evaluated in UTC).
`postAnalytics` requested `start_date` 2 years ago, so every pin-analytics call
failed with "You can only get data from the last 90 days", surfacing in prod as:
  Error fetching Pinterest post analytics: ApplicationFailure: Unknown Error
(the generic "Unknown Error" is BadBody's default; Pinterest's real message was
in the failure details).

Changes:
- postAnalytics: start_date now 89 days back instead of 2 years. Pinterest does
  not expose pin metrics older than 90 days, so 89 is the maximum obtainable;
  89 (not 90) avoids an off-by-one when the server's local date leads UTC.
- analytics (account level): clamp the requested period to <= 89 days for the
  same reason, so a longer UI selection can't trip the same error.
- handleErrors: map "only get data from the last 90 days" to a clear message
  instead of the generic "Unknown Error".

Introduced in 5cca81e ("feat: post analytics").

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@postiz-contribution postiz-contribution Bot added the contribution:approved Approved contributor label Jul 1, 2026
@postiz-contribution

Copy link
Copy Markdown

Contribution-checker quality warning
Heuristic score: 0/100 (low). This is a non-blocking warning surfaced by the project's quality settings.

Heuristics that flagged:

  • Excessive inline code references: 15 inline refs (>3)
  • PR doesn't use the repo's PR template: 5 required checkbox items missing (max 1, match ≥80%)
  • Body adds too many extra headers beyond the template: 3 extra headers (>1)
  • AI watermark phrase: Matched: "Generated with Claude Code"
  • Commit message too long: Longest: 1091 chars
  • Excessive added comments: 7 added comment lines (ratio 0.70)

If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it.

@postiz-agent

postiz-agent Bot commented Jul 1, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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

Labels

contribution:approved Approved contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant