Skip to content

Commit

Permalink
Merge pull request #4 from customgento/DEV-405-add-consent-mode
Browse files Browse the repository at this point in the history
Add consent mode, DEV-405
  • Loading branch information
sprankhub committed Mar 20, 2024
2 parents c7c8cdd + f219abd commit 4e67221
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/code/community/CustomGento/Cookiebot/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CustomGento_Cookiebot_Model_Config
private const XML_PATH_COOKIEBOT_ENABLED = 'web/cookiebot/enabled';
private const XML_PATH_COOKIEBOT_ID = 'web/cookiebot/id';
private const XML_PATH_COOKIEBOT_BLOCKINGMODE = 'web/cookiebot/blocking_mode';
private const XML_PATH_COOKIEBOT_USE_GOOGLE_CONSENT_MODE = 'web/cookiebot/use_google_consent_mode';

public function isEnabled(): bool
{
Expand All @@ -22,4 +23,9 @@ public function getBlockingMode(): string
{
return Mage::getStoreConfig(self::XML_PATH_COOKIEBOT_BLOCKINGMODE);
}

public function useGoogleConsentMode(): bool
{
return (bool)Mage::getStoreConfig(self::XML_PATH_COOKIEBOT_USE_GOOGLE_CONSENT_MODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ public function generate(): string
$cookiebotId = Mage::getModel('customgento_cookiebot/config')->getCookiebotId();
$blockingMode = Mage::getModel('customgento_cookiebot/config')->getBlockingMode();

return sprintf(self::COOKIEBOT_SCRIPT_FORMAT, $cookiebotId, $blockingMode);
$cookiebotScript = sprintf(self::COOKIEBOT_SCRIPT_FORMAT, $cookiebotId, $blockingMode);

if (Mage::getModel('customgento_cookiebot/config')->useGoogleConsentMode()) {
$cookiebotScript .= '<script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("consent", "default", {
ad_personalization: "denied",
ad_storage: "denied",
ad_user_data: "denied",
analytics_storage: "denied",
functionality_storage: "denied",
personalization_storage: "denied",
security_storage: "granted",
wait_for_update: 500,
});
gtag("set", "ads_data_redaction", true);
gtag("set", "url_passthrough", true);
</script>';
}

return $cookiebotScript;
}
}
1 change: 1 addition & 0 deletions app/code/community/CustomGento/Cookiebot/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<enabled>0</enabled>
<id/>
<blocking_mode>auto</blocking_mode>
<use_google_consent_mode>1</use_google_consent_mode>
</cookiebot>
</web>
</default>
Expand Down
12 changes: 12 additions & 0 deletions app/code/community/CustomGento/Cookiebot/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<enabled>1</enabled>
</depends>
</blocking_mode>
<use_google_consent_mode translate="label">
<label>Google Consent Mode</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<enabled>1</enabled>
</depends>
</use_google_consent_mode>
</fields>
</cookiebot>
</groups>
Expand Down

0 comments on commit 4e67221

Please sign in to comment.