CookieYes GDPR Cookie Consent plugin has recently completely revamped its user interface and functionality.
This is explained here:
To try the new UI, all you need to do is follow the steps:
- Navigate to WordPress Dashboard > GDPR Cookie Consent.
- Add the query parameter
&migrate=true
at the end of your WordPress URL.
If you are using the new UI already, then follow these steps to block a script from loading before user consent:
1. ΅When adding a cookie in the administration area, go to the Advanced Settings of the cookie and and add a Script URL Pattern which will capture and block it until the user consents.
2. Add the required data attribute to the script you want to block:
<script async data-cookieyes="cookieyes-analytics" src="https://www.googletagmanager.com/gtag/js?id=UA-144842869-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-144842869-1');
</script>
Alternatively you can manually add a script like this:
<script>
function getCookie(key) {
const cookies = document.cookie
.split(";")
.reduce(
(ac, cv, i) =>
Object.assign(ac, { [cv.split("=")[0]]: cv.split("=")[1] }),
{}
)["cookieyes-consent"];
const { [key]: value } = cookies
.split(",")
.reduce(
(obj, pair) => (
(pair = pair.split(":")), (obj[pair[0]] = pair[1]), obj
),
{}
);
return value;
}
if (getCookie("consent") == "yes" && getCookie("analytics") == "yes") {
const script = document.createElement("script");
script.setAttribute("src", "<URL of your script>");
document.body.appendChild(script);
}
</script>