libraries/tracking-core/helpers/formatHelpers.js
function sanitizeTitle(title, shopName) {
  // Take care that the parameters don't contain leading or trailing spaces
  let trimmedTitle = title.trim();
  const trimmedShopName = shopName.trim();

  if (!trimmedShopName) {
    /**
     * If no shop name is available, it doesn't make sense to replace it.
     * So we return the the trimmed title directly.
     */
    return trimmedTitle;
  }

  /**
   * Setup the RegExp. It matches leading and trailing occurrences
   * of known patterns for generically added shop names within page title
   */
  const shopNameRegExp = new RegExp(`((^${trimmedShopName}:)|(- ${trimmedShopName}$))+`, 'ig');

  if (trimmedTitle === trimmedShopName) {
    // Clear the page title if it only contains the shop name
    trimmedTitle = '';
  }

  // Remove the shop name from the page title
  return trimmedTitle.replace(shopNameRegExp, '').trim();
}
function sanitizeTitle(title, shopName) {
  // Take care that the parameters don't contain leading or trailing spaces
  let trimmedTitle = title.trim();
  const trimmedShopName = shopName.trim();

  if (!trimmedShopName) {
    /**
     * If no shop name is available, it doesn't make sense to replace it.
     * So we return the the trimmed title directly.
     */
    return trimmedTitle;
  }

  /**
   * Setup the RegExp. It matches leading and trailing occurrences
   * of known patterns for generically added shop names within page title
   */
  const shopNameRegExp = new RegExp(`((^${trimmedShopName}:)|(- ${trimmedShopName}$))+`, 'ig');

  if (trimmedTitle === trimmedShopName) {
    // Clear the page title if it only contains the shop name
    trimmedTitle = '';
  }

  // Remove the shop name from the page title
  return trimmedTitle.replace(shopNameRegExp, '').trim();
}
function sanitizeTitle ( title , shopName ) { // Take care that the parameters don't contain leading or trailing spaces let trimmedTitle = title . trim ( ) ; const trimmedShopName = shopName . trim ( ) ; if ( ! trimmedShopName ) { /**
     * If no shop name is available, it doesn't make sense to replace it.
     * So we return the the trimmed title directly.
     */ return trimmedTitle ; } /**
   * Setup the RegExp. It matches leading and trailing occurrences
   * of known patterns for generically added shop names within page title
   */ const shopNameRegExp = new RegExp ( ` ${ trimmedShopName } ${ trimmedShopName } ` , 'ig' ) ; if ( trimmedTitle === trimmedShopName ) { // Clear the page title if it only contains the shop name trimmedTitle = '' ; } // Remove the shop name from the page title return trimmedTitle . replace ( shopNameRegExp , '' ) . trim ( ) ; }
Removes shop names out of the page title
@param {string} title The page title
@param {string} shopName The shop name
@returns {string} The sanitized page title
Removes shop names out of the page title