• Hello Duracelltomi,

    I’m using your great plugin with WC integration and only data layer injection.
    On the checkout page (https://wp-ok.it/checkout/) I have a JS error:

    Uncaught ReferenceError: jQuery is not defined
        at (index):707

    The code there is:

    <script data-cfasync='false' type='text/javascript'>
    	(function($) {
    		if ( $( '.gtm4wp_productdata' ).length > 0 ) {
    			for( var i=0; i<dataLayer.length; i++ ) {
    				if ( dataLayer[ i ][ 'ecomm_prodid' ] ) {
    					break;
    				}
    			}
    
    			if ( i == dataLayer.length ) {
    				// no existing dyn remarketing data found in the datalayer
    				i = 0;
    				dataLayer[ i ][ 'ecomm_prodid' ] = [];
    			}
    
    			if ( typeof dataLayer[ i ][ 'ecomm_prodid' ].push == 'undefined' ) {
    				return false;
    			}
    
    			var productdata;
    			$( '.gtm4wp_productdata' ).each( function() {
    				productdata = jQuery( this );
    
    				dataLayer[ i ][ 'ecomm_prodid' ].push( '' + productdata.data( 'gtm4wp_product_id' ) );
    			});
    		}
    	})(jQuery);
    </script>

    Is this a bug of the plugin or am I missing something?
    Note that I have CloudFlare active.

    Thanks
    WP-OK

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi,

    Since my codes use jQuery heavily, it is important that jQuery is loaded the head. I know that this might be against some performance best practices but currently this is the only way to get rid of those JS errors.

    I am working on moving inline JS codes to separate .js files so that my plugin can benefit from the features of WP to prioritize JS loading.

    Thread Starter Daniele

    (@dabesa)

    Hello Duracelltomi.

    Sorry if I took so long to come back to you on this.
    It was indeed the ‘rocket launcher’ feature in CloudFlare, that caused the JS to load async hence breaking your code.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘JS error in WC checkout’ is closed to new replies.