cookieconsent icon indicating copy to clipboard operation
cookieconsent copied to clipboard

[Feat]: Toggle script with multiple data-categories

Open KotaruS opened this issue 1 year ago • 1 comments

Description

It might be useful to be able to apply simple OR or AND in data-category so It's loaded when either or both categories are granted. I know about onChange and onConsent but solution like this provides extra flexibility with some CMS solutions.

Proposed solution

Example OR:

<script type="text/plain" data-category="analytics|marketing">
// gets loaded when analytics or marketing consent is granted
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
</script>

Example AND:

<script type="text/plain" data-category="analytics&marketing">
// gets loaded when both analytics and marketing consent is granted
gtag('consent', 'update', { 
  'analytics_storage': 'granted',
  'ad_user_data': 'granted',
  'ad_personalization': 'granted',
  'ad_storage': 'granted',
});
</script>

Additional details

No response

KotaruS avatar Apr 09 '24 07:04 KotaruS

Yes, could be useful!

orestbida avatar Apr 24 '24 18:04 orestbida