Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't disable Pixel when website is cached. GDPR + CDN #2576

Open
edirpedro opened this issue Jul 6, 2023 · 4 comments
Open

Can't disable Pixel when website is cached. GDPR + CDN #2576

edirpedro opened this issue Jul 6, 2023 · 4 comments
Labels
type: enhancement The issue is a request for an enhancement.

Comments

@edirpedro
Copy link

edirpedro commented Jul 6, 2023

I'm getting problems when combining Pixel with cached pages, using Varnish or a CDN. this is my scenario:

  1. Can't create a custom cache on the server, I need to use the host solution only.
  2. Can't use the PHP filter "facebook_for_woocommerce_integration_pixel_enabled" because the page will be cached without the Pixel and served to all other users.
  3. I can only rely on the client side to handle the opt-in and out for Pixel, but I didn't find a way to manage this.

What I think that could be a solution, just an ideia, not tested.

Instead of add the scripts direct on the page, we need a JS Hook to check if this can be done or not and only after that we add the script source and all the rest to start up the Pixel or any other third party application. Like this using WP JS Hooks:

addFilter( 'facebook_for_woocommerce_integration_pixel_enabled', 'facebook_for_woocommerce', consent_for_facebook_pixel );
function consent_for_facebook_pixel() {
    return document.cookie.indexOf('consent-facebook-pixel=true') >= 0;
}

Without checking the user consent on the server side, there is no problem creating caches on the server or using a CDN, the Pixel will be on the HTML but only injected on the page after checking it on the client side, according to user consent.

Additional information

https://developers.facebook.com/docs/meta-pixel/implementation/gdpr

There is an option at documentation, using fbq('consent', 'revoke');. But it has to be setted before the fbq('init', '<your pixel ID>'); and this can't be done with the plugin since the script don't have this option.

But wait, this solution still allows Facebook to track the user since it revokes after the scripts are loaded! This is not a GDPR solution.

Originally posted by @edirpedro in #301 (comment)

@edirpedro edirpedro changed the title Can't disable Pixel when website is cached. GPDR + CDN Jul 6, 2023
@ibndawood ibndawood assigned ibndawood and unassigned ibndawood Jul 7, 2023
@betagoo
Copy link

betagoo commented Mar 16, 2024

Is there any hook to paste:
fbq('consent', 'revoke');
before
fbq('init', '<your pixel ID>');
I search whole code and I not found any consent revoke.

@rawdreeg
Copy link
Contributor

rawdreeg commented Mar 20, 2024

@edirpedro @betagoo

You can use you the facebook_woocommerce_pixel_init to prepend fbq('consent', 'revoke'); to the facebook_woocommerce_pixel_init code

Here's an axample implementation you can use in your child's theme function.php:

function prepend_fb_consent_to_pixel_init( $original_script ) {
    // Your consent code to prepend
    $consent_code = "fbq('consent', 'revoke');\n";

    // Prepending the consent code to the original pixel init code
    $modified_script = $consent_code . $original_script;

    return $modified_script;
}

// Adding your custom filter to modify the facebook_woocommerce_pixel_init output
add_filter( 'facebook_woocommerce_pixel_init', 'prepend_fb_consent_to_pixel_init', 10, 1 );
@rawdreeg rawdreeg added type: enhancement The issue is a request for an enhancement. and removed needs investigation labels Mar 20, 2024
@edirpedro
Copy link
Author

@rawdreeg Facebook tell us to do this way but this action does make it track te user since the scripts are already loaded on page before this action. The right way should be simply not include the scripts on the page, to not make any request to the Facebook servers.

@rawdreeg
Copy link
Contributor

Thanks for your reply @edirpedro

Yes, the https://connect.facebook.net/en_US/fbevents.js script is loaded before . I'll keep this issue open for client site solution for preventing fbevents.js from getting included into the page. But the goal is to revoke the consent then facebook_woocommerce_pixel_init should help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement The issue is a request for an enhancement.
4 participants