Skip to content

[TASK] Clean up the analytics data client and render the page performance bar with Fluid - #30

Open
sfsmfc wants to merge 4 commits into
feature/site-attachfrom
feature/analytics-data-client-utility
Open

sfsmfc wants to merge 4 commits into
feature/site-attachfrom
feature/analytics-data-client-utility

Conversation

@sfsmfc

@sfsmfc sfsmfc commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactoring of the data client and the page performance bar. Stacked on #29.

Data client

  • The query and response helpers move into AnalyticsQueryUtility and AnalyticsResponseUtility with own tests. The behaviour does not change.
  • All single requests go through postJson(). websiteUrl() builds the URLs, fetchGraph() fetches the daily graphs. The behaviour does not change.
  • Top pages, traffic graph and traffic sources now query full UTC days, like the site performance widget and the page performance bar. The endpoints bucket by UTC day, so with the local offset the first day was only a part of a day. The numbers of these widgets can change a little.
  • The previous period of the top pages and the breakdowns of the sessions by device, browser and country also use full UTC days.
  • In time zones behind UTC, "today" does not include the hours after midnight UTC. This is intentional, because the endpoints bucket by UTC day.

Page performance bar

  • PagePerformanceBarBuilder is split into PagePerformanceDataProvider (site, page URL, link and metrics) and PagePerformanceBarRenderer.
  • The bar renders with Fluid templates in Resources/Private/Templates/PagePerformance and the partial PagePerformance/MetricDetails.html. Fluid escapes all output. The manual escaping is removed.
  • The renderer gives the request to the views, so the view helpers get the language of the backend user from the request.
  • The HTML does not change. A comparison of the old and the new output gave the same DOM for two pages, so the styles and the JavaScript stay as they are.

Test

  • ddev composer t3g:test, t3g:test:functional, t3g:phpstan and t3g:cgl pass.
  • A functional test renders the templates of the bar with a real backend user.
  • A functional test sends the bar through the AJAX route with a real site and the metrics from the API. Only the HTTP transport is replaced. The test checks the values, the trend context of the rates (percentage points) and the labels of the charts.

@sfsmfc
sfsmfc added this pull request to stack #31 October 14, 2026 09:22
@sfsmfc
sfsmfc force-pushed the feature/analytics-data-client-utility branch 2 times, most recently from bac87bc to 5365e01 Compare October 14, 2026 09:27
@sfsmfc
sfsmfc force-pushed the feature/analytics-data-client-utility branch from 5365e01 to ec94e3c Compare October 14, 2026 09:31
@sfsmfc
sfsmfc force-pushed the feature/analytics-data-client-utility branch from ec94e3c to 681aebe Compare November 6, 2026 10:04
@sfsmfc
sfsmfc force-pushed the feature/analytics-data-client-utility branch from 681aebe to e2fb62d Compare November 16, 2026 10:23
…ilities

The data client only builds and sends the requests now. The helpers
without a dependency go into two utility classes with own tests:

- AnalyticsQueryUtility: UTC day ranges, graph queries and the page
  URL filter
- AnalyticsResponseUtility: settled responses, session totals, daily
  series, time on page and time series

The behaviour does not change.
Each fetch method built the headers, sent the request, decoded the
JSON and converted the errors by itself. postJson() now does these
steps once, websiteUrl() builds the URL below a website and
fetchGraph() fetches a daily graph. The visits, sessions and visitors
graphs share fetchGraph().

AnalyticsResponseUtility::graph() reads the labels and datasets of a
graph response. timeSeriesData() takes the decoded body.

The behaviour does not change.
…ll UTC days

The analytics and graph endpoints bucket by UTC day. These widgets
still sent the range with the local offset, so the first day of the
range was only a part of a day. All queries of the data client now use
full UTC days, as the site performance widget and the page performance
bar already do. The previous period of the top pages and the session
breakdowns uses the same range.

The numbers of the three widgets can change a little, because the
first day is now complete.
PagePerformanceBarBuilder loaded the data of the bar and built its
HTML as strings, with manual escaping. The class is split:

- PagePerformanceDataProvider gets the site, the page URL, the link to
  the dashboard and the metrics. A metric holds label keys instead of
  translated labels.
- PagePerformanceBarRenderer renders the templates Skeleton.html and
  Bar.html in Resources/Private/Templates/PagePerformance and the
  partial PagePerformance/MetricDetails.html. The sparkline comes from
  the sparkline ViewHelper. The renderer gives the request to the
  views, so the view helpers get the language of the backend user.

Fluid escapes all output now. The HTML of the bar does not change, so
the styles and the JavaScript of the bar stay as they are.

A functional test renders the templates with a real backend user. A
second functional test sends the bar through the AJAX route with the
metrics from the API and replaces only the HTTP transport.
@andreaskienast
andreaskienast force-pushed the feature/analytics-data-client-utility branch from e2fb62d to ef68f9a Compare November 24, 2026 11:44
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