Skip to content

34849 frontend work#35513

Open
nicobytes wants to merge 16 commits intomainfrom
34849-frontend-work
Open

34849 frontend work#35513
nicobytes wants to merge 16 commits intomainfrom
34849-frontend-work

Conversation

@nicobytes
Copy link
Copy Markdown
Member

This pull request migrates the analytics data access layer from the legacy CubeJS-based endpoints to the new analytics event API, refactoring the service and store logic to use the new endpoints and data structures. It introduces new API methods, updates state types, and simplifies data mapping throughout the analytics feature. Additionally, it adds robust health check logic for analytics availability.

Migration to new analytics event API:

  • Refactored the DotAnalyticsService to add methods for fetching analytics data (getTotalEvents, getUniqueVisitors, getTopContent, getPageviewsByDeviceBrowser) from the new event-based endpoints, replacing CubeJS queries. These methods support both predefined ranges and custom date ranges, and map the API responses to the expected data types. [1] [2]
  • Updated the store feature (with-pageview.feature.ts) to use the new service methods for all analytics data fetches, removing CubeJS query construction and mapping API responses to the store state. [1] [2] [3] [4] [5] [6]

State and type updates:

  • Changed the types in the PageviewState interface to use the new API data structures (e.g., TotalEventsByDayData[], TopContentData[]) instead of the old CubeJS entity types.
  • Updated utility functions and mapping logic to handle the new API data shapes, including filling missing dates and converting time range options.

Health check improvements:

  • Added new health check methods (healthCheck, healthCheckWithCache, clearHealthCache) to DotAnalyticsService, allowing components to check analytics API availability with optional caching.
  • Extended the HealthStatusTypes enum to include AVAILABLE and NOT_AVAILABLE for finer-grained health status reporting.

Constants and mapping enhancements:

  • Introduced TIME_RANGE_API_MAPPING to map internal time range options to the new API's range parameter.

These changes collectively modernize the analytics data access layer, improve reliability, and prepare the codebase for future analytics enhancements.

freddyDOTCMS and others added 15 commits March 11, 2026 10:47
- Added new health status types: AVAILABLE and NOT_AVAILABLE to `HealthStatusTypes` enum.
- Implemented `healthCheck` and `healthCheckWithCache` methods in `DotAnalyticsService` to check analytics availability.
- Updated `analyticsHealthGuard` to use the new health check methods.
- Modified `DotAnalyticsErrorComponent` to include a retry button that clears the health cache and navigates back to the dashboard.
- Adjusted routes to use dynamic component loading for better performance.
- Enhanced error handling in the analytics error component.

This update improves the overall reliability and user experience of the analytics feature by providing real-time health status checks and a retry mechanism.
- Introduced `TIME_RANGE_API_MAPPING` for mapping internal time range options to the new analytics event API.
- Updated `DotAnalyticsService` to include a new method `getTotalEvents` for fetching total events from the new analytics event endpoint, supporting both predefined ranges and custom date queries.
- Modified `withPageview` feature to utilize the new `getTotalEvents` method instead of the previous CubeJS query approach.
- Added new types for handling analytics event responses, including `AnalyticsEventResponse`, `TotalEventsData`, and `TotalEventsByDayData`.
- Updated utility functions to convert time range inputs to the new API format.

These changes improve the analytics service by integrating with the new event API, enhancing data retrieval capabilities and overall performance.
- Added methods `getUniqueVisitors` and `getTopContent` to `DotAnalyticsService` for fetching unique visitors and top content data from the new analytics event API.
- Updated existing `getTotalEvents` method to utilize a new private method `#buildRangeParams` for cleaner parameter handling.
- Introduced new types for the analytics event API, including `ApiGranularity`, `ApiRangeParams`, `UniqueVisitorsData`, and `TopContentData`.
- Modified the `withPageview` feature to leverage the new API methods, improving data retrieval for unique visitors and top content.
- Updated utility functions to support the new data structures and ensure compatibility with the new API.

