Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] solves #31 and #29 #33

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
}