Embed Google Tag Manager by extending TYPO3 Site ModuleGeorg RingerBlockedUnblockFollowFollowingJan 17This blog post describes how the Sites module of TYPO3 9 can be extended and how the information can be extracted and used later on.
Additional tab with one extra field to define the Google Tag Manager codeTYPO3 9 LTS ships a new module called Sites.
This is the central place to define all relevant information regarding domains and available languages.
SetupExtensions can extend the site configuration with additional fields.
To be able to provide custom configuration, the following file needs to placed in your site-package extension at Configuration/SiteConfiguration/Overrides/sites.
You will recognize the syntax from writing TCA code as it is very similar.
However, there are certain limits regarding the available field types which are written down in the docs.
In short, you can use input & select fields and checkboxes but for example no relations.
UsageThe value of the new field can be retrieved in various ways.
PHPThe SiteFinder can be used in Frontend or Backend to retrieve a proper Site object — either by providing a page id, root page id or the site identifier.
The Site itself includes all information which is persisted in the Sites module.
TypoScriptThe shortest possible snippet can look like this:lib.
test = TEXTlib.
data = site:googleTagManagerA real-world example would be the following which retrieves the value and uses it for including the Google Tag Manager into the TYPO3 site.