Feature request — enqueue pixel scripts so consent platforms can gate them
-
Hi Meta Pixel for WordPress team,
We use the Meta Pixel for WordPress plugin (currently v5.1.0) on client sites that are required to run a consent management platform (Usercentrics / IAB TCF / GDPR). To be compliant, the pixel
<script>tags must not execute until the visitor grants consent — typically by rendering them astype="text/plain"with adata-usercentrics="..."(or equivalent) attribute, which the consent tool then activates after opt-in.The problem is that the plugin currently prints the pixel script tags directly. In
core/class-facebookwordpresspixelinjection.php,inject_pixel_code()echoes hardcoded markup defined incore/class-facebookpixel.php(the$pixel_base_codeproperty andget_pixel_init_code()/get_pixel_track_code()), all as<script type='text/javascript'>…</script>. Because these are echoed inline rather than registered through WordPress’s script API, there is noscript_loader_tagfilter and no markup filter we can hook into. Our only option today is full-page output buffering with a regex rewrite, which is fragile and has caused “headers already sent” conflicts with page builders.Could you please consider one of the following:
- Preferred: register the pixel scripts via
wp_enqueue_script()/wp_register_script()and attach the inline pixel code withwp_add_inline_script(). This would let consent platforms and site owners modify the tag through the standardscript_loader_tagfilter (and properly handle the externalfbevents.jsload). - Minimum: add a filter on the generated script markup (e.g.
apply_filters( 'facebook_pixel_script_tag', $html, $context )) before it’s echoed, so the tag attributes can be modified without output buffering.
Either change would make the plugin compatible with consent management out of the box and remove the need for fragile workarounds. Happy to provide more detail or test a build.
Thank you!
- Preferred: register the pixel scripts via
You must be logged in to reply to this topic.