Adobe DTM Custom rule conditions check for cookies

793 views Asked by At

I have some problems to get a specific rule to fire in DTM. And the documentation on custom rule conditions from Adobe is very basic. What is should do:

  • Check if a specific cookie exists (values of the cookie are irrelevant).
  • When this cookies does not exist fire the rule.

With this script this should work:

    var n = document.cookie, 
    i = "someCookie" + "=", 
    o = n.indexOf("; " + i); 
    if (-1 == o) { 
    if (o = n.indexOf(i), 0 != o) return null 
    } else { 
    o += 2; 
    var r = document.cookie.indexOf(";", o); - 1 == r && (r = n.length) 
    } 
    return unescape(n.substring(o + i.length, r)) 

But it does the exact opposite. When the cookie exists, the rule is fired.

1

There are 1 answers

0
CrayonViolent On BEST ANSWER

If you want to stick with using a Data > Custom condition, ultimately it must either return (bool) true if you want the condition to pass, or (bool) false if you want the condition to fail.

Simple Example:

Only trigger rule if js var foo equals "bar":

if ((typeof foo!='undefined')&&(foo=='bar'))
  return true;
return false;