Introducing the Pixel Manager Command Queue
ยท 2 min read
TL;DR:
- The Pixel Manager now supports a command queue (
window._pmwq
) starting with version1.49.0
. - It ensures your API calls to the Pixel Manager and custom tracking events are executed safely and in order โ whether the Pixel Manager is loaded yet or not.
- Just push your function or tracking event to the queue, and it'll run when the Pixel Manager is ready.
๐ Why It Mattersโ
Modern websites often load scripts asynchronously to improve performance. This can make it tricky to know whether the Pixel Manager is already available when your code runs.
To solve this, weโve introduced a simple but powerful solution: the command queue.
๐ง What Is It?โ
The Pixel Manager Command Queue is a JavaScript array that temporarily stores API commands until the Pixel Manager is ready to execute them.
How It Worksโ
- The queue is available globally as
window._pmwq
- You push functions (commands) into it
- If the Pixel Manager is already loaded, the command runs immediately
- If not, the command is queued and run as soon as the Pixel Manager is ready
๐ ๏ธ Example Usageโ
Here's how to safely send commands to the Pixel Manager, regardless of load timing:
window._pmwq = window._pmwq || [];
window._pmwq.push(function () {
// Add your command here
console.log('API call to the Pixel Manager API');
});
This is especially useful for developers who develop consent banners and want to integrate with our Consent Management API.
window._pmwq = window._pmwq || [];
window._pmwq.push(function () {
pmw.consent.api.acceptAll();
});