Skip to content

Commit d0e57d8

Browse files
Add commands into head of GPT queue when possible
1 parent 3959aa4 commit d0e57d8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

audienceproject-data-web.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,17 @@ export const utils = {
588588
sendDataToGooglePublisherTag: (data) => {
589589
window.googletag = window.googletag || { cmd: [] };
590590

591-
window.googletag.cmd.push(() => {
591+
const setTargeting = () => {
592592
Object.keys(data.keyValues).forEach((key) => {
593593
window.googletag.pubads().setTargeting(key, data.keyValues[key]);
594594
});
595-
});
595+
};
596+
597+
if (window.googletag.cmd.unshift) { // put in front of queue when possible
598+
window.googletag.cmd.unshift(setTargeting);
599+
} else { // native array method is not available if queue was processed
600+
window.googletag.cmd.push(setTargeting);
601+
}
596602
},
597603
};
598604

0 commit comments

Comments
 (0)