Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: Fix for styling issue #2508

Merged
merged 3 commits into from
Feb 24, 2025
Merged

Website: Fix for styling issue #2508

merged 3 commits into from
Feb 24, 2025

Conversation

OchiengPaul442
Copy link
Contributor

@OchiengPaul442 OchiengPaul442 commented Feb 24, 2025

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • New Features
    • Enhanced analytics integration ensures that tracking is activated consistently across the site for improved engagement insights.
  • Refactor
    • Streamlined event tracking functionality across interactive elements for greater clarity and maintainability.
    • Updated Google Analytics integration to load dynamically on the client side, improving performance and reliability.

Copy link

coderabbitai bot commented Feb 24, 2025

📝 Walkthrough

Walkthrough

This pull request updates the integration of Google Analytics across the site. In the RootLayout, the GA component is now imported as a dynamic import and rendered unconditionally at the end of the body instead of conditionally in the head. In the GoogleAnalytics component, optional properties have been added to the global interface, and the GA script loading is now managed via Next.js’s Script component. Additionally, the event tracking function, trackEvent, has been refactored to accept a single object parameter, and its usage across multiple components has been updated accordingly.

Changes

File(s) Change Summary
website2/src/app/layout.tsx Updated GA integration: switched to dynamic import and moved GA component from conditional head rendering to unconditional rendering at the end of <body>.
website2/src/components/GoogleAnalytics.tsx Made gtag, dataLayer, and measurementId optional; switched to using Next.js Script for controlled script loading; refactored trackEvent signature.
website2/src/components/layouts/{Navbar.tsx, NotificationBanner.tsx} &
website2/src/views/home/HomePlayerSection.tsx
Refactored calls to trackEvent from separate arguments to a single object parameter with named properties (action, category, label).

Sequence Diagram(s)

sequenceDiagram
    participant Browser as User
    participant Layout as RootLayout
    participant GA as GoogleAnalytics Component
    participant ScriptLoader as Next.js Script

    Browser->>Layout: Loads page
    Layout->>GA: Renders GA component unconditionally
    GA->>ScriptLoader: Loads GA initialization script
    ScriptLoader-->>GA: Script execution completes
    Browser->>GA: Triggers UI event (e.g., button click)
    GA->>GA: Executes `trackEvent({ action, category, label })`
Loading

Possibly related PRs

Suggested labels

ready for review

Suggested reviewers

  • Baalmart
  • Codebmk

Poem

In lines of code both crisp and clear,
Analytics now stand open, ever near.
From head to body they freely roam,
Tracking events like whispers from home.
A code journey marked with clever cheer!
🚀✨

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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 or @coderabbitai title 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
website2/src/components/GoogleAnalytics.tsx (3)

8-11: Consider strengthening type definitions.

While making the Window interface properties optional is good practice, using Record<string, any> and (...args: any[]) reduces type safety. Consider using more specific types:

interface Window {
-  dataLayer?: Record<string, any>[];
+  dataLayer?: Array<{
+    [key: string]: string | number | boolean | null;
+  }>;
-  gtag?: (...args: any[]) => void;
+  gtag?: (
+    command: 'event' | 'config' | 'js',
+    target: string,
+    params?: Record<string, string | number | boolean | null>
+  ) => void;
}

Also applies to: 14-16


29-35: Consider adding error logging.

The defensive checks are good, but consider logging errors in development to help debug GA integration issues.

  if (
    typeof window === 'undefined' ||
    !measurementId ||
    typeof window.gtag === 'undefined'
  ) {
+   if (process.env.NODE_ENV === 'development') {
+     console.warn('Google Analytics disabled:', {
+       reason: !measurementId ? 'Missing measurementId' : 'gtag not loaded'
+     });
+   }
    return;
  }

76-94: Consider type improvements for event tracking.

The object parameter pattern is good, but the function could benefit from some type improvements:

+ type TrackEventParams = {
+   action: string;
+   category: string;
+   label: string;
+   value?: number;
+ };

