javascript - Why does Google Tag manager append at the end of the body? -


i trying implement google tag manager run problem since gtm appends tags right before closing tag of body.

whenever have template needs call bit of code 1 of scripts in google tag manager undefined error. obvious since not matter place script in view, gtm come after since appends right before closing body tag.

is there way fix behaviour , why google this? understand helps non-blocking might place async attributes on scripts , same?

an example have facebook pixel 1 of tags in gtm , need able make specific event call when loading page view.

fbq('track', 'search'); 

ofcourse needs fbq instance begin with. leave me 1 option , try , place script in footer general template , messy.

any workaround behaviour?

the issue facing facebook library not loaded when calling function. 1 method migrate facebook code gtm trigger on pages , fire specific code on dom ready

you use code below , see when _fbq.loaded variable set true. https://gist.github.com/chrisjhoughton/1dc91dd7bd95717e08d3

you have create trigger based on javascript variable. hope helps


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -