


@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
Views
Replies
Total Likes
Hi,
The service PID should be
com.adobe.granite.optout
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? 🙄
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);
Thanks for the help @arunpatidar.
Some replies from me:
@arunpatidar wrote:Hi,
I did not implemented this, I was just refering the documents.
Ok thanks for confirming.
Can you check this configuration at http://localhost:4504/libs/granite/security/optout/configuration.json
My localhost:4502 author instance returns valid json (as you'd expect, given this comes as standard out of the box).
{"cookienames": ["omniture_optout","cq-opt-out"],"headers": {},"whitelistcookienames": ["ys-cq-siteadmin-tree","cq-sk-collapsed","ys-cq-cf-tabpanel","cq-show-clientcontext", // ...etc
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()
Ok I will add the X-Do-Not-Track header (if that's what you meant?) but i'm not sure why this would make this feature work? As you can see from my comments above, I am already calling methods directly like getCookieNames(), they just return empty arrays - despite the configuration. This is the root of my problem.
I don't think so that you need to set
Granite.OptOutUtil.init(window.GraniteOptOutConfig);
I don't "set" or call this function, it is run by the browser. I only mention it here to explain why client-side methods like getCookieNames return empty arrays (because the window.GraniteOptOutConfig object that provides this data is undefined when the init() function runs (see http://localhost:4502/crx/de/index.jsp#/libs/clientlibs/granite/utils/source/init.js)).
Hi,
I checked the code but did not find where the values are set
(function(d) { return function() { var d = {} , w = [] , y = []; d.init = function(d) { d ? (w = d.cookieNames || [], y = d.whitelistCookieNames || []) : (w = [], y = []) } ; d.getCookieNames = function() { return w } ; d.getWhitelistCookieNames = function() { return y } ; d.isOptedOut = function() { for (var q = document.cookie.split(";"), r = 0; r < q.length; r++) { var y = q[r].split("\x3d")[0]; y = String.prototype.trim ? y.trim() : y.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); if (0 <= d.getCookieNames().indexOf(y)) return !0 } return !1 } ; d.maySetCookie = function(q) { return !(d.isOptedOut() && -1 === d.getWhitelistCookieNames().indexOf(q)) } ; return d }() }); Granite.OptOutUtil.init(window.GraniteOptOutConfig);
Hi @arunpatidar
Where is JS you've pasted in above taken from?
This granite.utils client library is made up of the scripts specified in /libs/clientlibs/granite/utils/js.txt, i.e.
#base=source Sling.js Util.js HTTP.js I18n.js TouchIndicator.js OptOutUtil.js init.js
If you look at /libs/clientlibs/granite/utils/source/OptOutUtil.js you'll see code (and its inline documentation) like the following (line 63 onwards)
/** * Initializes this tool with an opt-out configuration. * * The following options are supported: * <ul> * <li>cookieNames: an array of cookie names representing opt-out cookies. Defaults to empty.</li> * <li>whitelistCookieNames: an array of cookies representing white-listed cookies. Defaults to empty.</li> * </ul> * * @param {Object} config The opt-out configuration. * * @example * { * "cookieNames": ["omniture_optout","cq-opt-out"], * "whitelistCookieNames": ["someAppCookie", "anotherImportantAppCookie"] * } */ self.init = function(config) { if (config) { optOutCookieNames = config.cookieNames || []; whitelistedCookieNames = config.whitelistCookieNames || []; } else { optOutCookieNames = []; whitelistedCookieNames = []; } };
@VaniBhemarasetty are you familiar with the AEM Sites cookie opt out feature?
I can't get the client side library to work, following the Adobe documentation.
I'm sure i'm missing something simple - see the comments above on this forum question.
Also, I tried setting the header as per the other web page you referenced and applied changes to the "we retail" example project. Unfortunately with the same outcome 😣.
I must be missing some configuration or additional settings...
My local osgi output service now configured as follows,
http://localhost:4502/libs/granite/security/optout/configuration.json { "cookienames": [ "omniture_optout", "cq-opt-out" ], "headers": { "X-Do-Not-Track": "1", "DNT": "1" }, "whitelistcookienames": [ "ys-cq-siteadmin-tree", "cq-sk-collapsed", "ys-cq-cf-tabpanel", "cq-show-clientcontext", "CommercePersistence", "wcmmode", "ys-cq-damadmin-tree", "login-token", "ys-cq-collabadmin-tree", "ys-cq-miscadmin-tree", "ys-cq-tagadmin", "cq-authoring-mode", "cq-scrollpos", "ys-cq-cf-clipboard", "SessionPersistence" ] }