Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ export class PinterestProvider
date: number
): Promise<AnalyticsData[]> {
const until = dayjs().format('YYYY-MM-DD');
const since = dayjs().subtract(date, 'day').format('YYYY-MM-DD');
// Pinterest analytics only cover the last 90 days (89 for a UTC safety margin)
const since = dayjs()
.subtract(Math.min(date, 89), 'day')
.format('YYYY-MM-DD');

const {
all: { daily_metrics },
Expand Down Expand Up @@ -456,8 +459,8 @@ export class PinterestProvider
date: number
): Promise<AnalyticsData[]> {
const today = dayjs().format('YYYY-MM-DD');
// Use a very long date range (2 years) to capture lifetime metrics for older posts
const since = dayjs().subtract(2, 'year').format('YYYY-MM-DD');
// 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');
Comment on lines +462 to +463

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().


try {
// Fetch pin analytics from Pinterest API
Expand Down
Loading