Skip to content

Commit

Permalink
Allow to show/hide cookie drawer via setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tonning committed Dec 3, 2023
1 parent 5912917 commit 31bbf4e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('osano.show_cookie_widget', true);
}

public function down()
{
$this->migrator->delete('osano.show_cookie_widget');
}
};
13 changes: 11 additions & 2 deletions resources/views/script.blade.php
Original file line number Diff line number Diff line change
@@ -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())
<script src="https://cmp.osano.com/{{ resolve(OsanoSettings::class)->account_id }}/{{ resolve(OsanoSettings::class)->configuration_id }}/osano.js"></script>
@unless($settings->show_cookie_widget)
<style>
.osano-cm-widget { display: none; }
</style>
@endunless

<script src="https://cmp.osano.com/{{ $settings->account_id }}/{{ $settings->configuration_id }}/osano.js"></script>
@endif
8 changes: 8 additions & 0 deletions src/OsanoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
});
Expand Down
2 changes: 2 additions & 0 deletions src/Settings/OsanoSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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\')"',
];
}
}

0 comments on commit 31bbf4e

Please sign in to comment.