Как расширить этот скрипт, чтобы удалить дополнительные параметры отслеживания, например - PullRequest
0 голосов
/ 28 мая 2020

Я нашел этот полезный скрипт для удаления параметров отслеживания в URL-адресе, но я хотел бы удалить больше параметров, чем просто utm_xxx.

function() {
    // Returns a function to strip out UTM parameters. So can be used as a function based parameter
    // when GA has finished it's pageview
    return function() {
        if (!window.history.replaceState) { return; }; 
        var cleanSearch = window.location.search
            .replace(/utm_[^&]+&?/g, '') // removes utm_xxx parameters
            .replace(/&$/, '')  // removes & if last character
            .replace(/^\?$/, '')  // removes ? if only remaining character
            ;

        // some pass utm_xxxx in the hash
        var cleanHash = window.location.hash
            .replace(/utm_[^&]+&?/g, '') // removes utm_xxx parameters
            .replace(/&$/, '')  // removes & if last character
            .replace(/^\#$/, '')  // removes # if only remaining character
            ;
        window.history.replaceState({}, '', window.location.pathname + cleanSearch + cleanHash);
    }
}

Ниже приведены шаблоны отслеживания, которые я использовал в рекламе. Итак, как удалить их с помощью приведенного выше сценария? Спасибо большое.

  • тип соответствия
  • adgroupid
  • adposition
  • сеть
  • устройство
  • размещение
  • targetid
  • feeditemid

✭Шаблон отслеживания поиска

{lpurl}?utm_campaign={campaignid}&utm_source=google&utm_medium=cpc&utm_content={creative}&utm_term={keyword}&matchtype={matchtype}&adgroupid={adgroupid}&adposition={adposition}&network={network}&device={device}&placement={placement}&targetid={targetid}&feeditemid={feeditemid}

✭Шаблон отслеживания отображения

{lpurl}?utm_campaign={campaignid}&utm_source=google&utm_medium=display&utm_content={creative}&adgroupid={adgroupid}&network={network}&device={device}&target={target}&placement={placement}&targetid={targetid}&utm_term={keyword}
...