简体   繁体   English

附加参数到 onClick URL

[英]Appending parameters to onClick URL

We're trying to append UTM parameters to a calendly link.我们正在尝试将 append 个 UTM 参数链接到一个日历链接。 It was working great when it was a standard anchor link, but now the site dev has changed the button to an onClick event.当它是标准锚链接时它工作得很好,但现在网站开发人员已将按钮更改为 onClick 事件。

Here is the code we were using to append the parameters to the URL:下面是我们用来将 append 参数传递给 URL 的代码:

(function() {
var links = document.querySelectorAll('a');
    for (var i = 0; i < links.length; i++) {
      if (links[i].hostname == "calendly.com") {
        var calendlyLink = links[i];
        if({{Javascript - finalParams}} !== '?' || {{Javascript - finalParams}} !== 'undefined'){
        calendlyLink.href = calendlyLink.href + {{Javascript - finalParams}};
      console.log(calendlyLink);
            }
      }
    };
 
 })();

Here is the new button code:这是新的按钮代码:

<a class="demo-button" onclick="Calendly.initPopupWidget({url: 'https://calendly.com/xxxxxx/product-demo'});return false;">Button Text</a>

What do I need to change to fix this so the UTM parameters are added to the URL?我需要更改什么才能解决此问题,以便将 UTM 参数添加到 URL?

The Calendly.initPopupWidget method accepts a utm parameter option that can be used to prefill the utm parameters in the iframe (see here ) Calendly.initPopupWidget方法接受一个 utm 参数选项,可用于预填充 iframe 中的 utm 参数(参见此处

<a class="demo-button" onclick="Calendly.initPopupWidget({url: 'https://calendly.com/xxxxxx/product-demo', utm: { utmSource: 'utmSource', utmCampaign: 'utmCampaign' } });return false;">Button Text</a>

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

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