justinhelmer
7/12/2017 - 3:09 PM

tealium script with KS consideration

tealium script with KS consideration

define(['scriptjs'], function ($script) {
  'use strict';
  
  const tealiumKS = window.ENV_CONFIG.tealium_enabled === 'on' ? true : false;
  
  let tealium = {
    _promise: null,
    load: () => !tealiumKS ? (() => ({})) : load()
  };
  
  function load() {
    if (!tealium._promise) { 
      const tealiumEnvironment = window.ENV_CONFIG.tealium_environment,
        brand = App.config.brand,
        brandNameForTealium = brand === 'mcom' ? 'macys' : brand;

      tealium._promise = new Promise((resolve, reject) => {
        $script(['//tags.tiqcdn.com/utag/' + brandNameForTealium + '/main/' + tealiumEnvironment + '/utag.js'], resolve, reject);
      });
    }

    return tealium._promise;
  });
  
  return tealium;
});