Google Tag Manager

This topic contains 12 replies, has 4 voices, and was last updated by  Paolo 6 years, 4 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #436493

    Tania Perez
    Full Member
    Post count: 299

    Hi guys,

    I´m trying to install Google Tag Manager using code snippets. I´m using Supreme Directory

    Google Tag Manager instructions are to “Copy the following JavaScript and paste it as close to the opening <head> tag as possible on every page of your website”

    I´m using this one for the header part:
    (add_action( ‘wp_head’, function () { ?>)

    And then “Copy the following snippet and paste it immediately after the opening <body> tag on every page of your website”

    And I don´t know what to use there, I tried:

    add_action( ‘wp_footer’, function () { ?>)
    add_action( ‘geodir_details_main_content’, function () { ?>
    add_action( ‘dt_after_header’, function () { ?>
    add_action( ‘body_class’, function () { ?>

    But none of those worked 🙂

    Could you help me with the right snippet please?

    Thank youuu!!

    #436503

    Alex Rollin
    Moderator
    Post count: 27815

    Try adding it to

    Geodirectory – Design – Scripts – Header script code

    #436519

    Tania Perez
    Full Member
    Post count: 299

    Thanks Alex, both parts?

    To implement Google Tag Manager on your website:

    Copy the following JavaScript and paste it as close to the opening <head> tag as possible on every page of your website, replacing GTM-XXXX with your container ID:
    <!– 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-XXXX’);</script>
    <!– End Google Tag Manager –>

    Copy the following snippet and paste it immediately after the opening <body> tag on every page of your website, replacing GTM-XXXX with your container ID:
    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-XXXX”
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>

    #436520

    Tania Perez
    Full Member
    Post count: 299

    Should I add the add_action part?

    #436521

    Tania Perez
    Full Member
    Post count: 299

    If I just copu and paste both of them it doesn´t work.

    I guess the header part is ok, but not the body

    Greetings

    #436522

    Tania Perez
    Full Member
    Post count: 299

    can you help with the right snippet?

    #436529

    Kor
    Moderator
    Post count: 16516

    Hi Tania,

    Could you share your WP admin access in private reply so that we could check your entry? Also, what’s your correct “GTM-XXXX” ID?

    #436538

    Tania Perez
    Full Member
    Post count: 299
    This reply has been marked as private.
    #436560

    Alex Rollin
    Moderator
    Post count: 27815

    This is for JS only: Geodirectory – Design – Scripts – Header script code

    PHP Snippets are added with the Code Snippets plugin.

    If it is only some header JS you can paste it into the field at:

    Geodirectory – Design – Scripts – Header script code

    #436604

    Tania Perez
    Full Member
    Post count: 299

    Thank you Alex, that´s exactly where I need help, inserting the second part after the <body> tag without touching the parent theme.

    This is what I need to insert:

    Copy the following snippet and paste it immediately after the opening <body> tag on every page of your website, replacing GTM-XXXX with your container ID:
    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-XXXX”
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>

    #436632

    Paolo
    Site Admin
    Post count: 31206

    did you try to add it in Geodirectory – Design – Scripts > Footer scripts?

    Let us know,

    Thanks

    #436671

    Tania Perez
    Full Member
    Post count: 299

    Paolo, it did 🙂

    I didn´t wanted to place it there since Google recommends to do it after body tag and not footer, to be more accurate, but it seems to be working.

    If there´s a way to do it after the body it would be awesome, if not, this can work for now

    Thank you!

    #436697

    Paolo
    Site Admin
    Post count: 31206

    Hi Tania,

    This is the typical structure of a WP theme page (simplified)

    
    
    <!DOCTYPE HTML>
    
    <html>
    
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<title>Your Website</title>
    </head>
    
    <body>
    
    	<header>
    		<nav>
    			<ul>
    				<li>Your menu</li>
    			</ul>
    		</nav>
    	</header>
    	
    	<section>
    	
    		<article>
    			<header>
    				<h2>Article title</h2>
    				<p>Posted on <time datetime="2009-09-04T16:31:24+02:00">September 4th 2009</time> by <a href="#">Writer</a> - <a href="#comments">6 comments</a></p>
    			</header>
    			<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
    		</article>
    		
    		<article>
    			<header>
    				<h2>Article title</h2>
    				<p>Posted on <time datetime="2009-09-04T16:31:24+02:00">September 4th 2009</time> by <a href="#">Writer</a> - <a href="#comments">6 comments</a></p>
    			</header>
    			<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
    		</article>
    		
    	</section>
    
    	<aside>
    		<h2>About section</h2>
    		<p>Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
    	</aside>
    
    	<footer>
    		<p>Copyright 2009 Your name</p>
    	</footer>
    
    </body>
    
    </html>
    

    While the header if before the Body tag, the Footer is after the body opening tag.

    So you it is perfectly placed to work correctly.

    Thanks

Viewing 13 posts - 1 through 13 (of 13 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount