Elephant provides a cookie tracking mechanism to allow
/ decline
types of cookies. The Cookie Management's goal is the ability to work in Elephant templates.
helper.cookies.anyUnset() |
Returns true if any configured cookie is unset. |
helper.cookies.unset(type) |
Returns true if the tracking cookie is unset. |
helper.cookies.allow(type) |
Returns true if the tracking cookie was accepted. |
helper.cookies.decline(type) |
Returns true if the tracking cookie was declined. |
helper.cookies.createPost(type, accept) |
Creates an asynchronous call for |
helper.cookies.createFormAction() |
Creates the URL to use on form action attribute. |
This example will show how to use the cookie tracking mechanism to allow or decline Google Analytics.
First, check if "track" type of cookies is unset and provide a user selection:
<#if helper.cookies.unset("track")> Would you allow Google Analytics? <a onclick='${helper.cookies.createPost("track", true)}'>Allow analytics</a> <a onclick='${helper.cookies.createPost("track", false)}'>Forbid analytics</a> < /#if>Now, if "track" type of cookies are allowed include Analytics:
<#if helper.cookies.allow("track")>
#your Analytics code here
< /#if>
Elephant also provides a cookie management easy to activate. By default remains inactive due no configured cookies. To use the Elephant management create the file cookie-context.properties
in /WEB-INF/elephant/conf
folder. Edit in BaaS -> Tools -> Files -> Configuration -> Properties editor and write this:
track=lTrackCookie
This line will activate de track cookie, explained in the labels key lTrackCookie. Now, just put the tracking code like this:
<#if helper.cookies.allow("track")>
// the tracking code, ex. Google Analytics
< /#if>
To control more kind of cookies, simply add more lines to the cookie-context.properties
, being the key the cookies' type. For single language sites, is possible to explain the type directly in this file. Otherwise, use a label key and add the corresponding values to the labels-site[_lang]
files (see BaaS -> Tools -> Files -> Configuration -> Resources)
Authenticated users will be able to modify their cookie preferences in the Session menu.