Run function from functions.php on GTM Event
-
Hi, so I have the code below, and what I’m trying to do is get CheckStatisticsAccepted() to run on an event triggered via Google Tag Manager in my frontend. So basically my JavaScript code will be inside GTM, which will fire at the right moment. That JavaScript code needs to trigger the checkStatisticsAccepted function in my functions.php file. I’m aware that I need to use AJAX, but not sure how :/
add_filter( 'facebook_for_woocommerce_integration_pixel_enabled', 'checkStatisticsAccepted', 10, 1 ); function checkStatisticsAccepted() { if (isset($_COOKIE["CookieConsent"])) { switch ($_COOKIE["CookieConsent"]) { case "-1": //The user is not within a region that requires consent - all cookies are accepted return true; default: //The user has given their consent //Read current user consent in encoded JavaScript format $valid_php_json = preg_replace('/\s*:\s*([a-zA-Z0-9_]+?)([}\[,])/', ':"$1"$2', preg_replace('/([{\[,])\s*([a-zA-Z0-9_]+?):/', '$1"$2":', str_replace("'", '"',stripslashes($_COOKIE["CookieConsent"])))); $CookieConsent = json_decode($valid_php_json); if (filter_var($CookieConsent->statistics, FILTER_VALIDATE_BOOLEAN)) { return true; } else { return false; } } } else { return false; } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Run function from functions.php on GTM Event’ is closed to new replies.