Skip to content

Fixed data inconsistency in Post Analytics > Overview tab#24558

Merged
cmraible merged 1 commit intomainfrom
fix-post-analytics-overview-inconsistency
Jul 30, 2025
Merged

Fixed data inconsistency in Post Analytics > Overview tab#24558
cmraible merged 1 commit intomainfrom
fix-post-analytics-overview-inconsistency

Conversation

@cmraible
Copy link
Copy Markdown
Collaborator

@cmraible cmraible commented Jul 30, 2025

ref https://linear.app/ghost/issue/PROD-2243/inconsistency-in-the-post-analytics-overview-data-compared-to-post

On the Post Analytics > Overview tab, the top level metric shown for unique visitors and the sum of the actual data in the chart can show different values. The metric and the chart are using separate requests to the same API endpoint with different date_from parameters, resulting in slightly different numbers, i.e. it's possible to see "1 unique visitor" but with 0 for every data point on the chart:

image

This fixes that by removing the duplicate API call, so the data for the metric and the chart use the same exact underlying data.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

The changes in the code remove the extraction of unused date and timezone variables and consolidate two sets of query parameters into a single params object for both KPI overview and chart data. The code eliminates the separate query and state variables for KPI data, updating all references to use the unified chart data variables. The calculation of total visitors and loading states is adjusted to use the new unified data and loading variables. The overall data fetching logic is simplified by using one parameter set and one query instead of two.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fda5776 and 219d13c.

📒 Files selected for processing (1)
  • apps/posts/src/views/PostAnalytics/Overview/Overview.tsx (3 hunks)
🔇 Additional comments (4)
apps/posts/src/views/PostAnalytics/Overview/Overview.tsx (4)

35-35: LGTM! Comment accurately reflects the unified parameter approach.

The updated comment correctly documents that the same parameters are now used for both chart and KPI data, which aligns with the PR objective of fixing data inconsistencies.


58-58: Excellent fix for the data inconsistency issue.

Using the unified params ensures that both KPI metrics and chart data use the same date range, directly addressing the inconsistency where "Unique Visitors" metric was using all-time data while the chart filtered from post.published_at.


63-70: Correct variable references after data source consolidation.

The changes from data to chartData are consistent with the unified approach. The total visitors calculation logic remains correct and now uses the same data source as the chart, ensuring consistency.


91-91: Proper loading state update after query consolidation.

Updating kpiIsLoading to use chartLoading is correct since the separate query and its tbLoading state were removed. This maintains proper loading behavior with the unified data source.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-post-analytics-overview-inconsistency

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines -76 to -81
const {data, loading: tbLoading} = useTinybirdQuery({
endpoint: 'api_kpis',
statsConfig: statsConfig || {id: ''},
params: params
});

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.

TL;DR: the "Unique Visitors" metric was using the value from this API call, which used the all time data, but the chart filtered from the post.published_at timestamp.

Since some "unique visitors" can be attributed to the day before the post.published_at timestamp, this resulted in different data for the metric than the chart.

@cmraible
Copy link
Copy Markdown
Collaborator Author

This fixes the inconsistency on the Post Analytics > Overview tab itself, and between the Overview <> Web Traffic tabs. It does not fix the fact that a "unique visitor" can be attributed to the day before a post is published, since we use the first pageview of the visit to define its timestamp. This is a stickier issue to solve, but this at least makes it less obvious to a user.

@cmraible cmraible marked this pull request as ready for review July 30, 2025 05:12
@cmraible cmraible requested a review from 9larsons July 30, 2025 05:16
@cmraible cmraible changed the title Fixed inconsistency in Post Analytics > Overview Fixed data inconsistency in Post Analytics > Overview tab Jul 30, 2025
@cmraible cmraible merged commit ac10801 into main Jul 30, 2025
23 checks passed
@cmraible cmraible deleted the fix-post-analytics-overview-inconsistency branch July 30, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants