This is my first question in the forum. I've searched a lot before asking you guys, but maybe because I'm still building my JavaScript skills, I couldn't figure it out.
I'm trying to pass a object as an argument dynamically, according to the URL like shown below.
let createDataLayer = () => {
//Creating objects with the values for each page
someurl = {
pageType: 'Content',
institution: 'Institution',
contentTopic: 'Membership',
productCategory: '',
productName: '',
};
//Attaching the right array to the actual url
let actualURL = "/some-url/";
actualURL = actualURL.replace(/-/g,"");
actualURL = actualURL.replace(/\//g,"");
//Function that applies the right content to the right page
let applyingContent = (variable) => {
console.log("Always come as string: ", typeof variable); //string
console.log("Can't access the object: ", variable.pageType); //undefined
console.log("If I call the variable itself, it's here: ", someurl); //the object logs ok
window.dataLayerValues = [variable.pageType, variable.institution, variable.contentTopic, variable.productCategory, variable.productName];
return window.dataLayerValues;
}
applyingContent(actualURL);
}
createDataLayer();
Can anyone help me, please?
I appreciate it so much!
actualURLwhich is a string. What do expect?