A cookie consent message for new visitors
- Optional requirements:
- Bootstrap 3+
- Download:
- MODX Extras
- GitHub
Overview
CookieConsent displays a message informing each new visitor that your site uses cookies, with a link to your site's cookie policy. Simply install CookieConsent and it will start working automatically. CookieConsent can help you comply with European Union cookie law.
Options
The output of CookieConsent can be customised using the options shown below.
Property | Description | Default |
---|---|---|
cookieDays |
The number of days the cookie should last for. | 365 |
cookieName |
The name of the cookie that determines whether consent has been given. | CookieConsent |
idCookiePolicy |
ID of resource containing site cookie policy. | |
tpl |
The name of the chunk containing the cookie disclaimer. | cookieConsent |
class |
The name of the class selector for the CookieConsent HTML. | cookieconsent |
includeCSS |
Whether to include the CSS file. | |
includeJS |
Whether to include the JavaScript file. | |
pathCSS |
The location of the CSS file. Use the {assets_path} placeholder as a shortcut. Must include ".css". | {assets_path}/.../cookieconsent-min.css |
pathJS |
The location of the JavaScript file. Use the {assets_path} placeholder as a shortcut. Must include ".js". | {assets_path}/.../mabCookieSet-min.js |
Custom properties
Setting your own custom properties for a MODX plugin takes a bit more effort than that required for a snippet.
To set your own properties, do the following:-
- Open the CookieConsent plugin and go to the Properties tab
- Add a new Property Set
- Set your custom values
- Now go to the System Events tab
- Update the Property Set field for the
OnWebPagePrerender
with the name of your custom Propert Set
You will need to update the OnWebPagePrerender
event with the name of your custom Property Set any time you upgrade your CookieConsent plugin. This is the way MODX handles the upgrade of a package plugin. However, the values you set in your custom Property Set will be saved between upgrades.
Templates
CookieConsent uses a simple template which contains the cookie disclaimer message and the call to the jQuery plugin that will save their response to a cookie.
The chunk displayed to the user. Can be set using the tpl
property. Our one uses a Bootstrap theme.
<a title="View out cookie policy" href="[[+class]]">cookie policy here</a>
<div data-name="[[+cookieName]]" data-value="[[+cookieValue]]" data-days="[[+cookieDays]]" class="alert alert-warning alert-dismissible fade in [[+class]]" role="alert">
<p class="text-center">
We have placed cookies on your device to help make this website better. You can view our <a title="View out cookie policy" href="[[+class]]">cookie policy here</a>.
<button type="button" class="btn btn-info" data-dismiss="alert">Continue using site</button>
</p>
</div>
<script>
$(function()
{
$(".[[+class]] button").click(function ()
{
$(".[[+class]]").mabCookieSet({onDone: function(){$(".[[+class]]").hide();}});
});
});
</script>
Custom CookieConsent on MODX?
Simply create your own chunk based on the one above, and name it CookieConsent.
jQuery plugin
CookieConsent includes a jQuery plugin named mabCookieSet. This plugin sets a cookie so that it remembers whether the current visitor has accepted your cookie policy.
Usage
The jQuery plugin is automatically included unless includeJS
is set to false. You might do this if you have your own script you'd like to use to add a cookie. If so, you could instead set pathJS
which will automatically include your own script.
The plugin can be triggered via JavaScript. It is triggered for you in the defualt chunk, as detailed above.
$( ".cookieconsent" ).mabCookieSet();
Options
Options are passed via data attributes or set directly in the call as options. For data attributes, append the option name to data-
, as in data-name="CookieConsent"
.
Name | type | Description | Default |
---|---|---|---|
name |
string | The name of the cookie | CookieConsent |
value |
string | The value of the cookie | |
days |
number | The number of days the cookie will last for | 365 |
References
Licence
CookieConsent by mad about brighton is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Permissions beyond the scope of this licence may be available by contacting me.