Cookies consent opt out utils not working | Community
Skip to main content
Level 4
October 29, 2021

Cookies consent opt out utils not working

  • October 29, 2021
  • 2 replies
  • 3504 views

@arunpatidar you may be able to help as i see you recently posted a link to the opt out service on this forum question.

I want to use the opt out service in an AEM Sightly template to do cookie consent management.

I am following the documentation linked to above, but i seem to be missing something.

In my local AEM instance, my service is configured OK as i can see at http://localhost:4502/system/console/status-Configurations

 

PID = com.adobe.granite.optout.impl.OptOutServiceImpl BundleLocation = Unbound optout.cookies = [cq-opt-out, omniture_optout] optout.whitelist.cookies = [cq-show-clientcontext, cq-scrollpos, cq-sk-collapsed, login-token, ys-cq-siteadmin-tree, ys-cq-damadmin-tree, ys-cq-collabadmin-tree, ys-cq-miscadmin-tree, ys-cq-tagadmin, ys-cq-cf-clipboard, ys-cq-cf-tabpanel, SessionPersistence, wcmmode, CommercePersistence, cq-authoring-mode, SH_CAMPAIGN] service.pid = com.adobe.granite.optout.impl.OptOutServiceImpl

 

and I am able to include and call browser script methods from Granite.OptOutUtil in a Sightly template in the following way,

 

<sly data-sly-test="${wcmmode.disabled}"> <sly data-sly-call="${clientlib.all @ categories='granite.utils'}"/> </sly> <script> (function logCookies() { console.info('whitelisted cookie names? ') console.table(Granite.OptOutUtil.getWhitelistCookieNames()) // outputs an empty array console.info('optout cookie names? ') console.table(Granite.OptOutUtil.getCookieNames()) // outputs an empty array })() </script>

 

but the method calls return empty arrays 😪

Debugging the client-side code in a browser, the Granite.OptOutUtil object is initialised with a config option, that is undefined when the following line executes.  What am I missing?

 

Granite.OptOutUtil.init(window.GraniteOptOutConfig); // window.GraniteOptOutConfig is undefined

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

arunpatidar
Community Advisor
Community Advisor
October 30, 2021

Hi,

The service PID should be 

com.adobe.granite.optout
Arun Patidar
Level 4
November 1, 2021

Thanks for the reply @arunpatidar and for pointing out what the PID should be.  Are you basing your reply on a working example - can you share that (I can't find an example of the opt out service being used by the we retail project)?  Or is your suggestion based on the documentation, where I see it says, 

"...The following table desribes [sic] the properties that you need for either method. For an OSGi configuration, the service PID is com.adobe.granite.optout."
I'm a bit confused about this point about the PID, when I run up AEM 6.4 with no custom code added to it, there is already an osgi configuration entry in place for 

service.pid="com.adobe.granite.optout.impl.OptOutServiceImpl"

If i provide a configuration entry for service.pid="com.adobe.granite.optout" then my local AEM instance ends up with 2 similar entries (presumably my entry plus the out-of-the-box one):

PID = com.adobe.granite.optout
  BundleLocation = Unbound
  optout.cookies = [cq-opt-out, omniture_optout]
  optout.whitelist.cookies = [cq-show-clientcontext, cq-scrollpos, cq-sk-collapsed, login-token, ys-cq-siteadmin-tree, ys-cq-damadmin-tree, ys-cq-collabadmin-tree, ys-cq-miscadmin-tree, ys-cq-tagadmin, ys-cq-cf-clipboard, ys-cq-cf-tabpanel, SessionPersistence, wcmmode, CommercePersistence, cq-authoring-mode, SH_CAMPAIGN]
  service.pid = com.adobe.granite.optout

PID = com.adobe.granite.optout.impl.OptOutServiceImpl
  BundleLocation = Unbound
  optout.cookies = [cq-opt-out, omniture_optout]
  optout.whitelist.cookies = [cq-show-clientcontext, cq-scrollpos, cq-sk-collapsed, login-token, ys-cq-siteadmin-tree, ys-cq-damadmin-tree, ys-cq-collabadmin-tree, ys-cq-miscadmin-tree, ys-cq-tagadmin, ys-cq-cf-clipboard, ys-cq-cf-tabpanel, SessionPersistence, wcmmode, CommercePersistence, cq-authoring-mode]
  service.pid = com.adobe.granite.optout.impl.OptOutServiceImpl

Either way, i still get empty arrays in response to client side calls like,

Granite.OptOutUtil.getCookieNames()

and when http://localhost:4502/etc.clientlibs/clientlibs/granite/utils.js is initialised, window.GraniteOptOutConfig is still 'undefined' 😥. 
How does the config get "read" and set on the client library utils.js? 🙄 

arunpatidar
Community Advisor
Community Advisor
November 1, 2021

Hi,

I did not implemented this, I was just refering the documents. BTW ths osgi configuration was correct with 

service.pid = com.adobe.granite.optout.impl.OptOutServiceImpl

Can you check this configuration at http://localhost:4504/libs/granite/security/optout/configuration.json

Please check https://rmengji.wordpress.com/2015/02/26/aem-do-not-track-cookie-setting-aem-granite-opt-out-service/

You need to set Header as well and you can directly used methods like 

Granite.OptOutUtil.getCookieNames()

 I don't think so that you need to set  

Granite.OptOutUtil.init(window.GraniteOptOutConfig);

 

Arun Patidar
Level 2
March 16, 2023

Hey @dorianhallward,

 

I am also having the same issue where I've created a custom OSGi configuration inside the repository. Every time I use the JS API to fetch the cookies that I have opted out from, it still outputs an empty array. I have tried passing the configuration cookies in the Granite.OptOutUtil class but it did not work (it only worked in my local environment). 

 

Did you ever solve this issue?

June 8, 2023

Same issue here, added custom OSGi config with optout.cookies, optout.headers and optout.whitelist.cookies. Yet still the same problem, when using the Granite.OptOutUtil to fetch the cookies, the arrays are always empty.

Have you found any fix for that @dorianhallward @frizzybrain