These changes enhance the analytics service by integrating additional data retrieval capabilities from the new event API, improving overall functionality and performance.
- Updated the `fillMissingApiDates` function in `analytics-data.utils.ts` to enhance code clarity.
- Replaced direct access to `dataMap` with a variable `existing` to simplify the conditional check for existing data.
- This change improves maintainability and readability of the code without altering its functionality.
- Added a new method `getPageviewsByDeviceBrowser` in `DotAnalyticsService` to fetch pageviews categorized by device and browser from the new analytics event API.
- Introduced the `DeviceBrowserData` type to represent the structure of the data returned by the new API.
- Updated the `withPageview` feature to utilize the new method, enhancing data retrieval for pageviews.
- Refactored utility functions to transform the new data structure for chart representation, improving the analytics dashboard's functionality.

These changes enhance the analytics service by integrating detailed device and browser analytics, providing better insights into user interactions.
…cture

- Replaced the `TopPerformanceTableEntity` with `TopContentData` across various files to align with the new analytics event API.
- Updated the `withPageview` feature to utilize the `getTopContent` method for fetching top content data, enhancing data retrieval.
- Modified utility functions and tests to accommodate the new data structure, ensuring compatibility and improving overall functionality.
- This refactor streamlines the analytics dashboard by providing a more consistent and efficient way to handle top page performance data.
@nicobytes
Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

# Conflicts:
#	dotCMS/src/main/java/com/dotcms/jitsu/validators/ValidationErrorCode.java
#	dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/content/ContentAnalyticsResource.java
#	dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/event/EventAnalyticsProxyHelper.java
#	dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/event/EventAnalyticsProxyResource.java

Co-authored-by: nicobytes <7611944+nicobytes@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 5d1aa7b. The conflicts were in 4 files:

  • ValidationErrorCode.java – kept main's javadoc for INVALID_JSON
  • ContentAnalyticsResource.java – accepted main's deletion (functionality moved to EventAnalyticsProxyResource)
  • EventAnalyticsProxyHelper.java – accepted main's URL encoding improvements for query params
  • EventAnalyticsProxyResource.java – accepted main's type-safety improvements for the context map

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates the Dot Analytics frontend data-access from legacy CubeJS queries to the new analytics event API (via new backend proxy endpoints), updating types, store logic, and health-check behavior.

Changes:

  • Added backend proxy endpoints under /v1/analytics/** to forward requests to the dot-ca-event-manager service, plus updated OpenAPI documentation.
  • Refactored the analytics frontend store/service/types to use the new event-based endpoints and data shapes.
  • Updated analytics routing/guard/error UI to use the new health-check flow and improved retry behavior.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml Replaces CubeJS endpoints/docs with proxy-based analytics paths.
dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/event/EventAnalyticsProxyResource.java Adds JAX-RS proxy resource for analytics GET forwarding and event ingest.
dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/event/EventAnalyticsProxyHelper.java Implements upstream URL/header building, proxy call, and response wrapping.
dotCMS/src/main/java/com/dotcms/rest/api/v1/analytics/content/ContentAnalyticsResource.java Disables legacy analytics resource endpoints (commented annotations).
dotCMS/src/main/java/com/dotcms/jitsu/validators/ValidationErrorCode.java Adds INVALID_JSON error code for JSON validation failures.
docker/docker-compose-examples/single-node/docker-compose.yml Adds example env vars/port for analytics proxy configuration.
core-web/libs/portlets/dot-analytics/portlet/src/lib/lib.routes.ts Refactors analytics portlet routes to lazy-load components.
core-web/libs/portlets/dot-analytics/portlet/src/lib/guards/analytics-health.guard.ts Updates analytics guard to rely on DotAnalyticsService health cache.
core-web/libs/portlets/dot-analytics/portlet/src/lib/guards/analytics-health.guard.spec.ts Updates unit tests for guard behavior and new health status values.
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-error/dot-analytics-error.component.ts Adds retry behavior + adjusts enterprise/non-enterprise error mapping.
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-error/dot-analytics-error.component.html Wires retry button to the empty state component.
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-dashboard/reports/pageview/dot-analytics-top-pages-table/dot-analytics-top-pages-table.component.ts Switches top-pages table state typing to new API TopContentData.
core-web/libs/portlets/dot-analytics/portlet/src/lib/dot-analytics-dashboard/reports/pageview/dot-analytics-top-pages-table/dot-analytics-top-pages-table.component.spec.ts Updates table tests to use new API entity shapes.
core-web/libs/portlets/dot-analytics/data-access/src/lib/utils/data/analytics-data.utils.ts Adds event-API range mapping + updates transformations to new response shapes.
core-web/libs/portlets/dot-analytics/data-access/src/lib/utils/data/analytics-data.utils.spec.ts Updates utils tests for new entities and simplified device/browser logic.
core-web/libs/portlets/dot-analytics/data-access/src/lib/types/index.ts Exports new analytics event API types.
core-web/libs/portlets/dot-analytics/data-access/src/lib/types/entities.types.ts Updates entity interfaces from CubeJS field names to typed event API fields.
core-web/libs/portlets/dot-analytics/data-access/src/lib/types/analytics-api.types.ts Introduces typed contracts for analytics event API endpoints.
core-web/libs/portlets/dot-analytics/data-access/src/lib/store/features/with-pageview.feature.ts Refactors pageview store feature to call new service endpoints + fill sparse timelines.
core-web/libs/portlets/dot-analytics/data-access/src/lib/services/dot-analytics.service.ts Adds event API methods + cached health checks; keeps CubeJS query support.
core-web/libs/portlets/dot-analytics/data-access/src/lib/constants/dot-analytics.constants.ts Adds time-range mapping for event API range param.
core-web/libs/dotcms-models/src/lib/dot-experiments-constants.ts Extends HealthStatusTypes enum with AVAILABLE / NOT_AVAILABLE.

Comment on lines 17 to 21
{
path: 'dashboard',
canMatch: [analyticsHealthGuard],
component: DotAnalyticsDashboardComponent
loadComponent: () => import('./dot-analytics-dashboard/dot-analytics-dashboard.component')
},
title: 'analytics.error.title',
loadComponent: () =>
import('./dot-analytics-error/dot-analytics-error.component').then((m) => m.default)
loadComponent: () => import('./dot-analytics-error/dot-analytics-error.component')
? HealthStatusTypes.AVAILABLE
: HealthStatusTypes.NOT_AVAILABLE
),
catchError(() => of(HealthStatusTypes.AVAILABLE))
Comment on lines +66 to +69
DOT_ANALYTICS_BASE_URL: 'http://host.docker.internal:8080'
DOT_ANALYTICS_CUSTOMER_ID: 'cust-001'
DOT_ANALYTICS_PASSWORD: 'abc'
DOT_ANALYTICS_ENVIRONMENT: 'dev'
Comment on lines +59 to +66
return this.#http.get<{ available: string }>(this.#HEALTH_URL).pipe(
map((response) =>
response.available === 'true'
? HealthStatusTypes.AVAILABLE
: HealthStatusTypes.NOT_AVAILABLE
),
catchError(() => of(HealthStatusTypes.AVAILABLE))
);
Comment on lines +63 to 66
it('should redirect to error page when health status is NOT_AVAILABLE', (done) => {
(mockAnalyticsService.healthCheck as jest.Mock).mockReturnValue(
of(HealthStatusTypes.NOT_AVAILABLE)
);
Comment on lines +66 to +69
DOT_ANALYTICS_BASE_URL: 'http://host.docker.internal:8080'
DOT_ANALYTICS_CUSTOMER_ID: 'cust-001'
DOT_ANALYTICS_PASSWORD: 'abc'
DOT_ANALYTICS_ENVIRONMENT: 'dev'
Comment on lines 12 to 16
path: 'search',
title: 'analytics.search.title',
canMatch: [analyticsHealthGuard],
loadComponent: () =>
import('./dot-analytics-search/dot-analytics-search.component').then((m) => m.default)
loadComponent: () => import('./dot-analytics-search/dot-analytics-search.component')
},
@github-actions github-actions Bot added the Area : Frontend PR changes Angular/TypeScript frontend code label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants