Class: Utils

Utils

Utility methods.

new Utils()

Members

isLocalStorageAvailable

Check if local storage is both supported and available

Methods

_num(len){string}

Generate GUID with numeric characters.
Name Type Description
len number Length of the generated GUID

_v4(){string}

Generate GUID with alphanumeric characters (v4 format).

addCallbackEvent(func)

Add callback event
Name Type Description
func function function to execute

addEvent(eventName, detailName, detailID, func)

Add custom event
Name Type Description
eventName string event name
detailName string detail name
detailID number detail uuid
func function function to execute

addEvtListener(obj, event, callback)

Add an event listener to an object.
Name Type Description
obj object DOM Element on which you want to add the event listener
event string Event you need to listen
callback function When event is triggered, it takes one parameter which is the event object

addOptOutEvent(eventID, func)

Add OPT-OUT event
Name Type Description
eventID number uuid
func function function to associate

arrayIndexOf(arr, elemToSearch){number}

Search an element in an array. Use Array.indexOf if possible.
Name Type Description
arr Array
elemToSearch *

cloneSimpleObject(inst, delUndefined){object}

Copy an object which doesnt' contain functions/objects.
Name Type Description
inst object Item that you want to clone
delUndefined boolean If true, undefined properties are not cloned
Returns:
clone of the instance

completeFstLevelObj(target, source, overload){object}

Complete the first level of an object with another.
Name Type Description
target object
source object
overload boolean If true, properties of the target will be overloaded by source ones if they exist

consentReceived(active)

Specify whether consent has been obtained preventing or allowing data to be stored in cookies or local storage
Name Type Description
active boolean false to prevent data to be stored, true to allow data to be stored

dispatchCallbackEvent(name)

Dispatch event for callbacks
Name Type Description
name string Callback's name

dispatchEvent(eventName, detailName)

Dispatch custom event
Name Type Description
eventName string event name
detailName string detail name

getObjectKeys(object){Array}

Get all keys from object.
Name Type Description
object object

hashcode(str){number}

Make a unique number with a given string.
Name Type Description
str

isOptedOut()

Get OPTOUT activation status

isPrerender(callback){boolean}

Check if we are in Chrome or IE prerendering case.
Name Type Description
callback function

isPreview(){boolean}

Check if we are in Safari previewing case.

jsonParse(str){Object}

Parse a string. Use JSON.parse if possible.
Name Type Description
str String JSON string that you want to parse to Javascript object

jsonSerialize(obj){Object|String}

Serialize any element. Use JSON.stringify if possible.
Name Type Description
obj Object Javascript object that you want to serialize to JSON
Returns:
JSON

loadScript(scriptObj, callback)

Load a script.
Name Type Description
scriptObj object Object containing script properties (url)
callback function Function to call on success or on error

removeEvent(eventName, func)

Remove custom event
Name Type Description
eventName string event name
func function function to execute

removeEvtListener(obj, event, callback)

Remove an event listener from an object.
Name Type Description
obj object DOM Element on which you want to add the event listener
event string Event you need to listen
callback function

removeOptOutEvent(func)

Remove OPT-OUT event
Name Type Description
func function function to remove

setLocation(contextObj)

Force document location.
Name Type Description
contextObj object Redirection's url and target (properties location & target)

userOptedIn()

Deactivate OPT-OUT mode

userOptedOut()

Activate OPT-OUT mode adding OPT-OUT value in hit and storage for idclient parameter

uuid(){function}

Generate UUID.