Adobe Experience Platform Launch已經過品牌重塑,現在是Adobe Experience Platform中的一套資料收集技術。 因此,所有產品文件中出現了幾項術語變更。 如需術語變更的彙整參考資料,請參閱以下文件。
本檔案可用作使用者端的參考 _satellite
物件以及您可以用它執行的各種功能。
track
程式碼
_satellite.track(identifier: string [, detail: *] )
範例
_satellite.track('contact_submit', { name: 'John Doe' });
track
會使用已設定核心標籤擴充功能之指定識別碼的「直接呼叫」事件型別,觸發所有規則。 上述範例會使用「直接呼叫」事件類型觸發所有規則,其中設定的識別碼為 contact_submit
。也會傳遞包含相關資訊的選用物件。您可以在條件或動作的文字欄位內輸入 %event.detail%
,或是在 Custom Code 條件或動作的程式碼編輯器內輸入 event.detail
,以存取詳細資料物件。
getVar
程式碼
_satellite.getVar(name: string) => *
範例
var product = _satellite.getVar('product');
在提供的範例中,如果資料元素存在且具有相符名稱,則會傳回資料元素的值。 如果沒有任何相符的資料元素存在,則會檢查看看是否有先前已使用 _satellite.setVar()
設定之相符名稱的自訂變數。如果找到相符自訂變數,則會傳回其值。
您可以使用百分比(%
)語法來參考標籤實作中許多表單欄位的變數,減少呼叫的需求 _satellite.getVar()
. 例如,使用 %product%
將存取產品資料元素或自訂變數的值。
當事件觸發規則時,您可以傳遞規則的對應專案 event
物件進入 _satellite.getVar()
如下所示:
// event refers to the calling rule's event
var rule = _satellite.getVar('return event rule', event);
setVar
程式碼
_satellite.setVar(name: string, value: *)
範例
_satellite.setVar('product', 'Circuit Pro');
setVar()
設定具有指定名稱和值的自訂變數。 變數的值之後可以透過 _satellite.getVar()
存取。
您可以傳遞鍵值為變數名稱且值為個別變數值的物件,選擇是否要一次設定多個變數。
_satellite.setVar({ 'product': 'Circuit Pro', 'category': 'hobby' });
getVisitorId
程式碼
_satellite.getVisitorId() => Object
範例
var visitorIdInstance = _satellite.getVisitorId();
Adobe Experience Cloud ID 如果此擴充功能已安裝在屬性上,則此方法會傳回 Visitor ID 例項。如需詳細資訊,請參閱 Experience Cloud ID 服務文件。
logger
程式碼
_satellite.logger.log(message: string)
_satellite.logger.info(message: string)
_satellite.logger.warn(message: string)
_satellite.logger.error(message: string)
範例
_satellite.logger.error('No product ID found.');
此 logger
物件允許將訊息記錄到瀏覽器主控台。 只有在使用者已啟用標籤偵錯(透過呼叫)功能時,才會顯示訊息 _satellite.setDebug(true)
或使用適當的瀏覽器擴充功能)。
_satellite.logger.deprecation(message: string)
範例
_satellite.logger.deprecation('This method is no longer supported, please use [new example] instead.');
這會將警告記錄到瀏覽器主控台。 顯示使用者是否啟用標籤偵錯的訊息。
cookie
_satellite.cookie
包含讀取和寫入Cookie的函式。 它是公開第三方程式庫js-cookie的副本。 如需此程式庫更進階用法的詳細資訊,請檢閱 js-cookie檔案.
若要設定Cookie,請使用 _satellite.cookie.set()
.
程式碼
_satellite.cookie.set(name: string, value: string[, attributes: Object])
舊版 setCookie
設定Cookie的方法中,此函式呼叫的第三個(選用)引數是整數,指出Cookie的過期時間(以天為單位)。 在這個新方法中,「attributes」物件會改為被接受為第三個引數。 若要使用新方法設定Cookie的有效期,您必須提供 expires
屬性物件中的屬性,並將其設定為所需的值。 以下範例說明此方法。
範例
以下函式呼叫所寫入的Cookie會在一週後過期。
_satellite.cookie.set('product', 'Circuit Pro', { expires: 7 });
若要擷取Cookie,請使用 _satellite.cookie.get()
.
程式碼
_satellite.cookie.get(name: string) => string
範例
以下函式呼叫會讀取先前設定的Cookie。
var product = _satellite.cookie.get('product');
若要移除Cookie,請使用 _satellite.cookie.remove()
.
程式碼
_satellite.cookie.remove(name: string)
範例
以下函式呼叫會移除先前設定的Cookie。
_satellite.cookie.remove('product');
buildInfo
程式碼
_satellite.buildInfo
此物件包含目前標籤執行階段程式庫組建的相關資訊。 此物件包含下列屬性:
turbineVersion
如此可提供 Turbine 目前程式庫內使用的版本。
turbineBuildDate
建置容器內使用的 Turbine 版本時的 ISO 8601 日期。
buildDate
建置目前程式庫時的 ISO 8601 日期。
此範例示範物件值:
{
turbineVersion: "14.0.0",
turbineBuildDate: "2016-07-01T18:10:34Z",
buildDate: "2016-03-30T16:27:10Z"
}
environment
此物件包含部署目前標籤執行階段程式庫所在環境的相關資訊。
程式碼
_satellite.environment
此物件包含下列屬性:
{
id: "ENbe322acb4fc64dfdb603254ffe98b5d3",
stage: "development"
}
屬性 | 說明 |
---|---|
id |
環境的ID。 |
stage |
建置此程式庫的環境。可能的值包括 development , staging 、和 production . |
notify
此方法已淘汰。請改用 _satellite.logger.log()
。
程式碼
_satellite.notify(message: string[, level: number])
範例
_satellite.notify('Hello world!');
notify
將訊息記錄到瀏覽器主控台。 只有在使用者已啟用標籤偵錯(透過呼叫)功能時,才會顯示訊息 _satellite.setDebug(true)
或使用適當的瀏覽器擴充功能)。
可傳遞選用的記錄層級,這會影響所記錄訊息的樣式和篩選。 支援層級如下:
3 - 資訊訊息。
4 - 警告訊息。
5 - 錯誤訊息。
如果您未提供記錄層級或傳遞任何其他層級值,訊息會記錄為一般訊息。
setCookie
此方法已淘汰。請改用 _satellite.cookie.set()
。
程式碼
_satellite.setCookie(name: string, value: string, days: number)
範例
_satellite.setCookie('product', 'Circuit Pro', 3);
這會在使用者的瀏覽器中設定Cookie。 Cookie 會持續保留到指定的天數。
readCookie
此方法已淘汰。請改用 _satellite.cookie.get()
。
程式碼
_satellite.readCookie(name: string) => string
範例
var product = _satellite.readCookie('product');
這會從使用者的瀏覽器中讀取Cookie。
removeCookie
此方法已淘汰。請改用 _satellite.cookie.remove()
。
程式碼
_satellite.removeCookie(name: string)
範例
_satellite.removeCookie('product');
這會從使用者的瀏覽器中移除Cookie。
下列函式不應從生產程式碼中存取。 這些函數適用於除錯用途,且會視需要隨時變更。
container
程式碼
_satellite._container
範例
不應從生產程式碼存取此函式。 此函數僅適用於除錯用途,且會視需求隨時變動。
monitor
程式碼
_satellite._monitors
範例
不應從生產程式碼存取此函式。 此函數僅適用於除錯用途,且會視需求隨時變動。
範例
在執行標籤庫的網頁上,將程式碼片段新增至HTML。 通常,程式碼會插入 <head>
元素之前的 <script>
載入標籤程式庫的元素。 這可讓監視器擷取標籤程式庫中發生的最早系統事件。 例如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
window._satellite = window._satellite || {};
window._satellite._monitors = window._satellite._monitors || [];
window._satellite._monitors.push({
ruleTriggered: function (event) {
console.log(
'rule triggered',
event.rule
);
},
ruleCompleted: function (event) {
console.log(
'rule completed',
event.rule
);
},
ruleConditionFailed: function (event) {
console.log(
'rule condition failed',
event.rule,
event.condition
);
}
});
</script>
<script src="//assets.adobedtm.com/launch-EN5bfa516febde4b22b3e7c6f96f6b439f.min.js"
async></script>
</head>
<body>
<h1>Click me!</h1>
</body>
</html>
在第一個指令碼元素中,由於標籤程式庫尚未載入,因此初始的 _satellite
已建立物件並在上建立陣列 _satellite._monitors
已初始化。 接著,指令碼將監視器物件新增到該陣列。監視器物件可以指定下列方法,標籤程式庫稍後會呼叫這些方法:
ruleTriggered
此函式會在事件觸發規則之後,但在處理規則的條件和動作之前呼叫。 傳遞到 ruleTriggered
的事件物件包含有關已觸發規則的資訊。
ruleCompleted
此函式會在完全處理規則後呼叫。 換言之,事件已發生、所有條件皆已傳遞,且所有動作皆已執行。 傳遞至的事件物件 ruleCompleted
包含已完成規則的相關資訊。
ruleConditionFailed
觸發規則且其中一個條件失敗後,會呼叫此函式。 已傳遞到 ruleConditionFailed
的事件物件包含有關已觸發規則和已失敗條件的資訊。
若已呼叫 ruleTriggered
,之後即將會呼叫 ruleCompleted
或 ruleConditionFailed
。
監視器不必指定所有三種方法 (ruleTriggered
、ruleCompleted
和 ruleConditionFailed
)。Adobe Experience Platform中的標籤可與監視器已提供的任何支援方法搭配使用。
以上範例在監視器中指定所有這三個方法。呼叫這些方法時,監視器會記錄相關資訊。若要對此進行測試,請在標籤程式庫中設定兩個規則:
如果您在 Chrome 中開啟頁面,請開啟瀏覽器主控台,然後選取頁面,下列內容就會顯示在主控台中:
您可視需要將其他Hook或其他資訊新增到這些處理常式。