Skip to content
Last updated

Managing Cookie Consent for Custom scripts

When implementing custom scripts that set cookies—especially for marketing or analytics purposes—it’s essential to respect user consent. This is not just a best practice, but in many regions (like the EU), a legal requirement under regulations such as the GDPR and ePrivacy Directive.

Custom tracking or analytics tools, such as Matomo, Hotjar, or other third-party platforms, are commonly placed in the Remarketing field. These tools typically set cookies to track user behavior, personalize experiences, or gather statistical insights. However, unless users have explicitly agreed to these types of cookies, running such scripts could lead to non-compliance.

Many CMPs—including Foleon’s native Cookie Consent Manager—allow you to conditionally load scripts based on the user’s choices. Instead of executing tracking scripts by default, they use a mechanism where the script type is set to text/plain and tagged with a specific data-cookieconsent attribute.

When the user grants consent for a certain category, the CMP activates and runs the corresponding scripts.

<script type="text/plain" data-cookieconsent="marketing">
  // This script will only execute if the user consents to marketing cookies
  console.log("Marketing script fired");
</script>
<script type="text/plain" data-cookieconsent="statistics">
  // This script will only execute if the user consents to statistics cookies
  console.log("Statistics script fired");
</script>
🔍 Note: Only the following data-cookieconsent categories are allowed: "marketing", "statistics", and "preferences".