Add custom JS with ID attribute using Tealium Generic Tag

Bronze Contributor
Bronze Contributor

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!

2 REPLIES 2

Add custom JS with ID attribute using Tealium Generic Tag

Employee Emeritus

@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

Add custom JS with ID attribute using Tealium Generic Tag

Bronze Contributor
Bronze Contributor
Thank you for the answer!
Public