This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3d84cb
commit 3de0f2c
Showing
6 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Phpro\CookieConsent\Setup\Patch\Data; | ||
|
||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
use Magento\Store\Model\Store; | ||
use Phpro\CookieConsent\Api\CookieGroupRepositoryInterface; | ||
use Phpro\CookieConsent\Api\Data\CookieGroupInterface; | ||
use Phpro\CookieConsent\Model\CookieGroupFactory; | ||
|
||
class PersonalizationData implements DataPatchInterface | ||
{ | ||
/** | ||
* @var CookieGroupFactory | ||
*/ | ||
private $cookieGroupFactory; | ||
|
||
/** | ||
* @var CookieGroupRepositoryInterface | ||
*/ | ||
private $cookieGroupRepository; | ||
|
||
|
||
public function __construct( | ||
CookieGroupFactory $cookieGroupFactory, | ||
CookieGroupRepositoryInterface $cookieGroupRepository | ||
) { | ||
$this->cookieGroupFactory = $cookieGroupFactory; | ||
$this->cookieGroupRepository = $cookieGroupRepository; | ||
} | ||
|
||
public static function getDependencies() | ||
{ | ||
return [ | ||
CookieGroupAttribute::class, | ||
DefaultCookieData::class, | ||
]; | ||
} | ||
|
||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
|
||
public function apply() | ||
{ | ||
$this->createDefaultGroups(); | ||
} | ||
|
||
private function createDefaultGroups(): void | ||
{ | ||
/** @var CookieGroupInterface $group */ | ||
$personalization = $this->cookieGroupFactory->create(); | ||
$personalization->setStoreId(Store::DEFAULT_STORE_ID); | ||
$personalization->setSystemName('personalization'); | ||
$personalization->setName('Personalization'); | ||
$personalization->setActive(true); | ||
$personalization->setEssential(false); | ||
$personalization->setDescription('Personalization cookies are used for ad personalization and remarketing.'); | ||
|
||
$this->cookieGroupRepository->save($personalization); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
|
||
function gtag() { | ||
console.log(arguments); | ||
dataLayer.push(arguments); | ||
} | ||
|
||
if (localStorage.getItem('consentMode') === null) { | ||
gtag('consent', 'default', { | ||
'ad_storage': 'denied', | ||
'analytics_storage': 'denied', | ||
'personalization_storage': 'denied', | ||
'functionality_storage': 'denied', | ||
'security_storage': 'denied', | ||
'ad_user_data': 'denied', | ||
'ad_personalization': 'denied', | ||
}); | ||
} else { | ||
gtag('consent', 'default', JSON.parse(localStorage.getItem('consentMode'))); | ||
} | ||
|
||
document.addEventListener('consent-changed', function (consent) { | ||
const consentMode = { | ||
'ad_storage': consent.marketing ? 'granted': 'denied', | ||
'analytics_storage': consent.analytical ? 'granted': 'denied', | ||
'personalization_storage': consent.personalization ? 'granted': 'denied', | ||
'functionality_storage': consent.essential ? 'granted': 'denied', | ||
'security_storage': consent.essential ? 'granted': 'denied', | ||
'ad_user_data': consent.marketing ? 'granted': 'denied', | ||
'ad_personalization': consent.marketing && consent.personalization ? 'granted': 'denied', | ||
}; | ||
|
||
gtag('consent', 'update', consentMode); | ||
localStorage.setItem('consentMode', JSON.stringify(consentMode)); | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters