Skip to end of banner
Go to start of banner

ENG Script-Anpassungen (Javascript)

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 2 Current »

The simplest way to prevent Javascript from executing without Consent is to make a small adjustment, whereby the browser no longer interprets the script as such:

In the scripts the type must be changed from type="text/javascript" to type="text/plain". If the type "text/javascript" is not explicitly specified in the script, because it can also be interpreted by the browser without being named, type="text/plain" must still be added.

Cookiebot can recognize these scripts with the help of an attribute to be defined and set the type from text/plain back to text/javascript if consent is given. For a correct assignment, therefore, a "data attribute" must also be added:

This data attribute is structured according to the principle data-cookieconsent="[cookie-category]", where "cookie-category" must correspond to one of the categories used in the Cookiebot. The Cookiebot works with the 3 categories of preferences, marketing and statistics. The associated values are as follows:

Category

unique identifier

Code adjustment

Preferences

preferences

type=”text/plain” data-cookieconsent="preferences"

Marketing

marketing

type=”text/plain” data-cookieconsent="marketing"

Statistics

statistics

type=”text/plain” data-cookieconsent="statistics"

Note: A combination of categories can also be used. For example, data-cookieconsent="statistics, marketing"

Example:

An example using the Google Analytics script.We assign this to the category "Statistics".

Original:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
 
  gtag('config', 'UA-XXXXXXXX-X');
</script>

Adjusted:

The adjustments were necessary in line 1 and line 2.

<script type=”text/plain” data-cookieconsent="statistics" async src="https://www.googletagmanager.com/gtag/js?id=UA-XXX"></script>
<script type=”text/plain” data-cookieconsent="statistics">
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
 
  gtag('config', 'UA-XXXXXXXX-X');
</script>
  • No labels