Search code examples
cookiesadobeadobe-analytics

Adobe DTM Custom rule conditions check for cookies


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.


Solution

  • 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;