How can i create new variable based on 2 separate current variable. The main condition is to check the existance of array or widget selector, and then return it's value:
function() {
var array = Array.prototype.slice.apply(document.querySelectorAll("div.widget-message.active.active-target a"));
var length = array.length;
var x = array.map(function(cn, index) {
var nameId = cn.href.split("?")[0].split("/").slice(-1)[0].replace("-", " ");
var urlParams = {{cjs - utility - url params}}(cn.href);
var name = urlParams.promo_name;
var creative = urlParams.promo_content;
return {
"name": "Widget - Personal - " + name,
"id": "Widget - Personal - " + nameId + "-" + index,
"position": "" + (index + 1) + "/" + length,
"creative" : creative,
"metric3": 1
}
});
return {
'ecommerce': {
'promoView': {
'promotions': x
}
}
}
}
and the second one is
function() {
var array = document.querySelector('[class="btn-new btn-fullwidth popup-trigger"]');
return {
'ecommerce': {
'promoView': {
"name": "Widget - Personal - " + array.dataset.targetId
}
}};
}
if (var array = ...does not make sense for an if statement. When should the if be true, whenlength > 0I presume?xAND the other selector's name? Or just one or the other? You can only return one thing in the function. Can you just have separate data layer variables for them and use them separately in TagManager? Or what it is that you want to combine? By the way, put the three ` in a separate line so the formatting shows. I'll edit for you.