Skip to content

Added static Newsletters tab to Post Analytics - #23231

Merged
peterzimon merged 10 commits into
mainfrom
ta-newsletters-post-analytics
May 7, 2025
Merged

peterzimon merged 10 commits into
mainfrom
ta-newsletters-post-analytics

Conversation

@peterzimon

Copy link
Copy Markdown
Contributor

@coderabbitai

coderabbitai Bot commented May 7, 2025 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@peterzimon has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 45 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f22ba2c83084da5f8ad71d7629d0585e8dbdc653 and b9224d1.

⛔ Files ignored due to path filters (1)
  • ghost/admin/public/assets/icons/stats-newsletter.svg is excluded by !**/*.svg
📒 Files selected for processing (16)
  • apps/posts/src/routes.tsx (2 hunks)
  • apps/posts/src/views/PostAnalytics/Growth.tsx (2 hunks)
  • apps/posts/src/views/PostAnalytics/Newsletter.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/Web.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/components/KpiCard.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/components/PostAnalyticsContent.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/components/Sidebar.tsx (2 hunks)
  • apps/posts/src/views/PostAnalytics/components/Web/Kpis.tsx (1 hunks)
  • apps/shade/src/components/ui/tabs.tsx (2 hunks)
  • apps/shade/styles.css (2 hunks)
  • apps/stats/src/views/Stats/Newsletters.tsx (2 hunks)
  • apps/stats/src/views/Stats/Web.tsx (1 hunks)
  • ghost/admin/app/components/posts/analytics.hbs (1 hunks)
  • ghost/admin/app/router.js (1 hunks)
  • ghost/admin/app/routes/posts/analytics/newsletter-stats.js (1 hunks)
  • ghost/admin/app/styles/layouts/content.css (2 hunks)

Walkthrough

This change introduces a new "Newsletter" analytics view to the post analytics section of the application. It adds a new route (analytics/:postId/newsletter) and corresponding React component (Newsletter) that displays newsletter-specific KPIs, a comparative bar chart, and an editable table of email click links. The sidebar navigation is updated to include a "Newsletter" link. Several UI components are restyled or refactored, including KPI cards and tab layouts, and a new CSS variable for chart colors is added. Parallel updates are made in the Ember admin app to support the new newsletter analytics route and sidebar link.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (8)
apps/stats/src/views/Stats/Newsletters.tsx (1)

329-348: Consider adding a comment explaining the commented-out mock data.

You've commented out several mock newsletter entries, reducing the dataset from 20 to 12 items. It would be helpful to add a brief comment explaining why some entries are commented out (e.g., for performance, visual simplicity, or testing purposes).

Also, I notice the dates have been updated from March 2024 to April 2025, which ensures the data appears current during development and testing.

apps/posts/src/views/PostAnalytics/Newsletter.tsx (7)

10-10: Empty interface should be replaced with a type alias.

The empty interface postAnalyticsProps doesn't add any value and could be simplified.

-interface postAnalyticsProps {}
+type PostAnalyticsProps = Record<string, never>;

Also, consider following the PascalCase naming convention for types and interfaces.

🧰 Tools
🪛 Biome (1.9.4)

[error] 9-10: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)


16-16: Apply PascalCase for component props type.

Component props types should follow PascalCase convention.

-const Newsletter: React.FC<postAnalyticsProps> = () => {
+const Newsletter: React.FC<PostAnalyticsProps> = () => {

22-24: Commented-out code should be removed or implemented.

There are several commented-out lines that appear to be placeholders for future API integration. Consider either implementing these or adding more descriptive TODO comments if they're meant to be implemented later.

-    // const {isLoading: isConfigLoading} = useGlobalData();
-    // const {postId} = useParams();
-    // const {stats: postReferrers, totals, isLoading} = usePostReferrers(postId || '');
+    // TODO: Implement API integration for loading post data
+    // Will use: 
+    // - useGlobalData() for configuration
+    // - useParams() to get postId
+    // - usePostReferrers() to fetch referrer stats

26-37: URL editing functionality is incomplete.

The handleEdit method sets up state for editing, but handleUpdate only resets state without actually updating anything. This matches the TODO comment on line 32, but should be completed for full functionality.

Would you like me to help implement a more complete version of this functionality that would work with an API?


60-60: Loading state is hardcoded.

The isLoading state is hardcoded to false instead of being derived from actual API calls. This is fine for a static implementation, but should be replaced when integrating with real data.

-    const isLoading = false;
+    // TODO: Replace with actual loading state when API integration is added
+    const isLoading = false; // Temporary static value

107-107: Consider adding a proper loading state UI.

The loading state is just displaying "Loading" text. Consider using a more user-friendly loading indicator or skeleton UI.

-                {isLoading ? 'Loading' :
+                {isLoading ? (
+                    <div className="flex flex-col items-stretch gap-6">
+                        <Card>
+                            <CardContent className="flex flex-col items-center justify-center py-20">
+                                <LucideIcon.Loader className="mb-4 size-10 animate-spin text-muted-foreground" />
+                                <p className="text-muted-foreground">Loading newsletter analytics...</p>
+                            </CardContent>
+                        </Card>
+                    </div>
+                ) :

222-256: URL editing UX could be improved.

The URL editing implementation could benefit from some UX improvements:

  1. There's no way to cancel editing other than clicking outside
  2. No validation is performed on the edited URL
  3. The input field doesn't maintain the full URL format (with protocol)

Consider adding:

  1. A cancel button next to the update button
  2. Basic URL validation
  3. Consistent URL format handling
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5b8882 and f22ba2c83084da5f8ad71d7629d0585e8dbdc653.

⛔ Files ignored due to path filters (1)
  • ghost/admin/public/assets/icons/stats-newsletter.svg is excluded by !**/*.svg
