在重定向URL上使用HubSpot表单数据

Use HubSpot Form Data on redirectURL

本文关键字:HubSpot 表单 数据 重定向 URL      更新时间:2023-09-26

我正在寻找一种方法,将HubSpot表单的数据发送到提交后重定向到的url,这样我就可以使用它来自动填充该页面上自定义表单中的字段。我试着把我需要的数据存储在一个cookie中,但运气不好。我还在github上找到了一个脚本,用于将数据附加到重定向URL,并在我的登录页模板代码中设置它,但一直无法使其工作:

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名称"hubspoutk",一旦您获取了该名称,就可以使用

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

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

有关api调用的更多信息。

希望它仍然相关。

当您调用要创建的表单时,需要定义"重定向URL"。

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

那么你从Github中找到的代码就可以工作了。

如果你在Hubspot管理面板控制器中的某个地方定义重定向URL,不幸的是,我还没有找到在Github中使用这些代码来查看检索它的方法。