Validating Cookie Usage
Use client-side JavaScript to call the Adobe Granite Opt-Out Service to verify that you can use a cookie. Use the Granite.OptOutUtil JavaScript object to perform any of the following tasks:
- Obtain a list of cookie names that indicate that that user does not consent to using cookies for tracking purposes.
- Obtain a list of cookies that can be used.
- Determine whether the web browser contains a cookie that indicates the user does not consent to the use of cookies for tracking.
- Determine whether a specific cookie can be used.
The granite.utils client library folder provides the Granite.OptOutUtil object. Add the following code to your page head JSP to include a link to the JavaScript library:
<ui:includeClientLib categories="granite.utils" />
For example, the following JavaScript function determines whether the COOKIE_NAME cookie is permitted for use before writing to it:
The Granite.OptOutUtil JavaScript Object
Granite.OptOutUtil enables you to determine whether cookie usage is allowed.
getCookieNames() function
The names of the cookies that, when present, indicate that the user has not given consent to the use of cookies.
Parameters
None.
Returns
An array of cookie names.
getWhitelistCookieNames() function
The names of cookies that can be used regardless of the user’s consent.
Parameters
None.
Returns
An array of cookie names.
isOptedOut() function
Determines whether the user’s browser contains any cookies that indicate that consent has not been given to use cookies.
Parameters
None.
Returns
A boolean value of true if a cookie is found that indicates no consent, and a value of false if no cookies indicate non-consent.
maySetCookie(cookieName) function
Determines whether a specific cookie can be used on the user’s browser. This function is equivalent to using the isOptedOut function with determining whether the given cookie is included in the list that the getWhitelistCookieNames function returns.
Parameters
- cookieName: String. The name of the cookie.
Returns
A boolean value of true if cookieName can be used, or a value of false if cookieName cannot be used.
Was this content helpful?
Announcements
Get hands-on with agentic AI.
Explore how AI agents work together through real examples and hands-on practice. Join your local User Group to design an agent workflow with your peers and leave with a practical framework you can apply to your own work.
Find an eventAdobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & EMEA
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & APAC
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Brand Visibility Roadmap Webinar - Americas & EMEA
Preview the Brand Visibility roadmap across Brand Concierge and AEM Sites. Ask live.