Define Initialization Tasks for Cookie Consent in SuiteCommerce

Learn to define initialization tasks for managing cookie consent in SuiteCommerce extensions and improve user privacy management.

·3 min read·View Oracle Docs

TL;DR Opening

This article explains how to define initialization tasks for cookie consent management in SuiteCommerce, significantly enhancing user privacy control by allowing website visitors to manage their cookie preferences directly through an intuitive interface.

How Do You Create a View for the Cookie Banner?

The cookie banner view is essential for managing user consent regarding SuiteCommerce analytics cookies. It allows visitors to accept or reject different cookie types, such as marketing or performance cookies. You can initialize this functionality using the SCView class, which facilitates the creation of a user-friendly consent form composed of various checkbox options.

Code Example

The following example demonstrates how to set up the cookie banner view:

javascript
1"text-purple-400">define (
2 'NetSuite.MyCookiesExtension.Banner.View',
3 [
4 'SCView',
5 'jQuery',
6 'netsuite_mycookiesextension_banner.tpl'
7 ],
8 "text-purple-400">function(SCViewComponent, jQuery, netsuite_mycookiesextension_banner_tpl) {
9 'use strict';
10
11 "text-purple-400">var SCView = SCViewComponent.SCView;
12
13 "text-purple-400">function MyCookiesExtensionBannerView(params) {
14 SCView.call("text-purple-400">this);
15
16 "text-purple-400">this.template = netsuite_mycookiesextension_banner_tpl;
17
18 "text-purple-400">this.userProfile = params.userProfile;
19 "text-purple-400">var userProfile = "text-purple-400">this.userProfile;
20
21 // Initialisation tasks. See below.
22 // <...>
23 }
24
25 MyCookiesExtensionBannerView.prototype = Object.create(SCView.prototype);
26 MyCookiesExtensionBannerView.prototype.constructor = MyCookiesExtensionBannerView;
27
28 // Additional functions here
29 "text-purple-400">return MyCookiesExtensionBannerView;
30 }
31);

How to Define Initialization Tasks

Initialization tasks should be included in the view's constructor. Begin by checking for the presence of the browser consent cookie when the extension loads. If it doesn’t exist, the cookie consent form should be displayed. Conversely, if it does exist, compare its timestamp with that of the server cookie to determine whether updates are necessary. Here's a structured outline of the initialization logic:

javascript
1"text-purple-400">var browserConsentCookie = "text-purple-400">this.getBrowserConsentCookie() || null;
2
3"text-purple-400">if (browserConsentCookie) {
4 // Handle cookie logic
5} "text-purple-400">else {
6 jQuery("text-purple-400">function() {
7 jQuery('#myCookiesExtensionBanner').show();
8 });
9}

How to Get or Set the Browser Cookie

Managing the browser cookie is critical for ensuring that user consent is tracked appropriately. Use the following functions to retrieve or set the cookie:

Getting the Cookie

javascript
1MyCookiesExtensionBannerView.prototype.getBrowserConsentCookie = "text-purple-400">function() {
2 "text-purple-400">var cookies = document.cookie.split(';');
3 "text-purple-400">var browserConsentCookie = cookies.find("text-purple-400">function(element) {
4 "text-purple-400">return element.trim().startsWith('trackingConsentCookie');
5 });
6
7 // Additional logic
8}

Setting the Cookie

javascript
MyCookiesExtensionBannerView.prototype.setBrowserConsentCookie = "text-purple-400">function(cookieOptions) {
// Logic to set the cookie
}

How Do You Format Consent Cookie Preferences?

When the user saves their preferences, the savePrefs function is invoked to gather the form values and format them correctly. This ensures compliance with consent regulations while enhancing data privacy. Here is a brief overview of how to create the preferences object:

Code Example

javascript
MyCookiesExtensionBannerView.prototype.savePrefs = "text-purple-400">function() {
// Logic to save preferences
}

How to Persist Cookie Preferences in NetSuite

To save a user’s preferences in the NetSuite backend, it’s vital to implement the setCookiePreferences function, which interacts directly with the UserProfile component. This method allows the preferences to be retained across sessions, enhancing the user experience significantly.

Function Example

javascript
MyCookiesExtensionBannerView.prototype.setCookiePreferences = "text-purple-400">function(cookieOptions, browserCookieValue) {
// Logic to persist preferences in NetSuite
}

Key Takeaways

  • Initialize cookie permissions for user customization within SuiteCommerce.
  • Validate and update cookie preferences between client and server for accuracy.
  • Use structured functions to maintain a clean and efficient codebase when handling cookies.
  • Leverage SuiteCommerce frameworks to enhance user privacy features effectively.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

How do I initialize the cookie consent form in SuiteCommerce?
Initialization tasks for the cookie consent form should be included in the view's constructor. Start by checking for the presence of the browser consent cookie when the extension loads. If it doesn't exist, display the cookie consent form; if it does, compare its timestamp with the server cookie to decide if updates are necessary.
How can I create a custom view for the cookie banner in SuiteCommerce?
Use the `SCView` class to create the cookie banner view, allowing visitors to accept or reject different cookie types. This involves setting up a user-friendly consent form with checkbox options and initializing it through the `NetSuite.MyCookiesExtension.Banner.View` function.
What methods are available for managing browser cookies in the cookie consent extension?
You can manage browser cookies using two primary methods: `getBrowserConsentCookie` to retrieve the current consent cookie from the browser, and `setBrowserConsentCookie` to update or create a new consent cookie.
How do I save and persist cookie preferences in the NetSuite backend?
To save cookie preferences in the NetSuite backend, use the `setCookiePreferences` function. This function interacts with the UserProfile component to ensure preferences are stored across sessions, enhancing user experience.
Source: Define Initialization Tasks Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →