Cloud Cookie Documentation

Get started

To use Cloud Cookies on any site, embed the CloudCookie JavaScript SDK:

Sign Up to Copy Custom Code
Sign Up Free

Example - Chaining methods

CloudCookie uses JavaScript promises to easily and neatly chain multiple commands together. All methods return a promise, and can therefore be easily chained together. New to promises? Don't worry, they are simply a more organized way of dealing with asyncronous requests, learn more here. The following shows an example of initializing, setting, and getting a cookie in a single chain.

Example:

Sign Up to Copy Custom Code
Sign Up Free

CloudCookie.ready

The ready method is invoked once the CloudCookie SDK has been successfully loaded.

Method: CloudCookie.ready()
Returns: A promise
Arguments: none

Example:


CloudCookie.ready().then(function(){
  //Do something
  console.log("Cloud Cookie is ready!");
})

CloudCookie.config

Configure Cloud Cookie for your use case.

Method: CloudCookie.config( configuration_object )
Returns: A promise
Configuration object parameters
public_access_token required when using NPM install, optional when using CloudCookie.js from CDN
Data type: string
A token that identifies your account. The public_access_token in the examples on this page are specific to your account.
use_cloud_cookie optional
Data type: string
Possible values: 'always' or 'fallback'
Default: 'always'

Cloud Cookies have 2 modes:

always: Cookies are always stored on the cloud. This enables cookies across multiple domains, and deeper analytics.
fallback: Cookies will be stored locally when allowed by a particular browser, and stored on the cloud when disallowed by the browser. This will result in faster average response times.

security optional
Data type: string
Possible values: 'standard' or 'strict'
Default: 'standard'

Cloud Cookies have 2 security options:

standard: Standard security can identify a unique visitor 99.9+% of the time on all browsers. It is ideal for most applications, but isn't recommended for sensitive data.
strict: Strict security mode will only store data when a unique visitor can be 100% identified. Hence it is safe for more sensitive data, but will not store data in some browser configurations.

Example:

Sign Up to Copy Custom Code
Sign Up Free

CloudCookie.set

Used to create a cloud cookie, or override an existing cookie for the given name.

Method: CloudCookie.set( cloud_cookie_object )
Returns: A promise containing the cloud cookie object (eg {name: 'foo', value: 'bar'})
Cloud cookie object parameters:
name required
Data type: string
Identifier for the cookie
value required
Data type: string, integer, float, boolean, array, or object
The content/data for the cookie
days_until_expiration optional
Data type: integer or float
Default: 7
The number of days until the cookie is deleted

Example:


CloudCookie.ready().then(function(){
  return CloudCookie.set({
    name: 'foo',
    value: 'bar',
    days_until_expiration: 7
  })
}).then(function(cookie_response){
  //example cookie_response: {name: 'foo', value: 'bar'}
  console.log("Cookie has been set!");
})

CloudCookie.get

Used to fetch a previously set cloud cookie.

Method: CloudCookie.get(name)
Returns: A promise containing the fetched cloud cookie object (eg {name: 'foo', value: 'bar'})
Arguments:
name required
Data type: string
Identifier for the cookie previously used in the CloudCookie.set method

Example:


CloudCookie.ready().then(function(){
  return CloudCookie.get('foo')
}).then(function(cookie_response){
  //example cookie_response: {name: 'foo', value: 'bar'}
  console.log("Cookie value is "+cookie_response.value);
})

CloudCookie.delete

Used to delete a previously set cloud cookie.

Method: CloudCookie.delete(name)
Returns: A promise containing the deleted cloud cookie name
Arguments:
name required
Data type: string
Identifier for the cookie previously used in the CloudCookie.set method

Example:


CloudCookie.ready().then(function(){
  return CloudCookie.delete('foo')
}).then(function(cookie_response){
  //example cookie_response: 'foo'
  console.log('Cookie '+cookie_response+' has been deleted!');
})

Error Handling

Errors can be handled using the native .catch functionality of JS promises.


CloudCookie.ready().then(function(){
  return CloudCookie.set({
    value: 'bar' // Oops, we forgot to set a name
  })
}).then(function(cookie_response){
  //do something
}).catch(function(err){
  //example err: {success: false, error: 'Cloud Cookie requires a name attribute to be set.'}
  console.log("Error!",err);
})

Need help?

No prob, we got your back.
Get Help