简体   繁体   English

根据目标更改URL参数附加到链接的方式

[英]Changing how URL parameters are appended to links based on destination

My company is serving up PPC landing pages with Unbounce (on a subdomain), which then links back to our website. 我的公司通过Unbounce(在子域上)为PPC登陆页面提供服务,然后将其链接回我们的网站。 We're using the following code to append the AdWords gclid variable to outgoing links: 我们使用以下代码将AdWords gclid变量附加到传出链接中:

 $(document).ready(function() {var params = window.location.search.replace(/\+/g,'%20'); var button = $('a').each( function(i) {this.href = this.href + params;});});

The issue arises when the Gclid gets appended to a URL that already has a parameter (like our checkout forms). 当Gclid附加到已经具有参数的URL(例如我们的结帐表格)时,就会出现问题。 You end up with a URL that looks like this: 您最终得到的URL如下所示:

domain.com/checkout?EventID=15546?Gclid=jdkI324kd 

I'm wondering if there's a way to change the Glid's ' ? 我想知道是否有办法改变滑翔机的滑行能力 ' to an ' & ' for certain URLs that already have parameters, while keeping the existing functionality of using the '?' 对于某些已经具有参数的URL,将'改为' ',同时保留使用'?'的现有功能。 for the others. 为其他人。

Thanks! 谢谢!

Edit: Seems like there's some redirection going on, this is how the href looks for the links in question: http://domain.com/lp/clkg/https/domain.com/cart.aspx?EventID=125160?gclid=CPfO1JaOx7oCFQZyQgod5A4AFw 编辑:似乎正在进行一些重定向,这是href查找相关链接的方式: http : //domain.com/lp/clkg/https/domain.com/cart.aspx?EventID=125160?gclid= CPfO1JaOx7oCFQZyQgod5A4AFw

Simply replace it yourself: 只需自己更换:

$(document).ready(function() {
    var params = window.location.search.replace(/\+/g,'%20'); 
    var button = $('a').each( function(i) {
        if (this.href.indexOf('?') == -1) {
            this.href = this.href + params;
        } else if (params.length) {
            this.href = this.href + '&' + params.substr(1);
        }
    });
});

Edit: and are you aware that you are replacing subsequent spaces with only one single '%20'? 编辑:并且您知道仅用一个'%20'替换后续空格吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM