Is there a way to put custom HTML tag after jquery script?
-
I am using Google Tag Manager to track Universal Analytics events. I am putting a couple of custom HTML tags to subscribe to some click events using jQuery. The problem: jQuery code is added at the bottom of body tag (and I can't change that). GTM puts its custom HTML randomly before or after jQuery, so sometimes I get the "undefined variable $" error. Of course I can check if jQuery is loaded at the moment of event subscription but this way I will lose events on some pages. The question: is there a way to control custom HTML tag positioning in GTM? Or is there another way to avoid my problem?
-
Answer:
How come jQuery is being loaded at the end of your HTML code? It's a bit unusual. jQuery should typically be loaded at the top of the page so the library is available for use anywhere within the page. If you can, you should ask your developer to move jQuery so it's loaded before the GTM snippet. GTM tags will not start loading until the browser reaches the GTM snippet. Since the jQuery library doesn't load asynchronously, if you put it before the GTM snippet, you'll be sure $ is defined by the time it gets used in any tag fired by GTM. Otherwise, there's a way to somewhat control the position of the tags in GTM. Make sure they fire when the DOM is ready using the rule event equals gtm.dom. Then, you can write some Javscript to insert your tag script at the bottom of the page.
Lothaire Ruellan at Quora Visit the source
Other answers
.ready() method is the solution for this issue. For more information: http://api.jquery.com/ready
Vinoth Periasamy
Related Q & A:
- What is an easy way to put a song on my Yahoo 360?Best solution by Yahoo! Answers
- How can I put custom firmware on my PSP without a Pandora battery?Best solution by Yahoo! Answers
- Is there a way to put my entire Myspace in a scroll box?Best solution by myspacegens.com
- Is there any way to put a video on yahoo?Best solution by Yahoo! Answers
- How do I put an html code in a scroll box?Best solution by html.am
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.