P7S1 HbbTV Libraries

General

/**
 * Request the user data of the current user from the AdProxy and check if content
 * tracking is allowed
 *
 * @param {(isAllowed: boolean) => void} callback
 */
function isTrackingAllowed(callback) {
  var url = location.protocol + '//redbutton-adproxy-lb-prod.redbutton.de/user';
  $.ajax({ url, dataType: 'jsonp', cache: true, timeout: 10000 })
  .done(function(data) {
    if (data['content-tracking'] === 'off') {
      callback(false);
    } else {
      callback(true);
    }
  })
  .fail(function() {
    callback(false);
  });
}

Webtrekk

// fix for some devices so webtrekk doesn't crash
try {
  if (navigator.vendor === undefined) {
    navigator.vendor = '';
  }
} catch () {}

// example
initWebtrekk('hbbtv.prosieben.de', 'prod', function(webtrekk) {
  // store webtrekk instance
});

/**
 * Create the global webtrekkConfig object, load webtrekk and initialize it.
 * 
 * @param {string} domain
 * @param {string} webtrekkEnv
 * @param {(webtrekk: webtrekkV3) => void} callback
 */
function initWebtrekk(domain, webtrekkEnv, callback) {
  var trackIds = {
    test: {
      de: '766367172823277',
      at: '491545417275449'
    },
    prod: {
      de: '399620847653221',
      at: '139614371459755'
    }
  };
  var countryCode = webtrekkConfig.domain.match(/\.([a-z]+)$/)[1];
  var trackId = trackIds[webtrekkEnv][countryCode];

  // set global webtrekkConfig object
  window.webtrekkConfig = {
    trackId: trackId,
    domain: domain
  };

  // TODO: Use different path if mediaTracking is also required
  var url = location.protocol + '//hbbtv-libraries.redbutton.de/webtrekk/latest/'
    + webtrekkEnv + '/webtrekk.min.js';

  $.ajax({ url, dataType: 'script', cache: false, timeout: 10000 })
  // finally
  .done(function() {
    callback(new webtrekkV3());
  })
  .fail(function() {
    callback();
  });
}

latest (production)

latest (test)