From 039129620019dd580008786c036fc70ae96b316b Mon Sep 17 00:00:00 2001 From: "t.fassbender" Date: Wed, 9 Feb 2022 13:29:58 +0100 Subject: [PATCH] [FEATURE] solves #31 and #29 - 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 --- Classes/Hooks/PageRendererPreProcess.php | 78 +++++++++++++++++-- .../TypoScript/Static/constants.typoscript | 4 + .../TypoScript/Static/setup.typoscript | 4 +- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/Classes/Hooks/PageRendererPreProcess.php b/Classes/Hooks/PageRendererPreProcess.php index 8d78fd9..3a23c00 100644 --- a/Classes/Hooks/PageRendererPreProcess.php +++ b/Classes/Hooks/PageRendererPreProcess.php @@ -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.'] ?? []); } @@ -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 @@ -146,4 +212,4 @@ protected function getDataProcessingService(array $configuration): string return $configuration['dataProcessingService']; } -} +} \ No newline at end of file diff --git a/Configuration/TypoScript/Static/constants.typoscript b/Configuration/TypoScript/Static/constants.typoscript index f6ac5ee..e8aa1ae 100644 --- a/Configuration/TypoScript/Static/constants.typoscript +++ b/Configuration/TypoScript/Static/constants.typoscript @@ -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 } } diff --git a/Configuration/TypoScript/Static/setup.typoscript b/Configuration/TypoScript/Static/setup.typoscript index b36396c..e67f196 100644 --- a/Configuration/TypoScript/Static/setup.typoscript +++ b/Configuration/TypoScript/Static/setup.typoscript @@ -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} +} \ No newline at end of file