Skip to content

Commit

Permalink
[FEATURE] solves TYPO3GmbH#31 and TYPO3GmbH#29
Browse files Browse the repository at this point in the history
- Switch to CMP v2
- Support for integration of the Smart Data Protector for more secure and user-friendly Consent Management
- Support for preloading the required resources to increase performance
  • Loading branch information
thofas committed Feb 9, 2022
1 parent 7a93335 commit 0391296
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
78 changes: 72 additions & 6 deletions Classes/Hooks/PageRendererPreProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function addLibrary(): void
if (!$this->isValidId($config)) {
throw new \InvalidArgumentException('Usercentrics ID not configured, please set plugin.tx_usercentrics.settingsId in your TypoScript configuration', 1583774571);
}

$this->addUsercentricsScript($config);
if($config['smartDataProtector'])
$this->addSmartDataProtectorScript($config);
$this->addConfiguredJsFiles($config['jsFiles.'] ?? []);
$this->addConfiguredInlineJavaScript($config['jsInline.'] ?? []);
}
Expand Down Expand Up @@ -77,11 +80,74 @@ protected function addConfiguredJsFiles(array $jsFiles): void

protected function addUsercentricsScript(array $config): void
{
$this->assetCollector->addJavaScript('usercentrics', 'https://app.usercentrics.eu/latest/main.js', [
'type' => 'application/javascript',
'id' => $config['settingsId'],
'language' => $config['language'],
]);
if($config['preconnectRessources']) {
$this->assetCollector->addStyleSheet('usercentrics-preconnect-app', '//app.usercentrics.eu', [
'type' => '',
'rel' => 'preconnect'
],
[
'priority' => true
]
);
$this->assetCollector->addStyleSheet('usercentrics-preconnect-api', '//api.usercentrics.eu', [
'type' => '',
'rel' => 'preconnect'
],
[
'priority' => true
]
);
$this->assetCollector->addStyleSheet('usercentrics-preload-loader', '//app.usercentrics.eu/browser-ui/latest/loader.js', [
'type' => '',
'rel' => 'preload',
'as' => 'script'
],
[
'priority' => true
]
);
}

$this->assetCollector->addJavaScript('usercentrics-cmp', 'https://app.usercentrics.eu/browser-ui/latest/loader.js', [
'id' => 'usercentrics-cmp',
'data-settings-id' => $config['settingsId'],
'async' => 'async'
],
[
'priority' => true
]
);
}

protected function addSmartDataProtectorScript(array $config): void
{
if($config['preconnectRessources']) {
$this->assetCollector->addStyleSheet('usercentrics-preconnect-proxy', '//privacy-proxy.usercentrics.eu', [
'type' => '',
'rel' => 'preconnect'
],
[
'priority' => true
]
);
$this->assetCollector->addStyleSheet('usercentrics-preload-bundle', '//privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js', [
'type' => '',
'rel' => 'preload',
'as' => 'script'
],
[
'priority' => true
]
);
}

$this->assetCollector->addJavaScript('usercentrics-bundle', 'https://privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js', [
'type' => 'application/javascript',
],
[
'priority' => true
]
);
}

protected function convertPriorityToBoolean(array $options): array
Expand Down Expand Up @@ -146,4 +212,4 @@ protected function getDataProcessingService(array $configuration): string

return $configuration['dataProcessingService'];
}
}
}
4 changes: 4 additions & 0 deletions Configuration/TypoScript/Static/constants.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ plugin {
settingsId =
# cat=usercentrics; type=string; label=language iso code
language = en
#cat=usercentrics; type=boolean; label=add preconnect/preload ressources (performance improvements)
preconnectRessources = 0
#cat=usercentrics; type=boolean; label=include Smart Data Protector (Content Blocker)
smartDataProtector = 0
}
}
4 changes: 3 additions & 1 deletion Configuration/TypoScript/Static/setup.typoscript
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
plugin.tx_usercentrics {
settingsId = {$plugin.tx_usercentrics.settingsId}
language = {$plugin.tx_usercentrics.language}
}
preconnectRessources = {$plugin.tx_usercentrics.preconnectRessources}
smartDataProtector = {$plugin.tx_usercentrics.smartDataProtector}
}

0 comments on commit 0391296

Please sign in to comment.