Class: Utils

Utils

Utility methods.

new Utils()

Members

isBeaconMethodAvailable

Check if beacon method is supported and available

isLocalStorageAvailable

Check if local storage is both supported and available

privacy

Privacy object

Methods

_crypto(){string}

Generate GUID with alphanumeric characters (v4 format) with Crypto or Math random.

_mathRand(){number}

Generate a random number of n digits with Crypto or Math random.

_num(len){string}

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

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:
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

isEmptyObject(tagObject){boolean}

Check if object is empty.
Name Type Description
tagObject Object

isObject(contextualObject){boolean}

Check if parameter is an object.
Name Type Description
contextualObject *

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.

isTabOpeningAction(event){boolean}

Check if a key allowing a tab opening is pressed during a click
Name Type Description
event Object event object

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

objectToLowercase(tagObject){Object}

Change the keys of object to lowercase
Name Type Description
tagObject Object Object from tag

removeCallbackEvent(func)

Remove callback event
Name Type Description
func function function to remove

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)

splitProtocolAndKey(key, toLower){Object}

Process event key.
Name Type Description
key String Event key to split
toLower boolean Put the key to the property in lower case

trim(str){String}

Trim a string. Use String.prototype.trim if possible.
Name Type Description
str String string to trim

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.