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.

API calls in templates


Returns true if any configured cookie is unset.


Returns true if the tracking cookie is unset.


Returns true if the tracking cookie was accepted.


Returns true if the tracking cookie was declined.

helper.cookies.createPost(type, accept)

Creates an asynchronous call for type to accept or decline depending on the boolean value of accept.


Creates the URL to use on form action attribute.

Simple management for analytics cookies

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>

Using the default Elephant management for cookies

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 in /WEB-INF/elephant/conf folder. Edit in BaaS -> Tools -> Files -> Configuration -> Properties editor and write this:


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, 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.

Printer version
English11/02/20 18:27Lluís Turró Cutiller
English11/04/20 19:04Lluís Turró Cutiller