Skip to content

Collecting consents using custom scripts

Check how to set up proper cookie consent collection if you’re not using Google Tag Manager.

Last updated
February 18, 2025

Blocking the script call

To prevent the Google Analytics script from being triggered upon page load before the user has given the appropriate consent:

  • Access your website’s settings and locate the Google Analytics script.
  • Change the type parameter to text/plain.
  • Add the attribute data-easycookie-{type} that matches the required consent type.

Available consent types:

  • data-easycookie-aduser
  • data-easycookie-adpersonalization
  • data-easycookie-analytics
  • data-easycookie-functionality
  • data-easycookie-personalization
  • data-easycookie-security

See how to modify your script using the example below.

Original script:

Modified script:

The Easycookie script functions simply. Once consent is given for a specific cookie type, scripts of that type automatically revert to the correct type=text/javascript. This effectively triggers them upon consent.

Asynchronous script execution

A potential issue with such scripts is that they are triggered by a DOM event, e.g., DOMContentLoaded. When this event occurs, the scripts might not be available yet, as they are still blocked by Easycookie. The most common example of this asynchronous scenario is the Meta pixel.

In this situation, we recommend integrating the script via GTM. However, if you opt for manual configuration, follow these steps:

  • Remove the noscript tag.
  • Utilize events available from the Consent API with Meta:     fbq(‘consent’, ‘revoke’); // Withdraws permission for cookies fbq(‘consent’, ‘grant’); // Grants permission for cookies

Example of unaltered pixel code:

Transformed code:

This ensures that upon page load, consent for cookies is initially denied. Then, listen for the easycookieUpdateConsent event triggered by Easycookie, which sends e.detail, and only then grant consent based on the type: ad, aduser, adpersonalization, analytics, personalization, security.

Didn’t find what you were looking for? Contact us