- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
01-27-2017 05:36 PM
Hello! I would like to add a custom Javascript at the start of <body> tag using Tealium Generic Tag.
Here is an example of the JS:
<script id="custom_tag" type="text/javascript" src="//abc.xyz/123.min.js" async></script>
The are two questions here:
1. How can I add the ID attribute via Tealium Generic Tag?
2. How can I set it to be inserted at the start of <body> tag?
Thanks!
Solved! Go to Solution.
01-30-2017 09:17 AM - last edited on 01-31-2017 06:01 AM by adrian_browning
@ayuktanon In order to add a custom attribute to a tag you will need to use a custom container with a customized loader call. To do this, add the custom container to your profile and edit the template by pasting in the following:
(function (a, b, c, d) { a = '//abc.xyz/123.min.js'; b = document; c = 'script'; d = b.createElement(c); d.src=a; d.setAttribute('data-id', 'custom_tag'); d.type = 'text/java' + c; d.async = true; a = b.getElementsByTagName(c)[0]; a.parentNode.insertBefore(d, a); })();
Within this function you will set 'a' (your library URL to call) as well as the attributes you want created for this call (i.e. data-id, etc.).
As for the tag to be executed at the top of the body, this tag will fire in respect to wherever utag.js is coded into the page source. Best practice is to have utag.js added at the top of the body. If utag.js on your page is located somewhere else, the tag will be loaded in at that designated position.
Hope this helps,
Chris
02-06-2017 03:52 PM
Copyright All Rights Reserved © 2008-2023