Browser

With this method, you can check if the user is using a specific browser.

isOpera

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isOpera();
JS

isIE

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isIE();
JS

isMSIE

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isMSIE();
JS

isTrident

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isTrident();
JS

isEdge

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isEdge();
JS

isFirefox

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isFirefox();
JS

isSafari

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isSafari();
JS

isChrome

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isChrome();
JS

isPhantom

/**
 * @returns {boolean}
 */
wtSmart.utils.browser.isPhantom();
JS

With the "cookie" method, you can set and get a cookie.

/**
 * @param {string} name
 * @param {string} [value=""]
 * @param {number} [duration=0]
 * @param {string} [path="/"]
 * @param {string} [domain="current domain without subdomain"]
 * @param {boolean} [secure=false]
 *
 * @returns {string|boolean}
 */
wtSmart.utils.cookie(name, value, duration, path, domain, secure);
JS

Example

// set session cookie
wtSmart.utils.cookie('session_cookie', '1');
 
// set cookie with 6 month duration
wtSmart.utils.cookie('ever_cookie', '1', 6*30*24*60);
wtSmart.utils.cookie('ever_cookie', '1', 6*30*24*60, '/path', 'sub.domain.tld', true);
 
// get cookie value
var cookieValue = wtSmart.utils.cookie('cookie_name');
JS

Crypto

URL

With "URL" you have the option to "encode" and "decode" URI components.

encode

/**
 * @param {string} str
 *
 * @returns {string}
 */
wtSmart.utils.crypto.URL.encode(str);
JS

decode

/**
 * @param {string} str
 *
 * @returns {string}
 */
wtSmart.utils.crypto.URL.decode(str);
JS

Example

wtSmart.utils.crypto.URL.encode('äöü'); // %C3%A4%C3%B6%C3%BC

wtSmart.utils.crypto.URL.decode('%C3%A4%C3%B6%C3%BC'); // äöü
JS

SHA256

With "SHA256" you have the option to "encode" strings to a SHA256 hash.

encode

/**
 * @param {string} str
 *
 * @returns {string}
 */
wtSmart.utils.crypto.SHA256.encode(str);
JS

Example

wtSmart.utils.crypto.SHA256.encode('üöäÄÜÖ'); // c245f5277e70122d7e8427e6275cbd1a80f57cd7ec70a3e76f40d54a3687d02c
JS

MD5

With "MD5" you have the option to "encode" strings to a MD5 hash.

encode

/**
 * @param {string} str
 *
 * @returns {string}
 */
wtSmart.utils.crypto.MD5.encode(str);
JS

example

wtSmart.utils.crypto.MD5.encode('üöäÄÜÖ'); // 17cbf9298930599d4c7f06b9d46cb187
JS

Event

With "event" you have the option to "register" and "unregister" an event for an HTML Element.

register

/**
 * @param {HTMLElement|Window|Document} obj
 * @param {string} evt
 * @param {function(evt)} callback
 */
wtSmart.utils.event.register(obj, evt, callback);
JS

unregister

/**
 * @param {HTMLElement|Window|Document} str
 * @param {string} evt
 * @param {function(evt)} callback
 */
wtSmart.utils.event.unregister(obj, evt, callback);
JS

Example

var eventCallback = function(evt) {
    // do something after click
};

// register a click event
for (var i = 0, l = document.links.length; i < l; i++) {
    wtSmart.utils.event.register(document.links[i], "click", eventCallback);
}

// unregister a click event
wtSmart.utils.event.unregister(document.links[15], "click", eventCallback);
JS

Identifier

everId

/**
 * @param {string} [everId] - format (^\d{19}$)
 *
 * @returns {string}
 */
wtSmart.utils.identifier.everId(everId);
JS

cdbeid

/**
 * @returns {string}
 */
wtSmart.utils.identifier.cdbeid();
JS

forceNewSession

/**
 *
 */
wtSmart.utils.identifier.forceNewSession();
JS

example

// get existing Webtrekk Ever ID
var everId = wtSmart.utils.identifier.everId();
 
// set Webtrekk everId
wtSmart.utils.identifier.everId('0123456789012345678');

// get existing Webtrekk CDB ID
var cdbeid = wtSmart.utils.identifier.cdbeid();
JS

Image

With the "image" method, you can load an image asynchronously. Optionally, you can define a callback method and timeout that is called if the image is loaded or the timeout is reached.

/**
 * @param {string} imageURL
 * @param {function(HTMLImageElement, string, number)} [callback]
 * @param {number=2000} [timeout]
 */
wtSmart.utils.image(imageURL, callback, timeout);
JS

Example

/**
 * @param {HTMLImageElement} img
 * @param {string} status - (success, error, timeout)
 * @param {number} executionTime
 */
var imageCallback = function(img, status, executionTime)) {
    // do something
};
var imageURL = 'https://sub.domain.tld/track?page=start&t=' + (new Date().getTime());
 
// load an image asynchronous
wtSmart.utils.image(imageURL);
 
// load an image asynchronous with callback
wtSmart.utils.image(imageURL, imageCallback, 1000);
JS

Include

With the "include" method, you can load an JavaScript file asynchronously. You can define optional a callback method which is called if the JavaScript file was loaded (configured property "required"). If the property "required" isn't configured, the callback method to be called after creating of DOM elements.

/**
 * @param {string} scriptURL
 * @param {function()} [callback]
 */
wtSmart.utils.include(scriptURL, callback);
JS
/**
 * @param {{
 *      src: string,
 *      [required=false]: boolean
 * }[]} scriptURL
 * @param {function()} [callback]
 */
wtSmart.utils.include(scriptURL, callback);
JS

Example

// load one js file
wtSmart.utils.include('/path/to/my/js/file.js', function() {
    // do something and more
});
 
// load more js files
wtSmart.utils.include(
    [
        {src: '/path/to/my/js/file_1.js', required: true},
        {src: 'sub.domain.tld/path/to/my/js/file_2.js'},
        {src: '//sub.domain.tld/path/to/my/js/file_3.js', required: true}
    ],
    function() {
        // do something and more, if 'file_1' and 'file_3' was successfully loaded
    }
);
JS

OptOut

With these methods you can get the current 1st party optout status or set a 1st and 3rd party optout cookie.

getTrackingOptOut

/**
 * @returns {boolean}
 */
wtSmart.utils.optout.getTrackingOptOut();
JS

setTrackingOptOut

/**
 * @param {number} [duration=5*12*30*24*60]
 * @param {function} [callback]
 */
wtSmart.utils.optout.setTrackingOptOut(duration, callback);
JS

getAnonymousCookie

Depending on the settings in the advanced configuration, the value "true" of the cookie refers to different tracking scenarios:

  • When setting the user-identifiable cookie by default and providing the possibility to opt-out of user-identifiable tracking, "true" refers to anonymous tracking and no user-identifiable cookie is set.
  • When using anonymous tracking by default, "true" means that the user agreed to user-identifiable tracking and the respective cookie and information is set and tracked.
/**
 * @returns {boolean}
 */
wtSmart.utils.optout.getAnonymousCookie();
JS

setAnonymousCookie

/**
 * @param {number} [duration=5*12*30*24*60]
 */
wtSmart.utils.optout.setAnonymousCookie(duration);
JS

deleteAnonymousCookie

wtSmart.utils.optout.deleteAnonymousCookie();
JS

Example

// get the optout status
var optoutStatus = wtSmart.utils.optout.getTrackingOptOut();

// set the optout cookie with a default duration of 5 years
wtSmart.utils.optout.setTrackingOptOut();

// set the optout cookie with a duration of 6 months
wtSmart.utils.optout.setTrackingOptOut(6*30*24*60);

// set the optout cookie with a duration of 6 months an execute afterwards the callback method
wtSmart.utils.optout.setTrackingOptOut(6*30*24*60, function(img, status) {
    var message = 'The optout cookie was set successfully.';
    if (status !== 'success') {
        message = 'An error has occurred, please try again later.';
    }

    alert(message);
});

// get the anonymous cookie status
var anonymous = wtSmart.utils.optout.getAnonymousCookie();

// set the anonymous cookie with the default duration of 5 years
wtSmart.utils.optout.setAnonymousCookie();

// set the anonymous cookie with a duration of 6 months
wtSmart.utils.optout.setAnonymousCookie(6*30*24*60);

// delete the anonymous cookie
wtSmart.utils.optout.deleteAnonymousCookie();
JS

Parameter

With the "parameter" method, you can get a URL parameter value.

/**
 * @param {string} param
 * @param {string} [url=document.location.href]
 * @param {*} [def=false]
 *
 * @returns {*}
 */
wtSmart.utils.parameter(param, url, def);
JS

Example

// get an url parameter value
var parameterValue = wtSmart.utils.parameter('wt_mc', document.location.href, false);
JS

Referrer

With the "referrer" method, you can get the referrer URL. Optionally, you can set a referrer URL which is used for the Smart Pixel as "origin" referrer URL.

/**
 * @param {string} [referrer]
 *
 * @returns {string}
 */
wtSmart.utils.referrer(referrer);
JS

Example

// get referrer url
var referrer = wtSmart.utils.referrer();
 
// set referrer url
wtSmart.utils.referrer('https://sub.domain.tld/path/to/page');
JS

Url

With the "url" method, you can get the URL. Optionally, you can set a URL that is used for the Smart Pixel as "origin" URL.

/**
 * @param {string} [url]
 *
 * @returns {string}
 */
wtSmart.utils.url(url);
JS

Example

// get page url
var pageURL = wtSmart.utils.url();
 
// set page url
wtSmart.utils.url('https://sub.domain.tld/path/to/my/current/page');
JS