new BufferManager(tag)
Buffer manager (data for hits)
Option notion
An option is the way to 'typify' a parameter. Indeed it can be very useful to specify in which hits a parameter must appear or how (encoding for example).
Example
Here is the list of the options : - encode: (boolean) if true, the parameter will be encoded - permanent: (boolean) if true, the parameter won't be delete after sending. So it will be sent in all other hits (if other options allow it). - separator: (char) when the parameter is an array its value in the hit is the concatenation array values separated by a ','. This option allow to use an other separator. - hitType: (Array{string}) list the hit types in which the parameter can be sent. It's possible to use a non-existent type of hit but here is the existing ones : * 'page': for impression hit * 'all': for all type of hitFilter notion
'Filters' allow to select a set of parameters by their options. One filter is formed by an option name and its desired value(s). The filter value MUST BE of the same type as the option value type.
The 'filter' is a tuple, an Array of two elements. The first one is the option name we want to analyse, the second is the value(s) we want to filter.
Actually there's two cases : the option value type is a list or not. In the second case it's easy : the couple key/value in filter is the key/value to be retrieved. In the first case the filter will match with options which contain at least one of the value of the filter.
When a list of filters is used to retrieve some parameters, the result will be the intersection of the filters results.
Example
Here is a list of parameters with their options : param1 => {permanent: true, encode: true} param2 => {permanent: true, hitType: ['page', 'click']} param3 => {hitType: ['click']} param4 => {permanent: true, hitType: ['page', 'rm']} param5 => {hitType: ['page', 'rm']} Here is the filters results : [[permanent, true]] => param1, param2, param4 [[hitType, ['page']]] => param2, param4, param5 [[hitType, ['page', 'click']]] => param1, param2, param4, param5 (hitType 'page' OR 'click') [[permanent, true], [hitType, ['page']]] => param1, param2, param4 (hitType 'page' AND permanent true) If we want parameters with a hitType 'page' AND 'click' we must make TWO filter: [[hitType, ['page']], [hitType, ['click']]] => param2
Name | Type | Description |
---|---|---|
tag |
object | Instance of the Tag used |
Methods
-
addInFilters(filters, name, val, found)
-
Complete the filters. In all cases, if the given option is not already handled by the filters, a new filter will be added.
Otherwise the behavior is different according to the type of the given value :- if it's an Array, all the filter which handle the option will be completed with the value. It is assumed that these filters already contains an Array value,
- in other cases nothing happens.
Name Type Description filters
Array List of buffer filters name
string Option name val
Array | * found
boolean DO NOT SPECIFY IT Example
addInFilters(myfilters, 'permanent', true); //[] => [["permanent", true]] //[["hitType", ["click"]]] => [["hitType", ["click"]], ["permanent", true]] //[["hitType", ["page"]], ["permanent", true]] => [["hitType", ["page"]], ["permanent", true]]] addInFilters(myfilters, 'hitType', ['all']); //[["hitType", ["page"]] => [["hitType", ["page", "all"]]] //[["permanent", true]] => [["permanent", true], ["hitType", "all"]] //[["hitType", ["click"]], ["permanent", true]] => [["hitType", ["click", "all"]], ["permanent", true]] //[["hitType", ["page"]], ["permanent", true]] => [["hitType", ["page", "all"]], ["permanent", true]] //[["hitType", ["page"]], ["hitType", ["rm"]]] => [["hitType", ["page", "all"]], ["hitType", ["rm", "all"]]] //[["hitType", ["page"]], ["hitType", ["rm", "all"]]] => [["hitType", ["page", "all"]], ["hitType", ["rm", "all"]]] //[["hitType", ["page", "all"]], ["hitType", ["rm", "all"]]] => [["hitType", ["page", "all"]], ["hitType", ["rm", "all"]]]
-
clear()
-
Empty the buffer.
-
del(name)
-
Delete a hit variable in the buffer.
Name Type Description name
string Name of the hit variable -
get(filterList, withOptions){string|object}
-
Get variables in the buffer using the filter given, with possibility of returning options or not.
Name Type Description filterList
Array List of key/value(s) in an array. (ex : [[key1,value1],[key2,[value2A,value2B]]]) Filter on variable's options withOptions
boolean If true only returns value else returns object with value and options Example
// this filter will get variables with hitType 'page' OR 'all', AND with permanent true var filter = [ ['hitType',['page','all']], ['permanent',true] ] var dataObj = buffer.get(filter, true); // true to get options dataObj = { 'variableExample' : { _value:'value', _options: { hitType:['page'], permanent:true } } } var dataObj = buffer.get(filter); // no option in results dataObj = { 'variableExample':'value' }
-
presentInFilters(filters, name){boolean}
-
Check if an option is handled by at least one the filters.
Name Type Description filters
Array List of buffer filters name
string Option name -
set(name, value, options)
-
Set value for a hit variable (overrides if present).
Name Type Description name
string Name of the hit variable value
string | number | function | Array value of the hit variable options
object Configuration of the variable, if no hitType defined, it will be "page" by default