Expand my Community achievements bar.

SOLVED

Launch Rule to fire when cookie is accepted or cookie is already on browser

Avatar

Community Advisor

Hi. I am looking to implement a Launch rule to trigger when either a user clicks on accept cookie banner or a cookie is already existing on the user browser? what could be the custom code in Launch? Any Step by Step information? Or any other direct way to implement the rule?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can have 2 Rules:

  1. Rule with:
    1. Click event on the cookie banner's "Accept" button
  2. Rule with:
    1. Library Loaded event
    2. Condition that checks for the presence of the cookie

When new users click on the Accept banner, they would cause the 1st Rule to trigger. I assume the cookie banner then sets the cookie.

Subsequently, these users who had already granted consent would have the cookie in their browser, so every page they visit would cause the 2nd Rule to trigger.

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

You can have 2 Rules:

  1. Rule with:
    1. Click event on the cookie banner's "Accept" button
  2. Rule with:
    1. Library Loaded event
    2. Condition that checks for the presence of the cookie

When new users click on the Accept banner, they would cause the 1st Rule to trigger. I assume the cookie banner then sets the cookie.

Subsequently, these users who had already granted consent would have the cookie in their browser, so every page they visit would cause the 2nd Rule to trigger.

Avatar

Community Advisor
Thanks @juhuisg For the second rule where you asked to create a library loaded event and then check for the condition Cookie, What to do incase if the cookie value changes and is unique for each user? For example if we have ISO date format as value for each accepted cookie.

Avatar

Community Advisor
@JyotiSharmaV I guess you have 2 options: if there's some string in the cookie's value that's always constant, then you can check if the cookie value contains that string. Otherwise, you can check if the cookie is set or not, based on its name (assuming that it could only have been set after the user had granted consent).

Avatar

Community Advisor
@yuhuisg Yes, the cookie value is different for different users for example in "date format". But in condition how can i check for if cookie is set or not? Do I have to write any custom code? Can you help on that?

Avatar

Community Advisor

@JyotiSharmaV No, you don't need Custom Code.

 

1. Create a Data Element of "Cookie" type. Provide the name of your cookie.

2. In your Rule's Condition, use "Value Comparison". Pick the data element in the first field. Then in the dropdown list, choose "Is truthy". Save your Condition.

 

"Is truthy" is a convenient way to check if a data element is set with a value. ("Is falsy" is the reverse, i.e. check if a data element does not have a value.)

Avatar

Community Advisor
@yuhuisg But to check if the cookie has been set or not (disregard of the value), we still have to configure condition. And, then what would be the condition type in the configuration to check if cookie is set or not?

Avatar

Community Advisor
@yuhuisg Thanks, I will check with your provided solution.