- export function trackEvent({
+ export function trackEvent(params: TrackEventParams): void {
-  action,
-  category,
-  label,
-  value,
- }: {
-  action: string;
-  category: string;
-  label: string;
-  value?: number;
- })

  const { action, category, label, value } = params;

Also consider creating constants for common event categories to ensure consistency:

export const GA_CATEGORIES = {
  NAVIGATION: 'navigation',
  INTERACTION: 'interaction',
  // ... other categories
} as const;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ff3a7c4 and 3ab722a.

📒 Files selected for processing (5)
  • website2/src/app/layout.tsx (2 hunks)
  • website2/src/components/GoogleAnalytics.tsx (1 hunks)
  • website2/src/components/layouts/Navbar.tsx (2 hunks)
  • website2/src/components/layouts/NotificationBanner.tsx (1 hunks)
  • website2/src/views/home/HomePlayerSection.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-push-website2-deploy-preview
🔇 Additional comments (6)
website2/src/app/layout.tsx (1)

7-7:

❓ Verification inconclusive

Verify Google Analytics script loading behavior.

Moving the GA component to the end of the body and removing conditional rendering simplifies the integration. However, we should verify that this placement doesn't affect tracking of early user interactions.

Also applies to: 56-58


🏁 Script executed:

#!/bin/bash
# Check if GA script is loaded with correct attributes
ast-grep --pattern 'Script $props'

Length of output: 36


Verify that the GA script is properly configured for early interaction tracking.

The recent change moves the component to the end of the body and removes conditional rendering, which simplifies the integration. However, since our initial AST-based check didn’t return any script verification output, please manually verify that the <Script> component (or equivalent) within the GA component is loaded with the correct attributes (e.g., proper loading strategy) so that no early user interactions are missed.

  • Action Items:
    • Confirm that the GA script is injected at the desired location in the rendered body (in website2/src/app/layout.tsx).
    • Verify in website2/src/components/GoogleAnalytics.tsx that the <Script> (or similar) component includes all necessary attributes to ensure early tracking if needed.
website2/src/components/layouts/Navbar.tsx (1)

275-279: LGTM! Consistent event tracking implementation.

The refactored event tracking calls using object format improve code readability and maintainability.

Also applies to: 289-293

website2/src/components/layouts/NotificationBanner.tsx (1)

17-21: LGTM! Consistent event tracking implementation.

The refactored event tracking call using object format aligns with the new pattern and improves code clarity.

website2/src/views/home/HomePlayerSection.tsx (1)

217-221: LGTM! Consistent event tracking implementation.

The refactored event tracking calls using object format maintain consistency across components and improve code maintainability.

Also applies to: 226-230

website2/src/components/GoogleAnalytics.tsx (2)

55-68: LGTM! Good script loading implementation.

Using afterInteractive strategy and separating the initialization script is the recommended approach for GA in Next.js.


1-94: Verify PR title and description accuracy.

The PR is titled "Website: Fix for styling issue" but contains significant changes to Google Analytics implementation. Consider updating the PR title and description to accurately reflect these changes.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
website2/src/app/layout.tsx (2)

15-18: Consider adding error handling for dynamic import.

The dynamic import setup looks good and follows Next.js best practices. However, consider wrapping the dynamic import in an error boundary to gracefully handle loading failures.

const GoogleAnalytics = dynamic(() => import('@/components/GoogleAnalytics'), {
  ssr: false,
+ loading: () => null,
});

42-42: Enhance environment variable validation.

While the fallback to empty string works, consider adding runtime validation to ensure the GA measurement ID is properly configured in the environment.

- const GA_MEASUREMENT_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID || '';
+ const GA_MEASUREMENT_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID;
+ 
+ if (!GA_MEASUREMENT_ID && process.env.NODE_ENV === 'production') {
+   console.warn('Google Analytics Measurement ID is not configured');
+ }

Also applies to: 63-65

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab722a and f89debe.

📒 Files selected for processing (1)
  • website2/src/app/layout.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-push-website2-deploy-preview
🔇 Additional comments (1)
website2/src/app/layout.tsx (1)

36-69: Well-structured implementation with proper error handling and loading states!

The RootLayout implementation demonstrates good practices:

  • Error boundaries for fault tolerance
  • Suspense for loading states
  • Clean conditional rendering
  • Type safety with TypeScript

@Baalmart Baalmart merged commit 9d1cec2 into staging Feb 24, 2025
30 of 31 checks passed
@Baalmart Baalmart deleted the website-content-updates2 branch February 24, 2025 08:18
@Baalmart Baalmart mentioned this pull request Feb 24, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants