New Landing How can we help? Atelier Google tag manager

Viewing 15 posts - 1 through 15 (of 17 total)
  • Posted in: Atelier
  • #257189
    skullo27
    Member
    Post count: 217

    Hi, I am trying to implement Google Tag Manager for my site.

    It requires a line of code be added to my theme file inside the <body> tag, I was wondering how I can implement this without that code being over written each time the theme is updated?

    I did think of using a child theme, but my site ran really slow when using it so I turned it off.

    Any thoughts would be greatly appreciated.

    thanks
    Sam

    #257192
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    You can add that to Theme Options => Custom JS.

    Thanks.

    #257215
    skullo27
    Member
    Post count: 217

    Hi thanks that makes sense, so would that insert the GTM script in the right place?

    thanks

    #257234
    David Martin – Support
    Moderator
    Post count: 20834

    Yes, that is correct.

    Thanks.

    #257449
    skullo27
    Member
    Post count: 217

    Hi, I am using a plugin (https://wordpress.org/support/plugin/duracelltomi-google-tag-manager) to integrate with GTM. it asks to put a piece of PHP code in rather than the GTM script. Can you advise if there is a way to insert that without editing the theme template files?

    Many thanks.

    #257450
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    No that is not possible.

    – Let me know what it asks you to do and I’ll advise.

    Thanks.

    #257457
    skullo27
    Member
    Post count: 217

    HI, thanks, I have attached a screen grab. Please let me know how you think best to manage this. I think your suggestion of puting the GTM code in the custom JS could be an option, however I think it would mean doing the whole integration manual and not using the durall tomi plugin as I tried it with the plugin and it did not work.

    thank again.

    Attachments:
    You must be logged in to view attached files.
    #257465
    skullo27
    Member
    Post count: 217

    could there be a way to insert this PHP using the Snippets plugin that I use for other things?

    #257530
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    You can insert through Snippets plugin.
    Thanks
    Mohammad

    #257556
    skullo27
    Member
    Post count: 217

    Hi Mohammad, I tried using the below PHP using the snippets plugin and when I do my analytics tags vanish…

    <?php if ( function_exists( ‘gtm4wp_the_gtm_tag’ ) ) { gtm4wp_the_gtm_tag(); } ?>

    Any thoughts why that might be?

    Is there any way you could include it in an update of the theme? I imagine lots of users are struggling with this issue (they will be if they what to use GTM)… also it is a generic piece of code so the same for any installation of Duracell Tomi’s GTM plugin. If not any other ideas I can add the GTM code without editing the theme? I tried pasting manually the code direct from GTM into the Custom JS as suggested above but that did not seem to work, maybe it does not place it in the correct place on the page? It needs to be immediately inside the <body> tag.

    I notice using Google tag assistant you have analytics tags active on the Atelier site, how did you guys do it?

    Many thanks for the continued support.

    Sam

    #257559
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please paste this code at functions.php of child theme:-

    add_action('wp_head', 'sf_gtm');
    function sf_gtm(){
     if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } 
    return;
    }

    Thanks
    Mohammad

    #257565
    skullo27
    Member
    Post count: 217

    Hi Mohammad, thanks I will try this. Please clarify, I do not use a child theme… can it be added using the Snippets plugin?

    Code Snippets

    I use this for other code additions.

    Thanks
    Sam

    #257568
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    You can add it through snippet plugin.
    Thanks
    Mohammad

    #257592
    skullo27
    Member
    Post count: 217

    Hi Mohammad, I tried this but the GTM assistant then says the code is outside the <body> tag… does that sound right to you?

    I was looking at this: http://www.affectivia.com/blog/placing-the-google-tag-manager-in-wordpress-after-the-body-tag/

    Bud could not get it to work because your theme file header.php has a different value than <?php body_class(); ?>. Based on this link is there a way to adit the snippet you gave me to be compatible with this technique?

    Sorry I am no a programmer, but do have understanding of code.

    thanks
    Sam

    #257601
    skullo27
    Member
    Post count: 217

    Hi So I tried this and it seemed ok, I placed this code in the snippet plugin, would you mind looking at it to check it will not cause any theme issues and would in fact place in the body tag?

    thank you.

    add_filter( ‘body_class’, ‘gtm_add’, 10000 );

    function gtm_add( $classes ) {

    $block = <<<‘BLOCK’

    <!– Google Tag Manager –>
    <noscript><iframe src=”//www.googletagmanager.com/ns.html?id=GTM-WX9PHM”
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <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=
    ‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,’script’,’dataLayer’,’GTM-WX9PHM’);</script>
    <!– End Google Tag Manager –>

    BLOCK;

    $classes[] = ‘”>’ . $block . ‘<br style=”display:none’;
    return $classes;
    }

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register