Skip to content

[FEATURE] Attach a site to an active site and detach it again - #29

Open
sfsmfc wants to merge 14 commits into
developfrom
feature/site-attach
Open

sfsmfc wants to merge 14 commits into
developfrom
feature/site-attach

Conversation

@sfsmfc

@sfsmfc sfsmfc commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A second domain of a project can use the analytics of an active site instead of its own registration. This PR adds attach and detach to the backend module and limits all analytics to the domains of the selected site.

Stacked on #26. Needs TYPO3GmbH/site-analytics-middleware#91.

Attach and detach

  • The registration form offers "Attach to an active site". A confirmation dialog tells that the data of the site stays in the analytics of the active site, also after a detach.
  • Attach adds the hosts of the site and of its languages to the whitelisted domains of the website of the active site. The site gets the credentials and the tracking code of the active site and the settings attachedTo and attachedHosts.
  • Detach removes the hosts in attachedHosts from the whitelist and removes the copied settings. The site is inactive again.
  • When an API request or the settings write fails, attach and detach undo their whitelist changes.
  • Attach and detach check that the backend user has access to the sites. Detach needs access to the attached site only.

Which sites can be attached

Detach removes the hosts of a site from the whitelist. Thus a host must belong to one site only. A site can be attached only when:

  • the base of the site is a host without a path, and
  • no other site of the TYPO3 instance uses a host of the site or of its languages. The check includes all sites, also the sites that the user cannot access.

For all other sites, the form shows a hint and offers only the registration as a new site.

API key

  • An attached site never creates an API key.
  • When the active site gets a key, its attached sites get the same key. When this write fails, the next status refresh of the attached site copies the key.

Module

  • An attached site shows in an indented row below its active site and the details of that site, with the status "Attached" and a "Detach" button.
  • An attached site cannot be the target of another attach.
  • The dashboard and the plan of an attached site open only for the active site. The site menu in the module header leaves out attached sites.

Analytics of the selected site

  • Each query of the dashboard widgets uses a filter on the page URL with the bases of the site and its languages, for example pageUrl in ["://example.com"]. The API compares each value as "contains".
  • The top pages widget gets its pages from the API with this filter.
  • "Show in Analytics" links show only when the backend user has access to the root page of the site whose dashboard opens. Widgets of an attached site show no link, because the dashboard cannot filter by domain. The page performance bar opens the dashboard of the active site with the page filter.

Known limits (documented)

  • The filter ://example.com also matches example.com.au and example.community. When an active site and its attached site have such domains, the widgets show the data of both domains. The module does not prevent this.
  • The module uses only the bases of the current application context, not the baseVariants. Registration sends only the domain of the site base.
  • A language with a new domain that is added after the attach is not on the whitelist. Detach the site and attach it again.

Labels

  • The labels use "attach" and "detach" throughout, in German "anhängen" and "lösen".
  • Labels and badges use sentence case. The status badge shows translated values.
  • Duplicate label ids are removed. TYPO3 uses the last entry of an id, so the labels in the backend do not change.
  • The German labels use the formal "Sie".

Test

  • ddev composer t3g:test, t3g:test:functional, t3g:phpstan and t3g:cgl pass.
  • The functional tests use real site configurations and backend users. Only the HTTP transport to the API is replaced.
  • Tested live against the local middleware and the stage system: attach, detach, the confirmation dialogs, the widgets and the page performance bar for an active and an attached site. This live test was done before the review changes (attach rule, language hosts, rollback, API key). The functional tests cover these changes.

@sfsmfc
sfsmfc added this pull request to stack #31 October 14, 2026 09:22
@sfsmfc
sfsmfc force-pushed the feature/site-attach branch from 770552f to af4af88 Compare October 14, 2026 09:31
@sfsmfc
sfsmfc force-pushed the feature/site-attach branch from af4af88 to 6038968 Compare November 3, 2026 14:50
@sfsmfc
sfsmfc force-pushed the feature/site-attach branch from 6038968 to 16b8aa0 Compare November 16, 2026 10:23
Base automatically changed from feature/ui-overhaul to develop November 24, 2026 11:44
A second domain of a project can use the analytics of an active site
instead of its own registration.

Attach to an active site
- The registration asks whether the site is registered as a new site or
  attached to an active site.
- The domain of the site is added to the whitelisted domains of the
  website of the active site, via the new middleware endpoint
  POST /website/{intpWebsiteId}/whitelisted-domains.
- The site gets the credentials and the tracking code of the active site
  and the setting "attachedTo". Plan and credits are shared.

Detach
- A "Detach" button with a confirmation dialog removes the domain from
  the whitelist (DELETE /website/{intpWebsiteId}/whitelisted-domains/{domain})
  and removes the copied settings. The site is inactive again.

Requires the whitelisted domain endpoints of the middleware.
Several sites can track into one website when a site is attached to an
active site. Each query of the dashboard widgets now uses a filter on
the page URL. The filter contains the base of the site and the bases of
all site languages, for example "://example.com". The API compares each
value as a part of the page URL, as the analytics dashboard does for its
"contains" filter. The filter is also part of the cache keys.

- AnalyticsSiteProvider returns the filter with the credentials and
  lists attached sites again.
- The top pages widget gets its pages from the API with the filter.
- DashboardLinkBuilder builds the "Show in Analytics" links. A widget
  of an attached site shows no link, because the dashboard cannot show
  only the data of one domain. The page performance bar opens the
  dashboard of the active site with the page filter.
- A link shows only when the backend user has access to the root page
  of the site whose dashboard opens.
- The widgets for TYPO3 v13 show or hide the link when the site
  changes.
…tach

An attached site has no analytics of its own, so the module shows it
in an indented row below its active site and the details of that site.
The row shows the status "Attached" and the "Detach" button. A site
whose active site is not in the list keeps a row of its own.

- An attached site cannot be the target of another attach.
- The dashboard and the plan of an attached site open only for the
  active site. A direct call redirects with a message.
- The site menu in the module header leaves out attached sites.
- Attaching a site opens a confirmation dialog. The data of the site
  stays in the analytics of the active site, also after a detach.
- The labels use "attach" and "detach" throughout. Labels and badges
  use sentence case, and the status badge shows translated values.
Some labels had two or more entries with the same id: 35 ids with 37
extra entries in the German file and one id with 3 extra entries in
the English file. TYPO3 uses the last entry of an id, so the other
entries had no effect. Some of them differed from the entry in use,
for example a second "flash.accessDenied" with informal address.

The files now keep only the last entry of each id. The labels in the
backend do not change.
The German labels used formal and informal address. The TYPO3 backend
uses the formal "Sie", so all labels of the extension use it now:

- the status query error
- the messages about low and used up credits
- the question of the registration form
- the message after a plan upgrade
…t on TYPO3 v14

TrafficSourcesWidgetV14Pass still set the constructor argument
"$uriBuilder", which the widget no longer has. The container of TYPO3
v14 failed to build. The pass now sets "$dashboardLinkBuilder".
The parameter docs of the page URL filter referred to
"buildPageUrlWhere()" without a class. The interface does not have this
method, so the reference now names AnalyticsDataClient, which
implements it.
Attach sent the full base URL of the site. The API does not accept
a base without a scheme, for example "//example.com". Attach now sends
the host, as detach does, and stops when the base has no host.
Attach and detach loaded the site without the page access check.
A manager could attach or detach a site outside the own page mounts.

- Attach requires access to the site and to the active site.
- Detach requires access to the attached site. Detach removes only
  the domain of this site, so access to the active site is not
  necessary.
The tests for attach, detach and the site list used mocks of the
site finder, the sites, the page access check and the settings
services. The functional test now uses real site configurations,
real backend users and the controller from the DI container. Only
the HTTP transport to the API is replaced.
The tests of the dashboard link builder and of the widget AJAX
controllers used mocks of the site finder, the sites and the page
access check. The tests now use the link builder from the DI
container with real site configurations and real page mounts.
The unit test used mocks of the site finder, the sites, the site
languages, the cipher service and the page access check. A language
base without a host does not occur in a real site, because TYPO3
resolves the base against the base of the site. The functional test
uses real site configurations and the service from the DI container.
The status of the active site stays in the cache, also when its
settings lose the instance secret. Attach must then stop before
the API call and write no settings.
…sistent

Detach removes the hosts of a site from the whitelist of the active
site. Several sites with the same host thus caused problems. Also the
whitelist, the API key and the settings did not always agree.

Attach rule:

- The base of the site is a host without a path.
- No other site of the TYPO3 instance uses a host of the site or of
  its languages. The check includes all sites, also the sites that
  the user cannot access.
- For all other sites, the module shows a hint and offers only the
  registration as a new site.

Whitelist:

- Attach adds the hosts of the site and of its languages and stores
  them in the new setting "attachedHosts". Detach removes only these
  hosts.
- When an API request or the settings write fails, attach and detach
  undo the whitelist changes.

API key:

- An attached site never creates an API key.
- When the active site gets a key, its attached sites get the same key.
  When this write fails, the next status refresh of the attached site
  copies the key.

Documentation:

- The attach rule and the domains that the module uses.
- The module does not use the base variants.
- The page URL filter also matches a domain that starts with another
  domain, for example "example.com" and "example.com.au".
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