Please help me understand this piece of code in Tag Template .

AdityaTiwari
Rookie Contributor
AdityaTiwari

Hii All,
Need to understand what are b[d],e[f] and u.map.

/* Start Mapping Code */

for (d in utag.loader.GV(u.map)) {
if (b[d] !== undefined && b[d] !== "") {
e = u.map[d].split(",");
for (f = 0; f < e.length; f++) {
u.data[e[f]] = b[d];
}
}
}
/* End Mapping Code */

Thanks.

2 REPLIES 2
Highlighted

Please help me understand this piece of code in Tag Template .

Tealium Expert
Tealium Expert

Hi @AdityaTiwari,

utag.loader.GV is a function that returns the properties of an object that pass the hasOwnProperty check

u.map is an object that contains the mapping of UDO variables to vendor parameters (as configured in the Tags tab of TIQ), so for example:

u.map = {
  page_title: "WT.ti",
  page_category: "WT.cg_n,DCSext.page_category"
}

So that first line of code iterates over that mapping object, where each loop has "d" taking the value of each UDO element that's to be mapped to a vendor parameter.

In the second line then, b[d] is the current value of that UDO element in the current data payload that's been passed into the tag. The if statement checks that the variable for mapping is defined and not blank within the current payload. An undefined or blank UDO element won't be mapped into the tag.

The third line then looks up the target vendor parameter, and splits it on a comma in order to produce an array, since a single UDO variable can be mapped to multiple vendor parameters.

The fourth line then iterates over that array, so e[f] represents each individual vendor parameter.

The fifth line then might otherwise read as:

tag.data[target_variable] = payload[udo_variable]

Based on that mapping defined in the interface and stored in u.map.

So in the mapping example above, we might end up with the following assignments being made:

u.data["WT.ti"] = payload["page_title"];
u.data["WT.cg_n"] = payload["page_category"];
u.data["DCSext.page_category"] = payload["page_category"];

Hope that helps, let me know if you need any further clarification.

Please help me understand this piece of code in Tag Template .

Tealium Expert
Tealium Expert

Gasp! @UnknownJ you speak Webtrends!