Created
January 3, 2018 19:42
-
-
Save RichardDillman/eedf9ebc2bd25d43c075316c63eea1a3 to your computer and use it in GitHub Desktop.
Obtain label id's from loaded slots within GPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the label IDs from all currently loaded GPT slots. | |
* | |
* @return {Array)} The collected label ids. | |
*/ | |
function getLabelIds() { | |
// declare our output array. | |
var labels = []; | |
// for looping over the slots | |
function getlabels(slot) { | |
// get our labelIds | |
var rsp = slot.getResponseInformation() && slot.getResponseInformation().labelIds || []; | |
// Filter for new ids in this slot. | |
var updates = rsp.filter(function(item) { | |
return labels.indexOf(item) < 0; | |
}); | |
// Update the labels array. | |
labels = labels.concat(updates); | |
} | |
// Loop over the slots and get all the IDs. | |
window.googletag.pubads().getSlots().map(getlabels); | |
return labels; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment