自动填充来自Marketo Cookie的潜在客户信息的Marketo表单字段

时间:2017-03-02 20:18:33

标签: marketo

我们想要一种方法来跟踪从未通过Marketo发送的邮件中点击PDF链接的潜在客户。我们也不希望对PDF文件(要求我们的客户填写表格)进行访问以访问该文件。在谈到支持和搜索Marketo四分之一和支持站点之后,我理解(我认为)实现此目的的唯一方法是进行REST API调用并尝试从他们的PC上的cookie文件中获取前导信息(将会访问我们的PDF是已知的客户而不是普通公众。我不是专家编码员,所以我从我的研究中修补了这个代码,足以说它不起作用,任何帮助都将受到赞赏。

<script src="//xxx.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_2244" style="display:none"></form>
<script>MktoForms2.loadForm("//xxx.marketo.com", "xxx-xxx-xxx", 2244);</script>

<script>
MktoForms2.whenReady(function(form) {

  //OnSuccess is optional - only if you need to make client-side decisions about Thank You URL
  form.onSuccess(function(vals, tyURL) {
    location.href = 'http://www.1234.com/rs/xxx-xxx-123/images/somepdffile.pdf'; 
    return false;
  });

     //Get LEAD info from cookie
     var mktoGet = new XMLHttpRequest();
     mktoGet.open("GET", "https://xxx-xxx-xxx.mktorest.com/rest/v1/leads.json?filterType=cookie&filterValues=<cookie>&fields=email,firstName,lastName&access_token=<token>", false);
     mktoGet.send();

    //set the first result as local variable
    var mktoLeadFields = mktoLead.result[0];

    //map your results from REST call to the corresponding field name on the form
    var prefillFields = {
            "Email" : mktoLeadFields.email,
            "FirstName" : mktoLeadFields.firstName,
            "LastName" : mktoLeadFields.lastName
            };

    //pass our prefillFields objects into the form.vals method to fill our fields
    form.vals(prefillFields);
    });
  //Submit the form
  form.submit();
});
</script>

P.S。我替换了和值,一旦我在浏览器中粘贴链接,我就得到了成功结果。

2 个答案:

答案 0 :(得分:0)

您无法以这种方式使用REST API,因为它要求您每次都生成一个新的访问令牌,而且更有问题,将其暴露在客户端。 我能想到的唯一选择是使用重定向链接到marketo登陆页面。 您将创建一个空的登录页面并插入以下代码,这些代码将简单地重定向到您的pdf。

<script>location.href = 'http://www.1234.com/rs/xxx-xxx 123/images/somepdffile.pdf';</script>

此活动将记录在已知潜在客户的活动日志中

答案 1 :(得分:0)

<script type="text/javascript">  
  document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin-beta.js' type='text/javascript'%3E%3C/script%3E"));
</script> 
<script>  
  Munchkin.init('xxx-xxx-xxx'); 
</script> 
<script>
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj, start) {
         for (var i = (start || 0), j = this.length; i < j; i++) {
             if (this[i] === obj) { return i; }
         }
         return -1;
    }
}  
  (function(redirectTarget){
    var allowedOrigins = [
         'https://aaa.bbb.com',
         'https://aaa.com',
         'http://bbb.ccc.com',
         ], // which domains are allowed for redirection
        redirectMs = 3500, // how long before redirecting  
        progressMs = 500,  // how long between updates of the "progress meter"
        progressChar = '.', // progress character
        errNoAsset = 'URL not found.', // message when no asset in hash
        errInvalidAsset = 'URL not allowed.', // when asset not our domain
        progress = setInterval(function(){
          if (redirectTarget) {
            document.body.insertAdjacentHTML('beforeend',progressChar);
          } else {
            clearInterval(progress), clearTimeout(redirect);          
            document.body.insertAdjacentHTML('beforeend',errNoAsset);          
          }
        }, progressMs),
        redirect = setTimeout(function(){         
            var redirectLoc = document.createElement('a');
            redirectLoc.href = redirectTarget;
            redirectLoc.origin = redirectLoc.origin ||
                [redirectLoc.protocol,
                  '//',
                  redirectLoc.hostname, 
                  ['http:','http:80','https:','https:443']
                    .indexOf(redirectLoc.protocol+redirectLoc.port) != -1
                      ? ''
                      : ':' + redirectLoc.port
                ].join('');

            clearInterval(progress);
            if (allowedOrigins.indexOf(redirectLoc.origin) != -1) {            
              document.location.href = redirectTarget;
            } else {
              document.body.insertAdjacentHTML('beforeend',errInvalidAsset);                   
            }
        }, redirectMs);
    })(document.location.hash.substring(1));
</script>