/**
* @class
* @name PropertiesManager
* @public
* @param tag {object} Instance of the Tag used
* @description
* <h2>Properties manager (data for hits)</h2>
*/
var PropertiesManager = function (tag) {
'use strict';
var _this = this;
/**
* Complete list of properties
* @memberof PropertiesManager#
* @type {object}
* @private
*/
var _properties = {};
/**
* Set a property (overrides if present)
* @name setProp
* @memberof PropertiesManager#
* @function
* @param key {string} Key name of the property
* @param value {string|number} value of the property
* @param persistent {boolean} Persistence of property
* @public
*/
_this.setProp = function (key, value, persistent) {
if (typeof key !== 'undefined') {
_properties[key] = {
value: value,
persistent: !!persistent
};
}
/* @if debug */
tag.debug('Tracker:Properties:setProp', 'DEBUG', '', {
key: key,
value: value,
persistent: persistent,
allProperties: _properties
});
/* @endif */
};
/**
* Set multiple properties (overrides if present)
* @name setProps
* @memberof PropertiesManager#
* @function
* @param props {object} Object to be added
* @param persistent {boolean} Persistence of object properties
* @public
*/
_this.setProps = function (props, persistent) {
if (ATInternet.Utils.isObject(props)) {
for (var key in props) {
if (props.hasOwnProperty(key)) {
_this.setProp(key, props[key], persistent)
}
}
}
};
/**
* Delete/remove a property
* @name delProp
* @memberof PropertiesManager#
* @function
* @param key {string} Key name of the property
* @param [keepBufferParam] {boolean} Keep the parameter from the buffer (optional)
* @public
*/
_this.delProp = function (key, keepBufferParam) {
if (typeof _properties[key] !== 'undefined') {
delete _properties[key];
}
!keepBufferParam && tag.delParam(key.toLowerCase());
/* @if debug */
tag.debug('Tracker:Properties:delProp', 'DEBUG', '', {
key: key,
keepBufferParam: keepBufferParam,
allProperties: _properties
});
/* @endif */
};
/**
* Delete/remove all properties
* @name delProps
* @memberof PropertiesManager#
* @function
* @param [keepBufferParams] {boolean} Keep the parameters from the buffer (optional)
* @public
*/
_this.delProps = function (keepBufferParams) {
for (var key in _properties) {
if (_properties.hasOwnProperty(key)) {
_this.delProp(key, keepBufferParams);
}
}
};
/**
* Get a property
* @name getProp
* @memberof PropertiesManager#
* @function
* @param key {string} Key name of the property
* @return {string|number|undefined|null}
* @public
*/
_this.getProp = function (key) {
_properties = _properties || {};
/* @if debug */
tag.debug('Tracker:Properties:getProp', 'DEBUG', '', {
key: key,
allProperties: _properties
});
/* @endif */
return _properties[key];
};
/**
* Get all properties
* @name getProp
* @memberof PropertiesManager#
* @function
* @return {object}
* @public
*/
_this.getProps = function () {
/* @if debug */
tag.debug('Tracker:Properties:getProps', 'DEBUG', '', {
allProperties: _properties
});
/* @endif */
return _properties;
};
// For unit tests on private elements !!!
/* @if test */
_this._properties = _properties;
/* @endif */
};