t3g / usercentrics
This extension provides a usercentrics integration into TYPO3.
Installs: 13 758
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 8
Forks: 6
Open Issues: 9
Type:typo3-cms-extension
Requires
- php: ^7.2
- ext-json: *
- typo3/cms-core: ^10.4.0
Requires (Dev)
- bk2k/extension-helper: ^1.0
- friendsofphp/php-cs-fixer: ^2.14
- overtrue/phplint: ^1.1
- roave/security-advisories: dev-master
- typo3/testing-framework: ^4.9 || ^5.0 || ^6.3
README
This extension integrates Usercentrics (Compliance and Consent Management) into TYPO3.
Installation and Configuration
-
Download and install the extension from the TER or via composer:
- TER: https://extensions.typo3.org/extension/usercentrics
- Composer: composer require t3g/usercentrics
-
Activate the extension in the extension manager
-
On every site where you want to use the extension, include the static TypoScript setup
-
Configure your Usercentrics ID by setting
plugin.tx_usercentrics.settingsId = <your-id>
in your TypoScript setup -
Configure the JS Files to be handled by Usercentrics:
plugin.tx_usercentrics {
settingsId = {$plugin.tx_usercentrics.settingsId}
jsFiles {
# Path to JS File (required)
10.file = EXT:site/Resources/Public/JavaScriyt/MyScriptFile.js
# Identifier to use in Usercentrics (required)
10.dataProcessingService = My Data Processing Service
20.file = secondFile.js
20.dataProcessingService = My other Data Processing Service
# attributes for the script tag (optional)
20.attributes {
async = async
}
# options for the TYPO3 AssetCollector
# setting priority will render the script in the head instead of the footer section
20.options {
priority = 1
}
}
jsInline {
10.value (
alert(123);
)
10.dataProcessingService = My Data Processing Service
10.attributes {
custom = attribute
}
}
}
Note that the configured identifiers need to match your Usercentrics configuration.
You do not need to set the type
or data-usercentrics
attributes for the script tags, the extension will handle that for you.
Usage in Fluid
The extension comes with a custom view helper which can be used to add scripts via Fluid:
<usercentrics:script dataProcessingService="identifier123" src="EXT:my_ext/Resources/Public/JavaScript/foo.js" /> <usercentrics:script dataProcessingService="identifier123"> alert('hello world'); </usercentrics:script>
Integrate Usercentrics with PHP
Since TYPO3 v10 the AssetCollector is part of the TYPO3 Core API. To add scripts managed by Usercentrics via PHP, replace your previous calls to the PageRenderer
with AssetCollector
calls and make sure to
set the attributes type=text/plain
and data-usercentrics=identifer
.
Example:
$dataProcessingService = 'My Data Processing Service';
$identifier = \TYPO3\CMS\Core\Utility\StringUtility::getUniqueId($dataProcessingService . '-');
$file = 'EXT:site/Resources/Public/JavaScript/Scripts.js';
$attributes = [
'type' => 'text/plain',
'data-usercentrics' => $dataProcessingService
];
$assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
$assetCollector->addJavaScript($identifier, $file, $attributes);