Why doesn't HTML have a "Slogan" tag?

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

Was this solution helpful to you?

Other answers

.ready() method is the solution for this issue. For more information: http://api.jquery.com/ready

Vinoth Periasamy

Related Q & A:

Just Added Q & A:

Find solution

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.