Code to surface BKUUID from the BlueKai iframe to the page and store it in a cookie
<!--
- Run this code on your page before any BlueKai code (best to run top of the <body> or <head> if you need)
- Will pull BKUUID and drop in "bku_1p" cookie with a value of "CONTAINERID:BKUUID" (e.g. "12345:sjdhajshdsad")
-->
<script type="text/javascript">
// Set up global vars
window.bluekai_service = window.bluekai_service || {};
window.bluekai_service.functions = window.bluekai_service.functions || {};
window.bluekai_service.bkuuid_caller = window.bluekai_service.bkuuid_caller || {};
// FUNCTION : Receive BKUUID from iframe (postMessage handler)
bluekai_service.functions.bkuuid_parent_receiver = function(event) {
if (event.origin.indexOf("tags.bluekai.com") > -1) {
if (window.bluekai_service.bkuuid_caller.__bluekai_data_sent === false && typeof event.data !== 'undefined' && event.data.source === 'bluekai') {
// Drop into permanent cookie (using container site ID)
document.cookie = "bku_1p=" + event.data.bluekaiIds.container_id + ":" + event.data.bluekaiIds.bk_uuid + ";path=/;domain=" +
document.domain + ";expires=Thu, 31 Dec 2099 00:00:00 GMT";
window.bluekai_service.bkuuid_caller.__bluekai_data_sent = true;
}
}
}
// ### EXECUTION ###
window.bluekai_service.bkuuid_caller.__bluekai_data_sent = false;
addEventListener('message', window.bluekai_service.functions.bkuuid_parent_receiver, false);
</script>
<!--
- Run this code in a 'tag' in BlueKai and schedule to your containers of choice.
- It will surface the BKUUID and the container ID it is obfuscated on
-->
<script type="text/javascript">
var bk_uuids = {"container_id":document.location.pathname.split('/')[2],"bk_uuid":"$_BK_UUID", "bk_uuid_noslash":"$_BK_UUID_NOSLASH"};
parent.postMessage({bluekaiIds: bk_uuids, source: 'bluekai' }, '*');
</script>