Expand my Community achievements bar.

DTM: which JS is correct?

Avatar

Level 3

Hi All

I am trying to set some variables on a particular page. Page can be identifiable by document.title only.

So I did the following: created a load rule and chose in the Conditions "custom" where I tried to place different versions of the code: 

return ((document.title.match("1.3.3-make-a-payment")? true : false) return (document.title.match("1.3.3-make-a-payment")) ? true : false; return (document.title==“1.3.3-make-a-payment") ? true : false; 
return ((document.title.match("1.3.3-make-a-payment"))? true : false);
return ((document.title.match("1.3.3-make-a-payment"))? true : false)
return ((document.title=="1.3.3-make-a-payment"))? true : false)

The last one returns 'true' in the console but does not work in DTM. 

if (document.title =="1.3.3-make-a-payment"){ var zho = true;} else { var zho= false;} return zho; 

Which one is correct?

Did I use a correct approach?

1 Reply

Avatar

Level 10

Hi,

I'm going through some old threads and closing them out.

I'm assuming this question has been answered already, but I'd recommend creating a data element. The data element could have code that pulls the document.title of the page and stores it within the data element. Each rule could then be conditional on the data element equaling a certain value (ie name of the page).

Cheers,
Jantzen