utm参数_从URL删除UTM参数

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:17   1463   0

utm参数

If you've ever worked on a social media campaign, you're probably familiar with the UTM tracking pieces of a URL which allow you to tie visits and pageviews with a given campaign. They're a marketing person's dream but ugly for end users to look at. And if you don't want your statistics being muddle up with users bookmarking or sharing the link, you're out of luck. That is, unless you use the History API to prevent that problem:

如果您曾经从事过社交媒体广告系列工作,那么您可能会熟悉URL的UTM跟踪部分,该部分可让您将访问和综合浏览量与给定的广告系列联系起来。 这是营销人员的梦想,但对于最终用户来说很难看。 而且,如果您不希望自己的统计信息与添加书签或共享链接的用户混淆,那么您就不走运了。 也就是说,除非您使用History API来防止该问题:


(function() {
    var win = window;
    var removeUtms = function(){
        var location = win.location;
        if (location.search.indexOf('utm_') != -1 && history.replaceState) {
            history.replaceState({}, '', window.location.toString().replace(/(\&|\?)utm([_a-z0-9=]+)/g, ""));
        }
    };
    ga('send', 'pageview', { 'hitCallback': removeUtms });
})();


First track the event, then remove the ugly UTM parameters and you're golden. It's a tiny bit of code for a tiny bit of gloss. Just remember to track the pageview before removing the UTM parameters!

首先跟踪事件,然后删除丑陋的UTM参数,您会很高兴。 这是一小段代码,只需要一点点光泽。 只需记住在删除UTM参数之前跟踪浏览量即可!

Thank you to Luke Crouch for pointing out this technique!

感谢Luke Crouch指出这项技术!

翻译自: https://davidwalsh.name/remove-utm-parameters-urls

utm参数

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP