From 31bbf4eaaa72773ad1d2ae35de4a1b13ece88734 Mon Sep 17 00:00:00 2001 From: Kristoffer Tonning Date: Sun, 3 Dec 2023 22:50:34 +0100 Subject: [PATCH] Allow to show/hide cookie drawer via setting --- ...29_100000_add_show_cookie_widget_settings.php | 16 ++++++++++++++++ resources/views/script.blade.php | 13 +++++++++++-- src/OsanoServiceProvider.php | 8 ++++++++ src/Settings/OsanoSettings.php | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 database/migrations/settings/2023_11_29_100000_add_show_cookie_widget_settings.php diff --git a/database/migrations/settings/2023_11_29_100000_add_show_cookie_widget_settings.php b/database/migrations/settings/2023_11_29_100000_add_show_cookie_widget_settings.php new file mode 100644 index 0000000..ea26766 --- /dev/null +++ b/database/migrations/settings/2023_11_29_100000_add_show_cookie_widget_settings.php @@ -0,0 +1,16 @@ +migrator->add('osano.show_cookie_widget', true); + } + + public function down() + { + $this->migrator->delete('osano.show_cookie_widget'); + } +}; diff --git a/resources/views/script.blade.php b/resources/views/script.blade.php index 29924f3..afdadf1 100644 --- a/resources/views/script.blade.php +++ b/resources/views/script.blade.php @@ -1,5 +1,14 @@ -@php use Astrogoat\Osano\Settings\OsanoSettings; @endphp +@php + use Astrogoat\Osano\Settings\OsanoSettings; + $settings = resolve(OsanoSettings::class); +@endphp @if(OsanoSettings::isEnabled()) - + @unless($settings->show_cookie_widget) + + @endunless + + @endif diff --git a/src/OsanoServiceProvider.php b/src/OsanoServiceProvider.php index afd6801..f0c9caa 100644 --- a/src/OsanoServiceProvider.php +++ b/src/OsanoServiceProvider.php @@ -4,6 +4,7 @@ use Astrogoat\Osano\Settings\OsanoSettings; use Helix\Lego\Apps\App; +use Helix\Lego\Apps\AppToken; use Helix\Lego\Apps\Services\IncludeFrontendViews; use Helix\Lego\LegoManager; use Spatie\LaravelPackageTools\Package; @@ -19,6 +20,13 @@ public function registerApp(App $app) ->migrations([ __DIR__ . '/../database/migrations/settings', ]) + ->tokens([ + AppToken::name('Cookie preferences drawer trigger') + ->type(AppToken::TYPE_TEXT) + ->key('cookie-preferences-drawer-trigger') + ->value("event.preventDefault(); Osano.cm.showDrawer('osano-cm-dom-info-dialog-open')") + ->description('To trigger the Storage/Cookie preferences drawer'), + ]) ->includeFrontendViews(function (IncludeFrontendViews $frontendViews) { return $frontendViews->addToEnd('osano::script'); }); diff --git a/src/Settings/OsanoSettings.php b/src/Settings/OsanoSettings.php index ac1eab7..1fbaf80 100644 --- a/src/Settings/OsanoSettings.php +++ b/src/Settings/OsanoSettings.php @@ -9,6 +9,7 @@ class OsanoSettings extends AppSettings { public string $account_id; public string $configuration_id; + public bool $show_cookie_widget; public function rules(): array { @@ -41,6 +42,7 @@ public function help(): array return [ 'account_id' => 'Your Osano account ID can be found in the Osano dashboard, under your cookie consent configuration, and click "Get Code". The first string of random text after "cmp.osano.com/" is your account ID (do not include the forward slashes ("/")). E.g. "JiyzxlTvcbPaU3v4y".', 'configuration_id' => 'Your Osano configuration ID is the second string of random text after your account ID up until "/osano.js" (do not include the forward slashes ("/")). E.g. "fe9b6d40-6a13-49a8-a8d0-fdb931ab4c32".', + 'show_cookie_widget' => 'Show or hide the default cookie icon widget. There is, however, a caveat. If you hide the cookie widget, you MUST give your users another way of accessing the Storage/Cookie Preferences. The "Storage Preferences" or "Drawer" is required to (1) Easily Explain Cookie Categories (2) Allow Users to Understand and Change their Preferences and (3) Disclose Cookies to End Users. To trigger the Storage/Cookie preferences drawer, you can utilize the following Javascript: "Osano.cm.showDrawer(\'osano-cm-dom-info-dialog-open\')"', ]; } }