I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Gold Contributor
Gold Contributor
I need to load a js file that puts a variable, wfxtrigs, in the global namespace. Then, I need to process this variable into a js_page variable that can be mapped into the Google Publisher Tag(GPT). I want to use Tealium to do this, so that it can easily be turned on or off. I tried using the Tealium Custom Container tag and setting the Custom Script Source to the url of the js file. Since this file returns a basic js variable assignment, I get a warning that the page was interpreted as script but returned as plain text. It does load the variable in the global namespace, but it is not there before the GPT processes. Is there a prescribed way in Tealium to do what I want to do?
8 REPLIES 8

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Tealium Employee
Hi Steve, Your general understanding of what needs to be done is spot on. You state that the variable output of the file is wfxtrigs, but I do not see this variable declared in the UI. Looking at the configs I only see wfxtg which also happens to be mapped to GPT. Is there any reason for the name change?

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Employee Emeritus
Hey Steve, I think the problem is that the Custom Container code that sets the global variable is loading after Tealium's code runs that defines the js_page variables. So that global variable isn't getting picked up in the Tealium object and isn't available to map. I would suggest the following to begin with: 1) Make sure the Custom Container Tag is above the GPT tag in the list of tags. Now since this code is going to run after Tealium grabs the data from the page we will need to set up an extension to set the global variable to a variable in the Tealium object. 2) Add a Data Source called wftxtrigs and leave the type as Data Object. 3) Set Data Values extension that is configured like: Set: wftxtrigs (js) To: JS Code -->Type in "wftxtrigs" (not Quotes) Make sure this extension is scoped to the GPT tag. This will grab the wftxtrigs variable that was set in the Custom Container and set it into a variable that we can then map to the GPT tag. 4) Map the wftxtrigs (js) variable to the GPT tag as needed. That should take care of it, but because we can't control when that external script will load all of the time (nature of asynchronous loading) you may want to look at this other method: Again make sure the Custom Container Tag is above the GPT tag in the list of tags. 1) Open the js file you are trying to load and copy the entire contents. 2) Open the Template for the Custom Container and paste the JS file contents between these lines: /* Start Tag Library Code */ /* End Tag Library Code */ Now since this code is going to run after Tealium grabs the data from the page we will need to set up an extension to set the global variable to a variable in the Tealium object. 3) Add a Data Source called wftxtrigs and leave the type as Data Object. 4) Set Data Values extension that is configured like: Set: wftxtrigs (js) To: JS Code --> "wftxtrigs" (not Quotes) This will grab the wftxtrigs variable that was set in the Custom Container and set it into a variable that we can then map to the GPT tag. Make sure this extension is scoped to the GPT tag. 5) Map the wftxtrigs (js) variable to the GPT tag as needed.

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Gold Contributor
Gold Contributor
I have it working now, but the ads load extremely slowly with the wfxtriggers Tealium Custom Container turned on. If I turn this tag off, the ads load much faster.

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Employee Emeritus
Did you try the second method of placing the code directly into the Custom Container? It should speed it up quite a bit because it eliminates the need to call out to the other server to load the file.

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Gold Contributor
Gold Contributor
Unfortunately, this is a third party script. The response is not constant.

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Gold Contributor
Gold Contributor
Do you know if there is a way to aggregate all Tealium utag scripts into one js file?

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Employee Emeritus
Check out the Bundle Libs section of this post: https://community.tealiumiq.com/posts/705799 NOTE: This will only bundle the tags that are set to load on All Pages.

I need to load a js file in line and then get a variable that this file sets into the Google Publisher Tag(GPT).

Gold Contributor
Gold Contributor
I got it working. The wfxtrigs is a string that needs to be processed to then create wfxtg, which I map to GPT. Thanks for your response
Public