Back to Publisher API Reference
pbjs.mergeConfig(options)
This is the same as setConfig(options) except that it merges the supplied config into the structure rather than replacing it.
This is a convenience function, particularly useful to real time data modules, so one doesn’t have to read the config structure, update it, then call setConfig.
setConfig versus mergeConfig
Both methods update the runtime config:
setConfigreplaces valuesmergeConfigkeeps existing values and merges new ones into them recursively.
Object/scalar properties
setConfig iterates each top-level key in the incoming object and assigns it directly.
It makes no changes to other properties that might already exist in the current version of the config.
config = {
bidderTimeout: 3000,
debug: false
};
setConfig({
bidderTimeout: 5000
});
Result:
{
bidderTimeout: 5000,
debug: false
}
mergeConfig deep-merges the object into the current config.
Just like setConfig, it makes no changes to other properties that might already exist in the current version of the config.
config = {
bidderTimeout: 3000,
ortb2: {
site: { page: 'old.example.com' }
},
debug: false
};
mergeConfig({
bidderTimeout: 5000,
ortb2: {
site: { domain: 'example.com' }
}
});
Result:
{
bidderTimeout: 5000,
ortb2: {
site: {
page: 'old.example.com',
domain: 'example.com'
}
},
debug: false
}
Note that the merge is recursive for objects.
Arrays
setConfig has the exact same behavior for array properties as for scalar/object properties.
It will replace the value.
setConfig({
bidders: ['appnexus', 'rubicon']
});
setConfig({
bidders: ['pubmatic']
});
Result:
{
bidders: ['pubmatic']
}
mergeConfig will append new items to the existing array, and ignore duplicates.
config = {
bidders: ['appnexus']
};
mergeConfig({
bidders: ['rubicon', 'appnexus']
});
Result:
{
bidders: ['appnexus', 'rubicon']
}