簡體   English   中英

獲取 Intercom User_Id 並作為 javascript 變量傳遞

[英]Get Intercom User_Id and pass as javascript variable

我正在嘗試在靜態網頁上嵌入對講機小部件,然后提取用戶數據以填充 javascript 變量以動態填充頁面上的內容。 主要是我需要登錄用戶的 user_id 和 email。

誰能提供一個示例來說明如何設置 javascript 變量“userId”(然后我可以將其拉入頁面上的單獨函數)以等於對講機“user_id”的變量?

試試下面的方法。 這只是一個例子。

<script>
  #get the user id
  user_id = "<get the user id of the logged in user>";
  Intercom('boot', {  
    'app_id': 'abc12345',  
    'email': 'john.doe@example.com',
    'created_at': 1234567890,
    'name': 'John Doe',
    'user_id': user_id #user_id of the logged in user
  });
</script>

對講機 Javascript API - 鏈接

我偶然發現了同樣的問題,我也找不到任何官方對講 API 來檢索“領導”用戶的用戶 ID。 不幸的是,訪客 ID 不是很有幫助:一旦訪客轉換為潛在客戶或用戶,許多對講 API 不會接受它並返回“未找到”。 我能夠在前端檢索用戶 ID 的唯一方法是使用與對講小部件相同的內部 API:

const INTERCOM_APP_ID = 'XXXXXXXX';
const visitorId = window.Intercom('getVisitorId');
const apiResponse = await fetch('https://api-iam.intercom.io/messenger/web/ping', {
   credentials: 'include',
   method: 'POST',
   body: `app_id=${INTERCOM_APP_ID}&v=3&user_data={"anonymous_id":"${visitorId}"}`,
   headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(res => res.json())

console.log(apiResponse.user)

這將返回一個帶有用戶 ID 和一些附加信息的對象:

{
  // the intercom user ID you are looking for
  id: "6294666ff2e8e2xxxxxxxxxx",
  type: "user",
  role: "visitor_role",
  locale: "en",
  has_conversations: false,
  // the "visitor ID" (painful to deal with. use the ID above)
  anonymous_id: "2db7de4b-320c-4e4a-af30-xxxxxxxxxxxx",
  country_code: "ch",
  home_screen_slots: (2) […],
  new_session: true,
  help_center_require_search: false,
  … }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM