繁体   English   中英

在redirectURL上使用HubSpot表单数据

[英]Use HubSpot Form Data on redirectURL

我正在寻找一种将HubSpot表单的数据发送到提交后重定向到的url的方法,以便我可以使用它来自动填充该页面上的自定义表单中的字段。 我尝试将所需的数据存储在cookie中,但没有任何运气。 我还在github上找到了一个脚本,用于将数据附加到redirectURL并在我的着陆页模板代码中进行设置,但无法使其正常工作:

https://gist.github.com/axiak/2bf8f43d9d4a5f9c883f

 /**
 * Append the form data from a HubSpot form automatically
 * to the redirect URL query parameters. These values can
 * then be used on the form to modify the user experience
 * of the Thank You page
 * 
 * LICENSE
 * Form redirect
 * Written in 2015 by Mike Axiak <maxiak@hubspot.com>
 * To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
 * You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
 */
(function() {
  var $ = jQuery;

  var appendFields = function (url, values) {
    var data = {};
    $.each(values, function (i, item) {
      if (item.name !== "hs_context") {
        data[item.name] = item.value;
      }
    });
    if (url.match(/\?/)) {
      return url + "&" + $.param(data);
    } else {
      return url + "?" + $.param(data);
    }
  };

  $(function () {

  $("body").on("submit", "form.hs-form", function (e) {
    var $form = $(this);
    var apiUrl = $form.attr("action");
    var $hsContext = $("input[name='hs_context']", $form);
    var hsContext = JSON.parse($hsContext.val());
    hsContext.redirectUrl = appendFields(hsContext.redirectUrl, $form.serializeArray());
    $hsContext.val(JSON.stringify(hsContext));
  });

  });
})();

我认为您可以使用Hubspot的开发人员API来获取与联系人相关的所有数据。 Hubspot将用户令牌存储为cookie名称“ hubspotutk”,一旦您抓起就可以使用

GET /contacts/v1/contact/utk/:contact_utk/profile

获取与当前联系人关联的所有属性,其中应包括他们在第一页中填写的所有内容。

有关api调用的更多信息。

希望它仍然有意义。

要求创建表单时,需要定义“ redirectUrl”。

hbspt.forms.create({
    redirectUrl:"www.google.com",//here you go
    formId: '<your form id>',...}

那么您从Github找到的代码将起作用。

如果您在Hubspot管理仪表板控制器中的某个位置定义了重定向URL,很遗憾,我还没有找到使用Github中的这些代码来检索重定向URL的方法。

暂无
暂无

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

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