### Listen to surecookie_applied event Source: https://surecookie.com/docs/frontend-javascript-api-events Use this listener to react to consent changes and to handle returning visitors whose stored consent is applied on page load. It checks if analytics is allowed and starts or stops custom analytics accordingly. ```javascript window.addEventListener( 'surecookie_applied', () => { if ( window.surecookieManager.isAllowed( 'analytics' ) ) { startMyCustomAnalytics(); } else { stopMyCustomAnalytics(); } } ); ``` -------------------------------- ### Clear cache on scanner update with surecookie_scanner_results_updated Source: https://surecookie.com/docs/developer-reference-hooks-filters Example of clearing the WordPress cache when cookie data is updated after a scan. ```php add_action( 'surecookie_scanner_results_updated', function () { if ( function_exists( 'wp_cache_flush' ) ) { wp_cache_flush(); } } ); ``` -------------------------------- ### Include blog posts in SureCookie pickers using surecookie_searchable_post_types Source: https://surecookie.com/docs/including-custom-post-types-in-scanning-and-the-cookie-policy-picker Adds the built-in 'post' type to the pickers. Blog posts are not listed by default and are added the same way as custom post types. ```php add_filter( 'surecookie_searchable_post_types', function ( $post_types ) { $post_types['post'] = 'post'; return $post_types; } ); ``` -------------------------------- ### Reacting to consent changes with surecookie_changed event Source: https://surecookie.com/docs/developer-reference-hooks-filters Listen for the surecookie_changed event on the window object to handle consent updates. The consent data is provided within event.detail. ```javascript window.addEventListener( 'surecookie_changed', ( event ) => { console.log( 'Consent updated:', event.detail ); } ); ``` -------------------------------- ### Add a post type to both pickers using surecookie_searchable_post_types Source: https://surecookie.com/docs/including-custom-post-types-in-scanning-and-the-cookie-policy-picker Adds the 'product' post type to both the Cookie Scanner and Cookie Policy pickers. The filter receives the array of post type slugs and returns it with the new type added. The post type must be registered with public => true. ```php add_filter( 'surecookie_searchable_post_types', function ( $post_types ) { $post_types['product'] = 'product'; return $post_types; } ); ``` -------------------------------- ### getConsent() Source: https://surecookie.com/docs/frontend-javascript-api-events Returns the stored consent object with the visitor's per-category preferences, the action they took, and a timestamp, or null before any choice. ```APIDOC ## getConsent() ### Description Returns the stored consent object, with the visitor’s per-category `preferences`, the `action` they took, and a `timestamp`, or `null` before any choice. ### Method getConsent ### Parameters None ### Returns - **object|null** - The consent object with `preferences`, `action`, and `timestamp`, or `null` if no choice has been made. ```