libraries/tracking-core/helpers/urlMapping.js
function sgTrackingUrlMapper(url, data) {
  // In our development system urls start with /php/shopgate/ always
  const developmentPath = '/php/shopgate/';
  const appRegex = /sg_app_resources\/[0-9]*\//;

  // Build regex that will remove all blacklisted paramters
  let regex = '';
  urlParameterBlacklist.forEach((entry) => {
    regex += `((\\?|^){0,1}(${entry}=.*?(&|$)))`;
    regex += '|';
  });
  const params = url.indexOf('?') !== -1 ? url.split('?')[1] : '';
  let urlParams = params.replace(new RegExp(regex, 'g'), '');
  urlParams = urlParams === '' ? '' : `?${urlParams.replace(/&$/, '')}`;

  // Get rid of hash and app urls
  let urlPath = url.split('?')[0].split('#')[0].replace(appRegex, '');

  // Get path from url
  if (url.indexOf(developmentPath) !== -1) {
    urlPath = urlPath.substring(urlPath.indexOf(developmentPath) + developmentPath.length);
  } else if (urlPath.indexOf('http') !== -1) {
    urlPath = urlPath.substring(urlPath.indexOf('/', urlPath.indexOf('//') + 2) + 1);
  } else {
    urlPath = urlPath.substring(1);
  }

  // Get action from path
  const action = urlPath.substring(
    0,
    ((urlPath.indexOf('/') !== -1) ? (urlPath.indexOf('/')) : undefined)
  );

  // If no mapping function is available for the action, continue
  if (typeof mapping[action] === 'undefined') {
    return {
      public: urlPath + urlParams,
      private: action,
    };
  }

  // Call mapping function and return its result
  const pathWithoutAction = urlPath.substring(action.length + 1);
  let pathWithoutActionArray = [];

  if (pathWithoutAction.length !== 0) {
    pathWithoutActionArray = pathWithoutAction.split('/');
  }

  const mappedUrls = mapping[action](pathWithoutActionArray, data || {});

  if (Array.isArray(mappedUrls)) {
    return {
      public: mappedUrls[1] + urlParams,
      private: mappedUrls[0],
    };
  }

  return {
    public: mappedUrls + urlParams,
    private: mappedUrls,
  };
}
function sgTrackingUrlMapper(url, data) {
  // In our development system urls start with /php/shopgate/ always
  const developmentPath = '/php/shopgate/';
  const appRegex = /sg_app_resources\/[0-9]*\//;

  // Build regex that will remove all blacklisted paramters
  let regex = '';
  urlParameterBlacklist.forEach((entry) => {
    regex += `((\\?|^){0,1}(${entry}=.*?(&|$)))`;
    regex += '|';
  });
  const params = url.indexOf('?') !== -1 ? url.split('?')[1] : '';
  let urlParams = params.replace(new RegExp(regex, 'g'), '');
  urlParams = urlParams === '' ? '' : `?${urlParams.replace(/&$/, '')}`;

  // Get rid of hash and app urls
  let urlPath = url.split('?')[0].split('#')[0].replace(appRegex, '');

  // Get path from url
  if (url.indexOf(developmentPath) !== -1) {
    urlPath = urlPath.substring(urlPath.indexOf(developmentPath) + developmentPath.length);
  } else if (urlPath.indexOf('http') !== -1) {
    urlPath = urlPath.substring(urlPath.indexOf('/', urlPath.indexOf('//') + 2) + 1);
  } else {
    urlPath = urlPath.substring(1);
  }

  // Get action from path
  const action = urlPath.substring(
    0,
    ((urlPath.indexOf('/') !== -1) ? (urlPath.indexOf('/')) : undefined)
  );

  // If no mapping function is available for the action, continue
  if (typeof mapping[action] === 'undefined') {
    return {
      public: urlPath + urlParams,
      private: action,
    };
  }

  // Call mapping function and return its result
  const pathWithoutAction = urlPath.substring(action.length + 1);
  let pathWithoutActionArray = [];

  if (pathWithoutAction.length !== 0) {
    pathWithoutActionArray = pathWithoutAction.split('/');
  }

  const mappedUrls = mapping[action](pathWithoutActionArray, data || {});

  if (Array.isArray(mappedUrls)) {
    return {
      public: mappedUrls[1] + urlParams,
      private: mappedUrls[0],
    };
  }

  return {
    public: mappedUrls + urlParams,
    private: mappedUrls,
  };
}
function sgTrackingUrlMapper ( url , data ) { // In our development system urls start with /php/shopgate/ always const developmentPath = '/php/shopgate/' ; const appRegex = / sg_app_resources\/[0-9]*\/ / ; // Build regex that will remove all blacklisted paramters let regex = '' ; urlParameterBlacklist . forEach ( ( entry ) => { regex += ` \\ ${ entry } ` ; regex += '|' ; } ) ; const params = url . indexOf ( '?' ) !== - 1 ? url . split ( '?' ) [ 1 ] : '' ; let urlParams = params . replace ( new RegExp ( regex , 'g' ) , '' ) ; urlParams = urlParams === '' ? '' : ` ${ urlParams . replace ( / &$ / , '' ) } ` ; // Get rid of hash and app urls let urlPath = url . split ( '?' ) [ 0 ] . split ( '#' ) [ 0 ] . replace ( appRegex , '' ) ; // Get path from url if ( url . indexOf ( developmentPath ) !== - 1 ) { urlPath = urlPath . substring ( urlPath . indexOf ( developmentPath ) + developmentPath . length ) ; } else if ( urlPath . indexOf ( 'http' ) !== - 1 ) { urlPath = urlPath . substring ( urlPath . indexOf ( '/' , urlPath . indexOf ( '//' ) + 2 ) + 1 ) ; } else { urlPath = urlPath . substring ( 1 ) ; } // Get action from path const action = urlPath . substring ( 0 , ( ( urlPath . indexOf ( '/' ) !== - 1 ) ? ( urlPath . indexOf ( '/' ) ) : undefined ) ) ; // If no mapping function is available for the action, continue if ( typeof mapping [ action ] === 'undefined' ) { return { public : urlPath + urlParams , private : action , } ; } // Call mapping function and return its result const pathWithoutAction = urlPath . substring ( action . length + 1 ) ; let pathWithoutActionArray = [ ] ; if ( pathWithoutAction . length !== 0 ) { pathWithoutActionArray = pathWithoutAction . split ( '/' ) ; } const mappedUrls = mapping [ action ] ( pathWithoutActionArray , data || { } ) ; if ( Array . isArray ( mappedUrls ) ) { return { public : mappedUrls [ 1 ] + urlParams , private : mappedUrls [ 0 ] , } ; } return { public : mappedUrls + urlParams , private : mappedUrls , } ; }
Maps an internal url to an external url that we can send to tracking providers

@param {string} url internal url
@param {Object} [data] sgData object

@returns {Object} external url
Maps an internal url to an external url that we can send to tracking providers