cookieconsent
cookieconsent copied to clipboard
Additional helper functions
Hi,
it would be nice to have published additional helper functions
- cookieListed(cookieName) - check if cookie by given name is listed in the rules given in cookies list
- cookieAllowed(cookieName) - check if cookie by given name is allowed by current user preferences
Thanks for consideration...
Hi @n3t,
can you describe some specific use-cases where you need these methods?
Hi,
I am in development of plugin for Joomla CMS using your library. As in this CMS (same as in others) I do not have 100% control of scripts added by other plugins / templates etc. I overrided document.cookie set method, where I can filter cookies set by other. non controlled, scripts. For this I need if given cookie is listed (or unknown, meaning there is misconfiguration) and allowed by current user preferences. Currently I have to duplicate the list outside CookieCOnsent as separate array to search it, so just duplicating code...
Also, I mentioned that getUserPreferences() function returns all categories as rejected before user chooses either accept all, or accept neccessary, so even functional cookies (those in category with enabled by default) are rejected. Is this by design, or bug?
Thanks
I get it now.
I don't think it's worth adding these methods into the plugin since — in my opinion — they would be very rarely used. I'd like to avoid niche/super-optional features like this for a lighter plugin. If v3 releases with a "plugin" system, I will consider implementing features like this.
I don't think you need to duplicate the list. You could use an object with the category names as properties, where each property is a valid cookie_table
array.
Example:
const cookie_tables = {
analytics: [
{
col1: '_ga',
col2: '...',
col3: '...'
},
{
col1: '_gid',
col2: '...',
col3: '...',
}
],
ads: [
{
col1: '_cl',
col2: '...',
col3: '...'
}
]
}
And then you would simply need to put each prop. in the right cookie category section:
var cc = initCookieConsent();
cc.run({
// ...,
settings_modal : {
// ...,
blocks : [
// ...,
{
// ...,
cookie_table : cookie_tables.analytics
}
]
}
});
Yes, getUserPreferences()
will return proper preferences once the user has made a choice. It was meant to be used inside the onAccept
, onChange
and onFirstAction
callbacks (or any script managed by the plugin).
The plugin follows the gdpr rules and as such no categories can be automatically accepted without the explicit user consent. As for the enabled
option; it's been there since the very first version — when there were was only a "save preferences" button — and has now become a way less useful option (perhaps useless).
Yes, I ended up with similar code. Looking forward for version 3 then :)
According to enabled
option, I do not think it is useless, as functional cookies should be mentioned (according to my informations) in settings dialog also, so it's nice that its checkobox is checked by default...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.