• Resolved Ishko

    (@ishko)


    Hello,

    A JS error is fired in the console about gtm4wp_business_vertical on every pages of our website. I can’t find why, even after several tests and configuration changes.
    I used your guide to configure the woocommerce integration options (https://gtm4wp.com/how-to-articles/how-to-setup-dynamic-remarketing-in-google-ads-adwords).

    GTM4WP configuration :
    Google Ads Remarketing : unchecked
    Google Ads Business Vertical: Retail
    Product ID prefix: unset
    Use SKU instead of ID: unchecked

    The error, in Chrome browser console :

    Uncaught ReferenceError: gtm4wp_business_vertical is not defined
        at gtm4wp_map_eec_to_ga4 (gtm4wp-woocommerce-enhanced.js?ver=1.14.2:54)
        at gtm4wp-woocommerce-enhanced.js?ver=1.14.2:348
        at NodeList.forEach (<anonymous>)
        at gtm4wp_process_woocommerce_pages (gtm4wp-woocommerce-enhanced.js?ver=1.14.2:324)
        at HTMLDocument.gtm4wp_page_loading_completed (gtm4wp-woocommerce-enhanced.js?ver=1.14.2:1196)

    Note that I’m new to GTM usage and configuration and may have missed something obvious…

    Could you help me with this issue ?
    Best regards

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

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

    (@duracelltomi)

    Hi,

    There is some sort of code optimization active on your site that removes line breaks in added codes. This changes this code:

    <script data-cfasync="false" data-pagespeed-no-defer type="text/javascript">//<![CDATA[
    	var gtm4wp_datalayer_name = "dataLayer";
    	var dataLayer = dataLayer || [];
    	const gtm4wp_use_sku_instead        = 0;
    	const gtm4wp_id_prefix              = 'feed_prefix';
    	const gtm4wp_remarketing            = 1;
    	const gtm4wp_eec                    = 1;
    	const gtm4wp_classicec              = false;
    	const gtm4wp_currency               = 'EUR';
    	const gtm4wp_product_per_impression = 5;
    	const gtm4wp_needs_shipping_address = false;
    	const gtm4wp_business_vertical      = 'retail';
    	const gtm4wp_business_vertical_id   = 'id';
    //]]>
    </script>

    … to this:

    <script data-cfasync="false" data-pagespeed-no-defer type="text/javascript">//<![CDATA[var gtm4wp_datalayer_name = "dataLayer";var dataLayer = dataLayer || []; ...

    With that, the browser treats this line as a simple comment and wouldn’t execute the code resulting in an error on your site.

    I guess the cdata markup is not needed anymore in 2022. I will remove it in the next version. Until then, could you instruct your code optimization plugin not to change the code in the script blocks of GTM4WP?

    Plugin Author Thomas Geiger

    (@duracelltomi)

    Thread Starter Ishko

    (@ishko)

    Thank you very much for your explanations.

    Indeed, this site uses WP-ROCKET, which compresses the scripts of the page.

    The application of code changes in the core of the plugin, according to your instructions (https://github.com/duracelltomi/gtm4wp/commit/d6f145f8bda47fe516477e0db498c478d29cb2e7), solved the problem.

    It seems worth removing the CDATA markup, many sites use caching or optimization plugins that compress scripts and html.

    Please apologies for my late feedback and thanks again for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘JS error ‘gtm4wp_business_vertical is not defined’’ is closed to new replies.