Search code examples
javascriptjqueryadobe-analytics

Can you call or use a Data Element on a Custom Page Code? like the variables in GTM


in GTM you can use {{element}} to use on your custom JavaScript tag so I was wondering if there is a way in DTM to call other data elements in your custom page code?

And also I'm trying to get the value of eVar 1 and then output a string but haven't gotten this to work

function MyCase(){ 
var url;
var txt = s.eVar1;

switch (txt) {
    case 'Forewords':
        url = "forwords";
        break;
    case 'Executive Summary':
        url = "executive-summary";
        break;
    case 'Educating':
        url = "education";
        break;
    case 'Social engage':
        url = "social";
        break;
    case 'Next generation':
        url = "next-gen-retirement";
        break;
    case 'Conclusion':
        url = "conclusion";
        break;
    default:
	url = '';
	break;
	}
return url; 
}
MyCase();


Solution

  • You can use _satellite.getVar('data_element_name_here') to get the value of a data element.

    As to your eVar1 question: At face value, it doesn't look like you call MyCase() and it returns a value, but you aren't actually doing anything with it. What are you trying to do with it? For example, you can:

    // will output the returned value in the javascript console
    console.log(MyCase());
    
    // assign the returned value to a variable called someVar
    var someVar=MyCase();
    
    // create an on-the-fly data element
    _satellite.setVar('someVar',MyCase());