Class: Cookies

ATInternet.Tracker.Plugins. Cookies

Plugin to manage cookies.

new ATInternet.Tracker.Plugins.Cookies(parent)

This plugins allow the storage of elements like string, array or object in cookies. So it's important to know that it uses serialization. For that reason the values must be JSON compatible
Name Type Description
parent object Instance of the Tag used

Methods

cacheInvalidation()

Clear the cache
Delete a cookie or a property of it
Name Type Description
key string | Array If a string, name the element you wan to create/update, if an array the first element is the cookie's name and the second is a property of it

delPrivate(key)

Same as the 'del' method but for a private cookie linked to the current numsite
Name Type Description
key string | Array

get(key, byPassCache){*}

Retrieve a cookie or a property of it.
Name Type Description
key string | Array If a string, the cookie's name, if an array the first element is the cookies's name and the second is the property's name
byPassCache boolean optional If true, the value will be directly retrieved from the cookie
Returns:
Return null if the element does not exist

getCookie(name){string}

Returns the value of a cookie (decoded with Base64.decode)
Name Type Description
name string Name of the cookie wanted
Returns:
Return null if the cookie does not exist

getPrivate(key, byPassCache){*}

Same as the 'get' method but for a private cookie linked to the current numsite.
Name Type Description
key string | Array If a string, the cookie's name, if an array the first element is the cookies's name and the second is the property's name
byPassCache boolean optional If true, the value will be directly retrieved from the cookie
Returns:
Return null if the element does not exist

set(key, value, options){boolean|null}

Create, update or erase a cookie or the property of it.
Name Type Description
key string | Array If a string, name the element you wan to create/update, if an array the first element is the cookie's name and the second is a property of it
value * Value to save
options object Object which contains options. Useless if you create or update a property.
Returns:
Return true if the cookie has been set and really exists, return false if the cookie has been set but does not exists, returns null if the cookie hasn't been set at all (mostly a parameter with an error)
Example
set('cookie','value',{end:'3600',domain:'.site.com',path:'/',secure:true});
set('cookie',[1,2,3],{end:'3600'});
set('cookie',{'myvar1':1,'myvar2':2},{session:'3600'});
set(['cookie','myvar2'],3);

var date = new Date;
date.setMinutes(date.getMinutes()+30);
set('cookie','value',{end: date.getMinutes()+30});

setCookie(name, value, options){boolean|null}

Create, update or erase a cookie
Name Type Description
name string Name of the cookie that you wan to create/erase
value string Value that you need to cookies (encoded with Base64.encode)
options JSON Object which contains all cookies options (expiration date/ageInSecond, domain, path and secure flag)
Returns:
Return true if the cookie has been set and really exists, return false if the cookie has been set but does not exists, returns null if the cookie hasn't been set at all (mostly a parameter with an error)
Example
setCookie('name','value',{end:'3600',domain:'.site.com',path:'/',secure:true});   // try to set a secure cookie on '.site.com' with path '/' for 3600seconds
setCookie('name','value');                                                        // try to set a cookie on current domain/path for the session
var date = new Date;
date.setMinutes(date.getMinutes()+30);
setCookie('name','value',{end:date,domain:'.site.com'});   // try to set a cookie on '.site.com' for 30minutes
The third parameter options can contain 4 properties which are :
{
     end : expiration_date,      // if a number, it represents a time in second like the first example. If a date, see the previous example.
     session : expiration_date,  // OVERWRITE end ! indicates the expiration date must be delayed each time the element is read. It's a number representing a time in seconds
     domain : '.domain.com',     // allow to specify a domain
     path : '/',                 // allow to specify a path
     secure : 'boolean'          // allow to set a secure cookie (readable only in HTTPS pages)
 }
Same as the 'set' method but for a private cookie linked to the current numsite