Mapping data sources with custom vars

Bronze Contributor
Bronze Contributor
Good afternoon, I am working with an account and I have mapped some SiteCatalyst variables (prop1, prop2,...) with existing data sources. For example, the destination of version_s_code(js) are prop24 and eVar24. The destination of idioma_pagina(js) are prop27 and eVar27. The problem is that I would like to assign a value to these data sources from a Javascript Code extension but it seems like it is not possible. In my do_plugins extension I do something like this: b.version_s_code="20131125"; b.idioma_pagina="Castellano"; Could you help me? Is it possible to assign the value to my traffic and custom variables in SiteCatalyst using this code? Please answer me as soon as possible. Thank you very much. Best regards,
5 REPLIES 5

Mapping data sources with custom vars

Employee Emeritus
Hello Myrtha, If you want to assign a value to a data source you should be able to accomplish this through a "Set Data Values" extension. Set version_s_code to Text 20131125 and idioma_pagina to Text Castellano -- add a condition if needed. If you need these values to be dynamically set then a JavaScript extension might be in order. Does this help?

Mapping data sources with custom vars

Tealium Employee
Jim is correct. These should be set in a Set Data Values extension if they are static variables. I just want to add a bit of extra information for future readers. Depending on the dynamic nature of the variable, if applicable, you could still do it in a Set Data Values extension. For example, to get the current date you could set "your_variable" to "JS Code" with an input of: (function(){var t=new Date();var y=t.getFullYear();var m=t.getMonth();var d=t.getDate();var a=y+""+m+""+d;return a;})(); which gets the current date in "20131220" format. Best practices is that the doPlugins JS extension should only contain the doPlugins code.

Mapping data sources with custom vars

Employee Emeritus
To take this one step further, in the doPlugins code the "b" object isn't initiated which is why the original method wasn't working. Dan and Jim are correct that this should probably be done in a Set Data Values Extension then you can use the mappings that are currently set up. For future information, you can set props/eVars directly in the doPlugins function but they have to be referenced directly instead of using the "b" object like so: s.prop24=s.eVar24="20131125"; s.prop27=s.eVar27="Castellano"; This will set the props and eVars directly and can remain in the doPlugins function if desired.

Mapping data sources with custom vars

Bronze Contributor
Bronze Contributor
Thank you very much for your help. I think I will not use the "b" object in my JavaScript code.

Mapping data sources with custom vars

Employee Emeritus
For advanced JS coders reading this in the future, here's the order of events firing: 1. Extension code executes. Any code that sets fields on the 'b' variable will work fine. You can have this line in a JS Code extension as long as it is NOT inside a function. b.version_s_code="20131125"; 2. Mappings are run. If you have a mapping from version_s_code to prop24 and eVar24 then they will be set correctly on the SiteCat tag. 3. The SiteCatalyst tag executes, and it calls doPlugins(). That means that when the doPlugins code executes, it's too late to use Tealium mappings to set data fields. Here is a code example to summarise this: ////////// JS Code extension /////// // Will be picked up by mappings b.version_s_code="20131125"; function s_doPlugins() { // b is not defined here but you can use props and eVars directly s.prop24=s.eVar24="20131125"; } s.doPlugins = s_doPlugins; ////////// End of extension //////// As Dan rightly says, best practice is to keep these two pieces of code in separate extensions, because of the risk of confusion with different scopes.
Public