| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Include GTM Script immediately after <body> tag? | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Include GTM Script immediately after <body> tag?
Having a really tough go at getting my Google Tag Manager code to appear right after the <body> tag. I have the GTM being included in custom module, which is working great, except I can't get it to appear in the correct location. Google demands that the GTM script appear immediately after the <body> tag.
I am able to insert the script successfully into the <head> tag, but when I try to reconfigure to have it be included right after the opening <body> tag, I can never seem to get to it display before the <nav id="slider"> tag. Even when my GTM tpl has @ListChild (list="layout.slidebar", weight="5"), the <nav id="slider"> always appears first. When my GTM tpl has @ListChild (list="body", weight="5"), it also does not appear immediately after the <body> tag. I even tried setWeight(100) on 'XLite\View\Slidebar' in my runBuildCacheHandler, which changed the weight in the DB from 10 to 100, but didn't change the frontend hierarchy. Any suggestion will be greatly appreciated. I'm running out of ideas :/ Thanks! -Paul
__________________
X-Cart Version: 5.2 |
|||||||
#2
|
|||||||
|
|||||||
Re: Include GTM Script immediately after <body> tag?
In addition to trying to use a few combos of @ListChild list="body" and list="layout.slidebar" with my custom .tpl I also tried an alternate approach modifying the skins/mytheme/customer/en/body.tpl template like below, where getGTMCode() is a function defined in my custom module:
Code:
This produces output on the frontend that looks like this (I've simplified it for clarity), where the #slidebar nav element is still above the GTM code: Code:
I greatly prefer NOT having to customize body.tpl, because then my module is dependent on my custom theme. Any suggestions? Looking forward to any ideas EDIT: In the second code example above I noticed that when viewing page source (as opposed to looking at the markup in Dev Tools), the GTM script is being placed above the <nav id="slidebar"> element, so I assume that #slidebar is being moved by some JS at runtime. So when decorating body.tpl, I get the placement I want, but then my custom module is theme-dependent, which is not ideal. How do I achieve the same script placement in my module without making it theme-dependent?
__________________
X-Cart Version: 5.2 |
|||||||
#3
|
|||||||
|
|||||||
Re: Include GTM Script immediately after <body> tag?
HI Paul, Did you ever get any help with this, or work it out yourself? I'm trying to do the same thing, (though with x-cart 5.3 and even less documentation). It seems crazy that it's so hard to put GTM code in x-cart. If you have any insights please let me know. Thanks
__________________
5.3.1.3 |
|||||||
#4
|
|||||||||
|
|||||||||
Re: Include GTM Script immediately after <body> tag?
You can use the attached custom module for injecting Google Tag Manager code's into all your X-Cart 5.3.x website pages.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#5
|
|||||||
|
|||||||
Re: Include GTM Script immediately after <body> tag?
Quote:
Does similar code available for x-cart classic also ?
__________________
X-Cart: 4.7.7 LIVE Skin:Ultra by xcartmods.co.uk X-cart Modules: | ACR, Rich Google Search, Customer Testimonials | Cloud Search, | Websitecm: CDSEO (2.1.9) --------------- Server: Linux php: 5.3 mysql: 5.0.89 ---------------- |
|||||||
#6
|
|||||||||
|
|||||||||
Re: Include GTM Script immediately after <body> tag?
As far as I know there is no ready-made module for X-Cart 4 and you will have to edit core files manually.
I can't remember if anyone shared their tweaks for X-Cart 4 in these forums (at least I can't find one at the moment).
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#7
|
|||||||
|
|||||||
Re: Include GTM Script immediately after <body> tag?
Quote:
Or is there some other way? Please explain, thanks!
__________________
5.3.1.3 |
|||||||
#8
|
|||||||||
|
|||||||||
Re: Include GTM Script immediately after <body> tag?
Please use the "Upload add-on" button on the "Modules" back-end page.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#9
|
|||||||||
|
|||||||||
Re: Include GTM Script immediately after <body> tag?
There is a free ready-made module now:
https://market.x-cart.com/addons/google-tag-manager.html
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
|
|||
X-Cart forums © 2001-2020
|