Add PayPalInsightsLoader for Axo Block

This commit is contained in:
Daniel Dudzic 2024-10-23 18:45:33 +02:00
parent 654fcfc521
commit c89da49e8f
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
2 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,35 @@
import { registerPlugin } from '@wordpress/plugins';
import { useSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import PayPalInsights from '../../../../ppcp-axo/resources/js/Insights/PayPalInsights';
const PayPalInsightsLoader = () => {
// Subscribe to checkout store data
const checkoutData = useSelect( ( select ) => {
return {
paymentMethod: select( 'wc/store/checkout' ).getPaymentMethod(),
orderTotal: select( 'wc/store/checkout' ).getOrderTotal(),
// Add other data points you need
};
} );
// Watch for changes and trigger analytics events
useEffect( () => {
if ( isScriptLoaded && window.YourAnalyticsObject ) {
// Example tracking calls
window.YourAnalyticsObject.track( 'checkout_updated', {
payment_method: checkoutData.paymentMethod,
order_total: checkoutData.orderTotal,
} );
}
}, [ isScriptLoaded, checkoutData ] );
return null; // This component doesn't render anything
};
// Register the plugin to run with the checkout block
registerPlugin( 'wc-ppcp-paypal-insights', {
render: PayPalInsightsLoader,
scope: 'woocommerce-checkout',
} );