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

Filter wc_facebook_pixel_script_attributes doesn't change some events code #1268

Open
2 tasks done
fabiograsso opened this issue May 6, 2020 · 1 comment
Open
2 tasks done
Labels
feature: pixel events & conversion tracking Related to Facebook pixel, events, and conversion tracking. GDPR type: enhancement The issue is a request for an enhancement.

Comments

@fabiograsso
Copy link

fabiograsso commented May 6, 2020

🔎 Isolate the bug

  • I have confirmed this occurs in the most recent version of WordPress, WooCommerce, and Facebook for WooCommerce.
  • I have confirmed this occurs when only WooCommerce and Facebook for WooCommerce are active and when using a default WordPress or WooCommerce theme.

✍️ Describe the bug

I'm trying to fix an issue with my Cookie consent script (managed by Iubenda) that I've discussed here in issue #857 (link to my comment) and #301 (link to my comment). But leaving aside for a moment the reason why I need this (block cookie), I need to change the code around "<script" issued by your plugin and for doing this I've found a bug/limitation.

My idea is to change the HTML code provided by your script, by changing the filter wc_facebook_pixel_script_attributes. But it seems that only some pieces of your HTML code are changed while some events are still using the original code.

🚶‍♀️ Steps to reproduce

Add this function in theme's function.php:

add_filter('wc_facebook_pixel_script_attributes','wc_facebook_pixel_script_attributes_callback');
function wc_facebook_pixel_script_attributes_callback() {
  return array( 'type' => 'text/plain', 'class' => '_iub_cs_activate-inline', 'data-iub-purposes' => 5 );
}

✔️ Expected behavior

At this point I'm expecting that all the Javascript code inserted by your plugin will be changed. But I've found that was only changed the JS load script and the PageView event:


<script  type="text/plain" class="_iub_cs_activate-inline" "data-iub-purposes"="5">
	!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
	n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
	n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
	t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
	document,'script','https://connect.facebook.net/en_US/fbevents.js');
	</script>
	<!-- WooCommerce Facebook Integration Begin -->
	<script  type="text/plain" class="_iub_cs_activate-inline" "data-iub-purposes"="5">
	 
	fbq('init', 'xxxxxxxx', {}, {
	"agent": "woocommerce-4.0.1-1.11.2"
	});
	 
	fbq( 'track', 'PageView', {
	"source": "woocommerce",
	"version": "4.0.1",
	"pluginVersion": "1.11.2"
	} );
	 
	document.addEventListener( 'DOMContentLoaded', function() {
	jQuery && jQuery( function( $ ) {
	// insert placeholder for events injected when a product is added to the cart through AJAX
	$( document.body ).append( '<div class=\"wc-facebook-pixel-event-placeholder\"></div>' );
	} );
	}, false );
	 
	</script>
	<!-- WooCommerce Facebook Integration End -->

This is fine, but the other events (in page footer) have still the original code with type="text/javascript", example:


<!-- WooCommerce JavaScript -->
	
	<script type="text/javascript">
	jQuery(function($) {
	/* WooCommerce Facebook Integration Event Tracking */
	fbq('trackCustom', 'ViewCategory', {
	"source": "woocommerce",
	"version": "4.0.1",
	"pluginVersion": "1.11.2",
	"content_name": "Corsi",
	"content_category": "Corsi",
	"content_ids": "[\"wc_post_id_5974\"]",
	"content_type": "product"
	});
	});
	</script>

🗃 Logs

I have no useful logs to share

Do you have any suggestion on how can I change all the scripts type?

@fabiograsso
Copy link
Author

Hello again,
I've found the issue, and it's related to function inject_event in facebook-commerce-pixel-event.php: here you're invoking wc_enqueue_js that insert the pixel event code between other Woocomerce js code. This will ignore wc_facebook_pixel_script_attributes.

I propose to change behaviour of inject_event in order to not use wc_enqueue_js but print the full code with <script ...> and </script>.

I've made also a pull request with this changes: #1274

@haszari haszari added feature: pixel events & conversion tracking Related to Facebook pixel, events, and conversion tracking. GDPR type: enhancement The issue is a request for an enhancement. and removed skyverge-investigate labels Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: pixel events & conversion tracking Related to Facebook pixel, events, and conversion tracking. GDPR type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants