Google Tracking Disabled on Load and then Enabled after GDPR Consent
-
Hi Support,
I posted a question about disabling GA tracking by default when using WooCommerce Google Analytics Integration plugin and then re-enabling after receiving user consent.
I did manage to cobble together a solution based on another member’s suggestion. But this solution only assumes that the user has clicked ‘Accept’ to close the banner. I noticed that your plugin has some hooks which may give a better outcome.
Do you have any suggestions on how to improve the function below so that is works only when someone has given explicit consent rather than the default action of closing the banner?
Thanks!
add_action( ‘init’, ‘maybe_consent_woocommerce_google_analytics’);
function maybe_consent_woocommerce_google_analytics() {// Disable WooCommerce Google Analytics displaying tracking code by default
$integrations = WC()->integrations->get_integrations();
remove_action(‘wp_head’, array($integrations[‘google_analytics’], ‘tracking_code_display’), 999999 );// Display the tracking code if the user has accepted the GDPR Cookie Compliance policy
if ($_COOKIE[‘moove_gdpr_popup’] != null) {
add_action(‘wp_head’, array($integrations[‘google_analytics’], ‘tracking_code_display’), 999999 );
}}
- The topic ‘Google Tracking Disabled on Load and then Enabled after GDPR Consent’ is closed to new replies.