• Resolved arthurlam1

    (@arthurlam1)


    I use Google Tag Manager to deploy tracking code on my site.

    I realized that on the checkout pages, somehow Google Tag Manager does not appear. For example: https://i.imgur.com/HSGtx2W.png. Only Google Analytics shows up. However, on other non-Carflows pages, Google Tag Manager will show up.

    Does Cartflows block the Google Tag Manager code? And how do I get it to work on Carflows pages?

    I suspect there is a separate header.php type of file for Cartflows pages so I may have to copy and paste Google Tag Manager script there for it to work? Normally to deploy Google Tag Manager, the code is copied into header.php in the WordPress theme.

    Thanks.

    • This topic was modified 4 years, 3 months ago by arthurlam1.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support CartFlows Team

    (@cartflows)

    Hello @arthurlam1

    Thank you for getting in touch with us!

    Actually, the CartFlows does not loads any header & footer on it’s pages if the post template is set to “CartFlows-Box” OR “Template for Page Builders” also the CartFlows pages are the different than the normal WordPress pages. Due to which the GTM plugin does not adds the GTM code on the CartFlows pages.

    But there is a way to add the Script on the CartFlows pages and that is using the actions that we have provided.

    So, you can use wp_head action to add the GTM script in the head tag of the CartFlows pages and cartflows_body_top action to add the GTM script in the body tag of the CartFlows pages.

    I hope this helps you.

    Feel free to get in touch in case you need more assistance.

    Thread Starter arthurlam1

    (@arthurlam1)

    Thanks @cartflows. I am not a technical person. This is my Google Tag Manager code as shown below. Can you please let me know (1) how to use your actions wp_head and cartflows_body_top and (2) where do I insert it?

    Paste this code as high in the <head> of the page as possible:
    <!-- Google Tag Manager -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
    <!-- End Google Tag Manager -->
    
    Additionally, paste this code immediately after the opening <body> tag:
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

    Thank you.

    Plugin Support CartFlows Team

    (@cartflows)

    Hello @arthurlam1

    Thank you for getting back to us!

    Here is the article for the wp_head action to ad the head script in your CartFlows pages.

    For example: Here is the way how you can use the wp_head to add the GTM code in the CartFlows pages.

    add_action( 'wp_head', 'ga_add_ga_code_in_head' );
    
    function ga_add_ga_code_in_head(){
    
    	$head_code = '';
    
    	$post_type = get_post_type();
    
    	if( 'cartflows_step' === $post_type ){
    		$head_code = "<!-- Google Tag Manager -->
    			<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    			new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    			j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    			'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    			})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
    			<!-- End Google Tag Manager -->";
    	}
    
    	echo $head_code;
    }

    Also below is the code which you can use to add the body script on the CartFlows pages.

    add_action( 'cartflows_body_top', 'ga_add_ga_code_below_body' );
    
    function ga_add_ga_code_below_body(){
    	
    	$field_code = '';
    
    	$field_code = '<!-- Google Tag Manager (noscript) -->
    		<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
    		height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    		<!-- End Google Tag Manager (noscript) -->';
    
    	echo $field_code;
    }

    I hope this helps you.

    Feel free to get in touch in case you need more assistance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Why doesn’t Google Tag Manager load on Carflows Checkout pages?’ is closed to new replies.