Setting a utag_main cookie value to a dynamic parameter

Gold Contributor
Gold Contributor

We have some code where we loop through several parameter/value combination to set them into the utag_main cookie.

E.g.:

var dynamicpar = "parameter_name_for_this_loop";
utag.loader.SC("utag_main", {
[dynamicpar]: "somevalue"
});

This sets utag_main parameter to "parameter_name_for_this_loop":"somevalue". It works in most browsers, but not in IE11...

How can we set the name of a parameter in the utag_main cookie dynamically for all browsers? Is it possible at all?

 

5 REPLIES 5

Setting a utag_main cookie value to a dynamic parameter

Tealium Expert
Tealium Expert

Computed keys are a feature of ES6 and are not available in older JS implementations.

The easiest way to get it to just work would be:

var dynamicpar = "parameter_name_for_this_loop";
var cookie_payload = {};
cookie_payload[dynamicpar] = "somevalue";
utag.loader.SC("utag_main", cookie_payload);


Wherein you initialise an empty object, and then set the dynamic key to the desired value using the traditional mehod.

Setting a utag_main cookie value to a dynamic parameter

Gold Contributor
Gold Contributor
That effectively solves my problem. Wonderful, thank you!

Setting a utag_main cookie value to a dynamic parameter

Moderator
Moderator

I'd say @loldenburg that @UnknownJ deserves to have his post "Accepted as a Solution" #winkwink

If you liked it then you should have put a kudo on it!

Setting a utag_main cookie value to a dynamic parameter

Gold Contributor
Gold Contributor
did that now, sorry

Setting a utag_main cookie value to a dynamic parameter

Moderator
Moderator

Yay @loldenburg! #hugs

If you liked it then you should have put a kudo on it!
Public