Load the rule when cookie exists | Community
Skip to main content
Level 2
Jul 9, 2019 7:39 PM UTC
Solved

Load the rule when cookie exists

Hello All,

How i can fire the rule when there is a cookie exists using Adobe DTM?

Thanks,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
kumararajak
kumararajakAccepted solution
Level 5
Jul 12, 2019 12:52 PM UTC

Hi Krishna,

To fire the rule when there is a cookie exists using Adobe DTM,

Please modify BOLD text from the below JS code as per your requirement and post in the "Customize Page Code" editor and also tick the Check box for Enable EU compliance for Adobe Analytics from the General settings

var loadRule = true;

var ck = getCookie('cookiename');

    if(ck=='cookievalue'){

        loadRule = false;

    }

return loadRule;

function getCookie(cname) {

  var name = cname + "=";

  var decodedCookie = decodeURIComponent(document.cookie);

  var ca = decodedCookie.split(';');

  for(var i = 0; i <ca.length; i++) {

    var c = ca[i];

    while (c.charAt(0) == ' ') {

      c = c.substring(1);

    }

    if (c.indexOf(name) == 0) {

      return c.substring(name.length, c.length);

    }

  }

  return "";

}

Refer the screen shots below

Hope this helps

Regards,

Kumararaja K

2 replies

kumararajak
kumararajakAccepted solution
Level 5
Jul 12, 2019 12:52 PM UTC

Hi Krishna,

To fire the rule when there is a cookie exists using Adobe DTM,

Please modify BOLD text from the below JS code as per your requirement and post in the "Customize Page Code" editor and also tick the Check box for Enable EU compliance for Adobe Analytics from the General settings

var loadRule = true;

var ck = getCookie('cookiename');

    if(ck=='cookievalue'){

        loadRule = false;

    }

return loadRule;

function getCookie(cname) {

  var name = cname + "=";

  var decodedCookie = decodeURIComponent(document.cookie);

  var ca = decodedCookie.split(';');

  for(var i = 0; i <ca.length; i++) {

    var c = ca[i];

    while (c.charAt(0) == ' ') {

      c = c.substring(1);

    }

    if (c.indexOf(name) == 0) {

      return c.substring(name.length, c.length);

    }

  }

  return "";

}

Refer the screen shots below

Hope this helps

Regards,

Kumararaja K

Translate
Employee
Jul 11, 2019 2:09 AM UTC

You may need to write a custom code in the condition of the rule which will check if the cookie exist then return 'true' which will allow the rule to fire else return 'false'.

Translate