2017-03-02 68 views
0

我們想要一種方式來跟蹤通過未通過Marketo發送的郵件來點擊PDF鏈接的潛在客戶。我們也不希望打開PDF文件(要求我們的客戶填寫表格)來訪問文件。在談到支持和淘汰Marketo四維支持網站之後,我瞭解到(我認爲)實現這一目標的唯一方法是製作REST API調用,並嘗試從PC上的cookie文件獲取主要信息(將會訪問我們的PDF是已知的客戶,而不是普通大衆)我不是專家的編碼員,所以我從我的研究中修補了這段代碼,足以說它不工作,任何幫助將不勝感激。根據Marketo Cookie提供的潛在客戶信息自動填充Marketo表單字段

<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.我替換和值,一旦我粘貼在瀏覽器中的鏈接,我得到了一個成功的結果。

回答

0

您將無法以這種方式使用REST API,因爲它要求您每次都生成一個新的訪問令牌,並且更麻煩,將它公開在客戶端。 我能想到的唯一選擇是使用重定向鏈接到marketo登陸頁面。 您將創建一個空着陸頁並插入以下代碼,該代碼將簡單重定向到您的PDF。

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

這項活動將被記錄在活動日誌已知線索和

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> 
+0

任何人都知道如何將一個條件添加到代碼後,刪除任何東西「?」在一個鏈接? – Rayyis

相關問題