Cookie Component

Note: This feature is currently released under our Controlled Availability program. To request access to this feature, please log in to My Oracle Support and create a service request. Availability for this feature is specific to product trim. Contact your account representative for more information.

Cookie operates with 1st-party cookies that don’t have HttpOnly flag.

Establish the Cookie component

This step is performed once for the whole account.

Create a single Web personalization for all your shared scripts. It should go first in alphabetical order. This makes its Content nodes run first on the web page. All the Content nodes in it also run from left to right, as the arrows on the Canvas show.

Copy and paste the following JavaScript code into a Content and set its Location to the whole site.

data.global.cookie = function(name, value, days) {
  let cookieManager = ORA.personalization.cookieManager,
      expires = '';

  if (typeof days === 'number') {
    expires = '; expires=';

    if (days !== 0) {
      date = new Date();
      date.setDate(date.getDate() + days);
      expires += date.toUTCString();
    }
  }

  return typeof value === 'undefined' ? cookieManager.getCookie(name) : cookieManager.setCookie(name, value, expires);
}

Process Web personalization cookies

As soon as the Cookie component is set up, you can call it from any Content.

Use the following syntax to read a cookie:

data.global.cookie(name);

And the following syntax to write one:

data.global.cookie(name, value, *daysToExpire);

Where daysToExpire defaults to whatever is defined under the Analytics tag module.

Argument Name

Description Type

name

Cookie name.

Adding a unique prefix to your cookie name may help with avoiding conflicts.

String

value

Cookie value.

String

daysToExpire

Number of days a cookie will be available for.

Pass 0 to limit the cookie lifetime to a session.

Don’t pass anything to use the default value defined in the Analytics tag module.

Number

Example 1

let isLoggedIn = data.global.cookie("loggedIn");

Example 2

data.global.cookie("lastCategory", "bicycles");

Learn more

Web Personalization Canvas - Learn more on setting up a web personalization

Web Personalization Content Editing - Understand content editing capabilities