📒 Files selected for processing (14)
  • apps/posts/src/routes.tsx (2 hunks)
  • apps/posts/src/views/PostAnalytics/Growth.tsx (2 hunks)
  • apps/posts/src/views/PostAnalytics/Newsletter.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/Web.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/components/KpiCard.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/components/Sidebar.tsx (1 hunks)
  • apps/posts/src/views/PostAnalytics/components/Web/Kpis.tsx (1 hunks)
  • apps/shade/src/components/ui/tabs.tsx (2 hunks)
  • apps/shade/styles.css (2 hunks)
  • apps/stats/src/views/Stats/Newsletters.tsx (2 hunks)
  • apps/stats/src/views/Stats/Web.tsx (1 hunks)
  • ghost/admin/app/components/posts/analytics.hbs (1 hunks)
  • ghost/admin/app/router.js (1 hunks)
  • ghost/admin/app/routes/posts/analytics/newsletter-stats.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/posts/src/views/PostAnalytics/Growth.tsx (2)
apps/shade/src/components/ui/card.tsx (5)
  • Card (153-153)
  • CardHeader (153-153)
  • CardTitle (153-153)
  • CardDescription (153-153)
  • CardContent (153-153)
apps/posts/src/views/PostAnalytics/components/KpiCard.tsx (4)
  • KpiCardIcon (4-10)
  • KpiCardContent (12-18)
  • KpiCardLabel (20-26)
  • KpiCardValue (28-34)
🪛 Biome (1.9.4)
apps/posts/src/views/PostAnalytics/Newsletter.tsx

[error] 9-10: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Unit tests (Node 22.13.1)
  • GitHub Check: Unit tests (Node 20.11.1)
  • GitHub Check: Lint
  • GitHub Check: Admin tests - Chrome
🔇 Additional comments (26)
apps/shade/styles.css (2)

57-57: LGTM: New chart color variable addition for light mode

The addition of the --chart-gray variable provides a consistent way to style chart elements. This aligns well with the existing chart color variables.


98-98: LGTM: Consistent dark mode implementation

The dark mode implementation of --chart-gray maintains consistency with the light mode version, using an appropriate darkness value that should maintain sufficient contrast in dark theme.

apps/posts/src/views/PostAnalytics/components/KpiCard.tsx (5)

6-10: LGTM: Improved KpiCardIcon styling

The icon container has been restyled with better spacing, sizing, and alignment properties. The use of square dimensions (size-11) and flex layout ensures consistent icon presentation.


12-18: LGTM: New KpiCardContent component

Good addition of a dedicated content wrapper component with a flex column layout. This provides better structure and reusability for the KPI card content.


22-22: LGTM: Improved label styling

The label styling has been refined with appropriate text size, color, and weight properties for better readability.


30-30: LGTM: Enhanced value display

The value styling has been enhanced with better typography properties including tracking, leading, and font weight that should make the numbers more prominent.


38-38: LGTM: Improved main container layout

The main KpiCard container has been restyled as a flex container with better spacing, border, and padding properties. This creates a more consistent and clean appearance.

apps/posts/src/views/PostAnalytics/Web.tsx (1)

66-66: LGTM: Reduced grid gap for better layout

The reduction in grid gap from gap-8 to gap-6 creates a more compact layout between Sources and Locations components, which should improve the visual relationship between these related elements.

apps/posts/src/views/PostAnalytics/components/Web/Kpis.tsx (1)

111-111: LGTM: Reduced grid column count

Changing from grid-cols-4 to grid-cols-2 adjusts the layout to focus on the two main metrics (visitors and pageviews). This aligns with similar grid column reductions in related components for consistent UI presentation.

apps/stats/src/views/Stats/Web.tsx (1)

128-128: Grid column count updated for UI consistency.

The TabsList grid layout was changed from 4 columns to 2 columns, which aligns with similar grid adjustments in other KPI components. This change maintains a consistent UI appearance across the application.

apps/posts/src/views/PostAnalytics/components/Sidebar.tsx (1)

