@andyt1980 First, a correction to the premise: PYS does not strip its JavaScript when those filters return true. public.js is enqueued unconditionally. The filters only set two flags inside the localized pysOptions object — gdpr.all_disabled_by_api and cookie.disabled_all_cookie. The script reads these flags and skips pixel initialization and cookie writing. The assets are already loaded on the page but remain dormant.
pys.init() does nothing because no such method exists.
Here is the supported flow:
1. Make your filters consent-aware instead of hardcoding true
function my_has_consent() {
return isset( $_COOKIE['my_consent'] ) && $_COOKIE['my_consent'] === 'accepted';
}
add_filter( 'pys_disable_by_gdpr', fn() => ! my_has_consent() );
add_filter( 'pys_disable_all_cookie', fn() => ! my_has_consent() );
add_filter( 'pys_check_consent_by_gdpr', fn( $c, $pixel ) => my_has_consent(), 10, 2 );
2. Enable the AJAX filter refresh
Go to PYS → Settings → Consent → For Developers → “Enable AJAX filter values update”, or enable it programmatically:
add_filter( 'pys_gdpr_ajax_enabled', '__return_true' );
This makes PYS re-query the current filter values at runtime and also helps avoid issues caused by stale page-cache values.
3. Re-initialize on “Accept All” — no page reload is needed
document.cookie = 'my_consent=accepted; path=/; max-age=31536000; SameSite=Lax';
if ( window.pys && window.pys.Utils ) {
window.pys.Utils.manageCookies();
window.pys.Utils.loadPixels();
}
loadPixels() re-reads the PHP filter values, initializes every allowed pixel, and fires the static events queued for the current page (such as PageView). The _fbp cookie is created at that point.
Native client-side consent management:
There is no generic WP Consent API integration. PYS has native real-time integrations with Consent Magic (recommended), Cookiebot, Cookie Notice, CookieYes, and Real Cookie Banner. With these integrations, the JavaScript loads, but the pixels remain dormant until the appropriate consent event occurs, without requiring a page reload.
For Google tags, see Google Consent Mode support in the GDPR tab. This is the recommended “load but keep denied” approach for GA4 and Google Ads.
One important point to flag: the pys_disable_*_by_gdpr filters control the browser-side behavior. Server-side Conversions API events are gated separately and default to granted when no supported consent plugin is detected. Therefore, with a fully custom consent banner, CAPI events may still be sent.
The pys_check_consent_by_gdpr filter in step 1 addresses this by explicitly applying your custom consent state to the server-side events as well.