
/* Controltag Loader for Gawker Media */
(function(){
  function debugLog(msg) {
    var isDebug = /kxdebug=(1|true)/.test(location);
    if (isDebug && typeof window.console === 'object' && typeof console.info === 'function') {
      console.info(msg);
    }
  }

  function loadCT(url, callback) {
    debugLog('Loading Krux control tag.');
    var ct_element = document.createElement('script');
    ct_element.async = true;
    ct_element.src = url;

    ct_element.onload = ct_element.onreadystatechange = function() {
      var state = ct_element.readyState;
      if (!callback.done && (!state || /loaded|complete/.test(state))) {
        callback.done = true;
        callback();
      }
    };

    // Fetch the first script element, so we can insert the
    // controltag before it. There *must* be at least one
    // script element, or this code would never be called
    var sibling = document.getElementsByTagName('script')[0];
    sibling.parentNode.insertBefore(ct_element, sibling);
  };

  function loadConfig() {
    
    
    debugLog('Loading krux configuration.');

    var config = {"partner_segment_map": {}, "context_terms": [], "tags": [{"content": "<script>\r\n  Krux('require:http').pixel({\r\n    url: \"//s.ixiaa.com/digi/C726AB29-0470-440B-B8D2-D552CED3A3DC/a.gif\"\r\n  });\r\n</script>", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 28, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "data provider", "id": 32829, "name": "IXI Digital Open Market provider tag"}, {"content": "<script type=\"text/javascript\">Krux('social.init');</script>", "target": null, "target_action": "append", "require": "", "docwrite": null, "internal": 1, "template_replacement": 1, "execution_results": null, "tier": 1, "library_tag_config": {}, "content_type": "html", "timing": "onload", "method": "document", "type": "library", "id": 32328, "name": "Krux Track Social"}, {"content": "<img src=\"//adadvisor.net/adscores/g.js?sid=9212244187&_kdpid=2111c0af-fc3a-446f-ab07-63aa74fbde8e\" />", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 22, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "data provider", "id": 32373, "name": "AdAdvisor S2S provider tag"}, {"content": "<script>\r\n(function(){\r\n  var kuid = Krux('get', 'user');\r\n  if (kuid) {\r\n      var liveramp_url = 'https://idsync.rlcdn.com/379708.gif?partner_uid=' + kuid;\r\n      var i = new Image();\r\n      i.src = liveramp_url;      \r\n  }\r\n})();\r\n</script>", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 21, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "data provider", "id": 32374, "name": "Acxiom S2S provider tag"}, {"content": "<script>\r\n(function() {\r\n  // krxd.nexac.com throws SSL cert errors so only fire this tag\r\n  // on HTTP pages\r\n  if (location.protocol == \"http:\") {\r\n      var kuid = Krux('get', 'user');\r\n      if (kuid) {\r\n         var u = \"http://krxd.nexac.com/dlx.gif?_kdpid=2dd640a6-6ebd-4d4f-af30-af8baa441a0d&kuid=\" + kuid;\r\n         (new Image()).src = u;\r\n      }\r\n   }\r\n})();\r\n</script>", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 8, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "data provider", "id": 32375, "name": "DataLogix provider tag"}, {"content": "<script>\r\n(function(){\r\n  var kuid = Krux('get', 'user');\r\n  if (kuid) {\r\n    Krux('require:http').pixel({\r\n      url: \"//loadm.exelator.com/load\",\r\n      data: {\r\n          _kdpid: 'e4942ff0-4070-4896-a7ef-e6a5a30ce9f9',\r\n          buid: kuid,\r\n          p: '204',\r\n          g: '270',\r\n          j: '0'\r\n      }});\r\n  }\r\n  })();\r\n</script>", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 11, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "data provider", "id": 32376, "name": "eXelate Media provider tag"}, {"content": "<script>\r\n// this tag is intentionally blank\r\n</script>", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 6, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "data provider", "id": 31370, "name": "Technographic Data provider tag"}, {"content": "", "target": null, "target_action": "append", "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 14, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "id": 31371, "name": "Krux Geographic Data provider tag"}, {"content": "<script type=\"text/javascript\">\r\nif(window._sf_async_config != undefined || null)\r\n{\r\nKrux('set', 'page_attr_authors', typeof window._sf_async_config === 'object' && window._sf_async_config['authors']);\r\nKrux('set', 'page_attr_sections', typeof window._sf_async_config === 'object' && window._sf_async_config['sections']);\r\n}\r\n\r\n// Using Globals __reach_config.pid to produce page attribute __reach_config.pid\r\nKrux('scrape', { 'page_attr___reach_config.pid': {js_global: \"__reach_config.pid\"}});\r\n</script>", "target": "", "target_action": null, "require": "", "docwrite": null, "template_replacement": 1, "execution_results": {"onloadSafe": true, "docwrite": false, "listeners": []}, "tier": 1, "internal": 1, "content_type": "html", "timing": "onload", "method": "document", "type": "publisher", "id": 36136, "name": "All Gawker Data Transfer Code"}, {"content": "<script>\r\nKrux('set', 'page_attr_Jzbl_authors', typeof window._sf_async_config === 'object' && window._sf_async_config['authors']);\r\nKrux('set', 'page_attr_Jzbl_sections', typeof window._sf_async_config === 'object' && window._sf_async_config['sections']);\r\n</script>", "target": "", "target_action": null, "require": "", "docwrite": null, "template_replacement": 1, "execution_results": {"onloadSafe": true, "docwrite": false, "listeners": []}, "tier": 1, "internal": 1, "content_type": "html", "timing": "onload", "method": "document", "type": "publisher", "id": 32325, "name": "Jezebel Data Transfer Code"}, {"content": "<script type=\"text/javascript\">// DFP premium\r\n(function(require) {\r\n  var config = require('config')();\r\n  var store = require('store');\r\n  var _ = require('util');\r\n  var segments;\r\n\r\n  function handleUserDataResponse(r) {\r\n    // Handle the response as usual.\r\n    segments.handleUserDataResponse(r);\r\n    // Override localStorage.kxuser with a case-insensitive value for DFP premium.\r\n    // This will get read by the interchange direct snippet for Krux.user\r\n    // and Krux.dfpKeyValues\r\n    if(r.kuid_long) {\r\n      store.set('user', r.kuid_long, store.DAYS*30);\r\n    }\r\n  }\r\n\r\n  // Our own fetch uses our own handleResponse\r\n  function fetch() {\r\n    var options = {\r\n      url: _.get('url_userData'),\r\n      data: {\r\n        pubid: _.get('pubid')\r\n      },\r\n      callback: 'kxjsonp_userData',\r\n      done: handleUserDataResponse\r\n    };\r\n\r\n    // SEE: SCRUM-1129\r\n    var orgUserId = _.get('org_user_id');\r\n    if(orgUserId) {\r\n      options.data._kuid = orgUserId;\r\n    }\r\n\r\n    var fpId;\r\n    var useFingerprint = config.get('params.fingerprint', false);\r\n    if (useFingerprint && _.get('fp_sent')) {\r\n      fpId = _.get('fp_id');\r\n      options.data.kxfp = _.get('fp');\r\n      if (fpId) {\r\n        options.data.kfuid = fpId;\r\n      }\r\n    }\r\n    else if (useFingerprint) {\r\n      fpId = _.get('fp_id');\r\n      if (fpId) {\r\n        options.data.kfuid = fpId;\r\n      }\r\n    }\r\n\r\n    if(!segments.readTechFromStore()) {\r\n      options.data.technographics = 1;\r\n    }\r\n    require('http').jsonp(options); \r\n  }\r\n\r\n  if(!store.get('segWait')) {\r\n    // disable segments.fetch and use our own\r\n    _.set('segWait', 1, store.MINUTES*5);\r\n    _.onOnce('dom:load', fetch);\r\n    _.fire('user_data_fetch_scheduled');\r\n  }\r\n\r\n  // Finally, require segments as usual.\r\n  segments = require('segments');\r\n}(Krux.require));\r\n</script>", "target": "", "target_action": null, "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": false, "content_type": "html", "timing": "onload", "method": "document", "type": "publisher", "id": 31373, "name": "Load Segments v3 (fingerprinting)"}, {"content": "<script>\r\n(function(){\r\n  var kuid = Krux('get', 'user');\r\n  if (kuid && typeof kuid != 'undefined') {\r\n      var prefix = location.protocol == 'https:' ? \"https:\" :\"http:\";\r\n      var r_url = prefix + '//cm.g.doubleclick.net/pixel'\r\n      var kurl = prefix + '//apiservices.krxd.net/um?partner=google&r=' + r_url;\r\n      var i = new Image();\r\n      i.src = kurl;\r\n  }\r\n})();\r\n</script>", "target": "", "target_action": null, "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 1, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "publisher", "id": 31374, "name": "Google User Match"}, {"content": "<script>\r\n(function(){\r\n  if (window.Krux) {\r\n    var kuid = window.Krux('get', 'user');\r\n    if (kuid && typeof kuid != 'undefined') {\r\n       var rubicon_url = '//tap.rubiconproject.com/oz/feeds/krux/tokens?afu=' + kuid;\r\n       var i = new Image();\r\n       i.src = rubicon_url;\r\n\r\n      var ki = new Image();\r\n      ki.src = '//beacon.krxd.net/usermatch.gif?partner=rubicon&kuid=' + kuid;\r\n    }\r\n  }\r\n})();\r\n</script>", "target": "", "target_action": null, "require": "", "docwrite": null, "template_replacement": 1, "execution_results": null, "tier": 1, "internal": 1, "content_type": "html", "freq_cap": 3, "timing": "onload", "method": "document", "type": "publisher", "id": 31375, "name": "Rubicon User Match"}, {"content": "<script> Krux('admEvent','Jm6OxIje', {}); </script>", "target": "", "target_action": null, "require": "", "docwrite": null, "template_replacement": 1, "execution_results": {"onloadSafe": true, "docwrite": false, "listeners": []}, "tier": 1, "internal": false, "content_type": "html", "criteria": [{"operator": "=", "name": "page_attr___reach_config.pid", "value": "524998cce79548b4db000001"}], "timing": "onload", "method": "document", "type": "publisher", "id": 43954, "name": "Test Re-Targeting Pixel"}], "segments": [], "publisher": {"uuid": "f957ee1a-d222-492b-b86e-4b6eba139638", "id": 12252, "name": "Gawker Media"}, "controltag_options": {"async": "true", "render": true}, "site": {"id": 18111, "name": "Jezebel"}, "dnt": null, "params": {"connector_host": "connector.krxd.net", "control_tag_load_sync": "false", "fingerprint": "0", "disable_http_compression": false, "remove_kxhead": true, "supertag_requires_approval": false, "config_source": 1, "control_tag_stats_prefix": null, "beacon_host": "beacon.krxd.net", "control_tag_pixel_throttle": "100", "user_id_cookie": null, "max_segments": null, "no_pii": 0, "recommend": false, "revenue_optimization": false, "context_terms": "false", "jslog_host": "jslog.krxd.net", "site_level_supertag_config": "site", "max_slot_time": 1000, "services_host": "apiservices.krxd.net", "capture_leakage": true, "client_side_storage": "localStorage,cookie", "userData_host": "cdn.krxd.net", "control_tag_namespace": null, "control_tag_version": "stable", "capture_js_errors": "true", "datatag_version": "3", "target_fingerprint": "0"}, "services": {"impression": "//beacon.krxd.net/ad_impression.gif", "stats": "//apiservices.krxd.net/stats", "log": "//jslog.krxd.net/jslog.gif", "userData": "//cdn.krxd.net/user_data/segments/3", "um": "//apiservices.krxd.net/um", "optout": "//beacon.krxd.net/optout_check", "pixel": "//beacon.krxd.net/pixel.gif", "contentConnector": "//connector.krxd.net/content_connector/", "is_optout": "//beacon.krxd.net/optout_check", "set_optin": "//apiservices.krxd.net/consumer/optin", "social": "//beacon.krxd.net/social.gif", "set_optout": "//apiservices.krxd.net/consumer/optout", "data": "//beacon.krxd.net/data.gif", "event": "//beacon.krxd.net/event.gif"}, "geo": {}, "realtime_segments": [{"test": ["and", ["or", ["and", ["or", ["intersects", "$page_attr___reach_config.pid", "[\"524998cce79548b4db000001\"]"]]]]], "id": "o7mp4e3md"}, {"test": ["and", ["or", ["and", ["or", "$event_Jm6OxIje"]]]], "id": "o9i68fk9g"}], "confid": "JO5Gn2nq"};

    // Wrap in a function and comment, then toString the func and replace
    // everything that's not the beginning or end of a JSON object, so we get a
    // string that's either empty or JSON.
    var esiGeo = String(function(){/*
      {"CONTINENT":"NA", "COUNTRY":"CA", "REGION":"QC", "CITY":"Montréal", "DMA":"0", "AREACODE":"0", "ZIP":"H3A", "LATITUDE":"45.508", "LONGITUDE":"-73.580"}
    */}).replace(/^.*\/\*[^{]+|[^}]+\*\/.*$/g, '');

    if (esiGeo) {
      config.geo = esiGeo;
    }

    Krux('config', config);
    
  };

  // ControlTag simply crashes when opening a website from Twitter browser on
  // iOS, temporarily disable CT when Twitter for iPhone is detected until they
  // fix this (works fine with other twitter client though)
  if (/Twitter for iPhone/.test(window.navigator.userAgent || '')) return;
    
  loadCT( "//cdn.krxd.net/ctjs/controltag.js.260514603d3d46dab9229c98b8488fde", loadConfig );
})();
