Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

jsvasu
Level 3
Level 3

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
yuhuisg
Correct answer by
Community Advisor
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
yuhuisg
Correct answer by
Community Advisor
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

jsvasu
Level 3
Level 3
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.
yuhuisg
Community Advisor
Community Advisor
@jsvasu 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).
jsvasu
Level 3
Level 3
@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?
yuhuisg
Community Advisor
Community Advisor

@jsvasu 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.)

jsvasu
Level 3
Level 3
@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?