25-30: New Newsletter tab added to the sidebar navigation.

The Newsletter tab has been properly added to the sidebar with consistent styling and navigation handling. It follows the same pattern as other navigation links, using the appropriate mail icon and correct path structure.

ghost/admin/app/components/posts/analytics.hbs (1)

277-279: New Newsletter link added to the Ember admin sidebar.

The Newsletter analytics link has been correctly implemented in the Ember admin sidebar, maintaining consistency with the React implementation. The SVG icon and route naming follow the established pattern of the other analytics sidebar items.

apps/posts/src/routes.tsx (2)

2-2: Newsletter component import added.

The Newsletter component is properly imported from the correct path.


30-34: New route configuration for Newsletter analytics.

The route configuration for the Newsletter analytics view has been correctly implemented following the established pattern of other analytics routes. It uses the appropriate path structure and renders the Newsletter component.

ghost/admin/app/router.js (1)

40-40: Great addition of the newsletter-stats route!

The new route follows existing patterns, keeping the same template and component naming conventions as sibling routes. This ensures consistency in the codebase.

ghost/admin/app/routes/posts/analytics/newsletter-stats.js (1)

1-10: Clean implementation of the NewsletterStatsRoute class.

The route implementation correctly extends the base AnalyticsRoute class and follows the same rendering pattern as sibling analytics routes. This maintains consistency in how templates are rendered across the analytics section.

apps/stats/src/views/Stats/Newsletters.tsx (1)

253-253: Good UI enhancement with maxBarSize.

Adding a maximum size for the bars improves the visual consistency of the chart across different data sets.

apps/posts/src/views/PostAnalytics/Growth.tsx (2)

1-1: Good update to include KpiCardContent in imports.

The import has been properly updated to include the new KpiCardContent component.


30-66: Nice refactoring of the KPI cards layout.

The KPI cards section has been refactored to use a more structured component hierarchy, with a Card wrapper and nested KpiCardContent components. This improves:

  1. Consistency with the newly added Newsletter tab
  2. Better semantic structure with proper Card components
  3. Clearer separation of concerns between container and content

The icon update from Wallet to WalletCards is also a good improvement for visual clarity.

apps/shade/src/components/ui/tabs.tsx (2)

51-51: Simplified and more consistent styling for KPI tabs.

The padding and spacing for KPI tabs lists has been streamlined to a cleaner gap-1 with p-3 padding. This change helps maintain consistent spacing in the analytics views.


83-83: Improved hover and active states for KPI tabs.

The styling has been simplified and improved by:

  • Removing the shadow effect on active state
  • Changing from background-based to muted-based colors for hover and active states
  • Adding proper rounded corners for better visual consistency

These changes align well with the broader UI updates in the Newsletter analytics feature.

apps/posts/src/views/PostAnalytics/Newsletter.tsx (5)

64-77: Well-structured chart configuration.

The chart data and configuration are well-organized and follow good practices:

  • Clear separation of data and configuration
  • Type safety with satisfies ChartConfig
  • Consistent color variables using CSS custom properties

This structure will make it easy to replace with dynamic data later.


79-96: Mock data follows a good structure for future API integration.

The mock data for links is structured in a way that will make it easy to replace with real API data later. The structure is clear and includes all necessary fields.


144-198: Accessibility improvements for chart component.

The chart implementation includes good accessibility features like:

  • Using the accessibilityLayer prop on the BarChart
  • Proper formatting of percentages
  • Clear tooltips with descriptive content

This is excellent for maintaining an accessible application.


12-14: URL sanitization function is simple and effective.

The sanitizeUrl function effectively removes protocol prefixes for cleaner display while preserving the actual URL for linking. This is a good approach.


115-143: KPI card layout is well-structured and consistent.

The KPI cards are well-implemented with:

  • Clear separation of icon, label, and value
  • Consistent styling and spacing
  • Appropriate icons for each metric
  • Proper number formatting

This provides a clear and concise summary of newsletter performance metrics.

Comment on lines 248 to 263

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Security improvement: Add noopener to external links.

When opening links in new tabs with target="_blank", it's recommended to include both noopener and noreferrer for security reasons.

<a
    className='inline-flex items-center gap-2 font-medium hover:underline'
    href={row.url}
-   rel="noreferrer"
+   rel="noreferrer noopener"
    target='_blank'
>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
className='inline-flex items-center gap-2 font-medium hover:underline'
href={row.url}
rel="noreferrer"
target='_blank'
>
<span>{sanitizeUrl(row.url)}</span>
</a>
<a
className='inline-flex items-center gap-2 font-medium hover:underline'
href={row.url}
rel="noreferrer noopener"
target='_blank'
>
<span>{sanitizeUrl(row.url)}</span>
</a>

@peterzimon
peterzimon force-pushed the ta-newsletters-post-analytics branch from a975fe4 to a4d5edf Compare May 7, 2025 17:31
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.

1 participant