Skip to content

Davidgu/analyticsroutes premerge - #218

Merged
UZ9 merged 9 commits into
mainfrom
davidgu/analyticsroutes-premerge
Oct 25, 2025
Merged

UZ9 merged 9 commits into
mainfrom
davidgu/analyticsroutes-premerge

Conversation

@UZ9

@UZ9 UZ9 commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

PR created for merging visibility

@greptile-apps greptile-apps 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.

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

Greptile Overview

Greptile Summary

This PR adds analytics data retrieval capabilities to the Juno platform by implementing 10 new viewer endpoints that expose read-only access to analytics events (click, visit, input, and custom events) through both the gRPC analytics service and REST API gateway.

Key Changes:

  • Added AnalyticsViewerService extending bog-analytics SDK's AnalyticsViewer class for read operations
  • Implemented 11 new service methods with pagination support and proper authentication/validation
  • Created proto definitions for all new RPC endpoints with corresponding auto-generated TypeScript types
  • Exposed 10 REST endpoints in API gateway with comprehensive OpenAPI documentation
  • Added complete test coverage for both analytics service and API gateway
  • All endpoints require API key authentication for security

Minor Issues Found:

  • Typo in method name: getCustomGraphTypesbyId should be getCustomGraphTypesById (line 264 in analytics.service.ts)
  • TODO comment indicates hardcoded DEVELOPMENT environment needs production configuration

Confidence Score: 4/5

  • This PR is safe to merge with one minor typo fix needed
  • Score reflects well-structured implementation with comprehensive test coverage and proper validation/authentication patterns. The typo in the method name will cause a runtime error when calling getCustomGraphTypesById, preventing this specific endpoint from working correctly. All other endpoints follow consistent patterns and should work properly. The hardcoded DEVELOPMENT environment is noted but acceptable for initial implementation.
  • packages/analytics-service/src/modules/analytics/analytics.service.ts requires a one-character fix to correct the method name typo on line 264

Important Files Changed

File Analysis

Filename Score Overview
packages/proto/definitions/analytics.proto 5/5 Added proto definitions for analytics viewer methods (10 new RPC endpoints for retrieving analytics data with pagination support)
packages/analytics-service/src/modules/analytics/analytics.module.ts 4/5 Configured AnalyticsViewerService provider with DEVELOPMENT environment (TODO comment notes this needs to be updated for production)
packages/analytics-service/src/modules/analytics/analytics.service.ts 3/5 Implemented 11 analytics viewer methods with validation and authentication; contains typo in method name getCustomGraphTypesbyId (should be getId with capital B)
packages/api-gateway/src/models/analytics.dto.ts 5/5 Added DTO classes for all new analytics viewer endpoints with proper validation decorators and Swagger documentation
packages/api-gateway/src/modules/analytics/analytics.controller.ts 5/5 Added 10 REST endpoints (GET routes) for analytics data retrieval with proper OpenAPI decorations and validation

Sequence Diagram

sequenceDiagram
    participant Client
    participant APIGateway as API Gateway<br/>(REST)
    participant AnalyticsService as Analytics Service<br/>(gRPC)
    participant BogAnalytics as bog-analytics SDK<br/>(AnalyticsViewer)
    participant Database as MongoDB

    Note over Client,Database: Analytics Data Retrieval Flow

    Client->>APIGateway: GET /analytics/events/click?projectName=X
    APIGateway->>APIGateway: Validate API Key
    APIGateway->>APIGateway: Validate Query Params
    APIGateway->>AnalyticsService: gRPC getClickEventsPaginated(request)
    AnalyticsService->>AnalyticsService: authenticateViewer(apiKey)
    AnalyticsService->>AnalyticsService: Validate projectName
    AnalyticsService->>BogAnalytics: getClickEventsPaginated(queryParams)
    BogAnalytics->>Database: Query click events
    Database-->>BogAnalytics: Return events + pagination cursor
    BogAnalytics-->>AnalyticsService: Return events array
    AnalyticsService->>AnalyticsService: Transform dates to ISO strings
    AnalyticsService-->>APIGateway: Return GetClickEventsResponse
    APIGateway->>APIGateway: Map to DTO
    APIGateway-->>Client: Return JSON response

    Note over Client,Database: Similar flow for Visit, Input, and Custom Events

    Client->>APIGateway: GET /analytics/custom-event-types?projectName=X
    APIGateway->>AnalyticsService: gRPC getCustomEventTypes(request)
    AnalyticsService->>BogAnalytics: getCustomEventTypes(projectName)
    BogAnalytics->>Database: Query event type definitions
    Database-->>BogAnalytics: Return event types
    BogAnalytics-->>AnalyticsService: Return event type array
    AnalyticsService-->>APIGateway: Return first event type
    APIGateway-->>Client: Return CustomEventTypeResponse
Loading

12 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread packages/analytics-service/src/modules/analytics/analytics.service.ts Outdated
}

// Return the first custom event type for now
const eventType = response[0];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only returns first type; this should be all types

@UZ9

UZ9 commented Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

Analytics tests will be rewritten during sprint day; critical functions tested by hand

@UZ9
UZ9 merged commit 3f72e11 into main Oct 25, 2025
6 of 8 checks passed
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