Skip to content

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

Merged
nevo-david merged 1 commit into
mainfrom
fix/pinterest-analytics-90-day-clamp
Jul 15, 2026
Merged

fix(pinterest): keep analytics within the 90-day window#1726
nevo-david merged 1 commit into
mainfrom
fix/pinterest-analytics-90-day-clamp

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, so the call failed every time and pin analytics were always empty. Introduced in 5cca81e0 ("feat: post analytics").

Changes

  • postAnalyticsstart_date is now 89 days back instead of 2 years (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.

Replaces #1665: per review there, analytics shouldn't be coupled to this.fetch/handleErrors, so the handleErrors mapping is dropped — #1725 decouples analytics from this.fetch across all providers.

Pin metrics older than ~90 days simply aren't available from Pinterest's API; older posts return only the recent-window data.

🤖 Generated with Claude Code

Pinterest's analytics endpoints only serve the last 90 days (evaluated
in UTC). postAnalytics requested a 2-year start_date, so Pinterest
rejected the call every time and pin analytics were always empty.

Clamp postAnalytics to 89 days back and cap the account-level analytics
period at 89 days (89 avoids an off-by-one when the server's local date
leads UTC).

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

Copy link
Copy Markdown

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

Heuristics that flagged:

  • Excessive inline code references: 13 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: 2 extra headers (>1)
  • AI watermark phrase: Matched: "Generated with Claude Code"
  • Commit message too long: Longest: 473 chars

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 14, 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.

Comment on lines +462 to +463
// Pinterest only serves pin analytics for the last 90 days (89 for a UTC safety margin)
const since = dayjs().subtract(89, 'day').format('YYYY-MM-DD');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The postAnalytics method for Pinterest hardcodes the analytics date range to 89 days, ignoring the user-selected date parameter from the frontend.
Severity: MEDIUM

Suggested Fix

Modify the postAnalytics method to respect the date parameter when calculating the since date. The implementation should be similar to the analytics method, using dayjs().subtract(Math.min(date, 89), 'day') to ensure the user's selection is used, capped at the 89-day limit imposed by the API.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts#L462-L463

Potential issue: The `postAnalytics()` method in the Pinterest provider consistently
ignores the `date` parameter passed from the frontend, instead hardcoding the analytics
window to 89 days. When a user requests analytics for a shorter period, such as 7 or 30
days, the API call still fetches data for the last 89 days. This is inconsistent with
the account-level `analytics()` method, which correctly respects the user's date
selection. As a result, the UI will display pin-level analytics aggregated over an
89-day period, regardless of the user's chosen date range, leading to incorrect data
representation.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

This method only reads lifetime_metrics, which Pinterest computes over the pin's whole lifetime regardless of start_date/end_date - so clamping to the user's date would return identical numbers. The window just has to satisfy the API's 90-day validity limit, hence the fixed 89 days (also keeps the request valid for unvalidated date values from the public API). The range-respecting view is the account-level analytics().

@nevo-david nevo-david merged commit bccbc08 into main Jul 15, 2026
11 checks passed
@nevo-david nevo-david deleted the fix/pinterest-analytics-90-day-clamp branch July 15, 2026 05:27
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.

2 participants