[整合]{class="badge positive"}

載入及觸發Target呼叫 load-fire-target

[AEM Sitesas a Cloud Service、AEM Sites 6.5]{class="badge informative"}

瞭解如何使用標籤規則,將引數載入、傳遞至頁面請求,以及從您的網站頁面觸發Target呼叫。 系統會使用Adobe使用者端資料層,擷取網頁資訊並以引數形式傳遞,此資料層可讓您收集和儲存訪客的網頁體驗相關資料,並且讓此資料易於存取。

頁面載入規則

Adobe使用者端資料層是事件導向的資料層。 載入AEM Page資料層時,會觸發事件 cmp:show . 在影片中, tags Library Loaded 使用自訂事件叫用規則。 您可以在下方找到視訊中用於自訂事件和資料元素的程式碼片段。

自訂頁面顯示事件 page-event

頁面顯示的事件設定和自訂程式碼

在tags屬性中,新增 事件規則

  • 副檔名: 核心
  • 事件型別: 自訂程式碼
  • 名稱: 頁面顯示事件處理常式(或描述性內容)

點選 開啟編輯器 按鈕,並貼入下列程式碼片段。 此程式碼 必須 已新增至 事件設定 和後續的 動作.

// Define the event handler function
var pageShownEventHandler = function(coreComponentEvent) {

    // Check to ensure event trigger via AEM Core Components is shaped correctly
    if (coreComponentEvent.hasOwnProperty("eventInfo") &&
        coreComponentEvent.eventInfo.hasOwnProperty("path")) {

        // Debug the AEM Component path the show event is associated with
        console.debug("cmp:show event: " + coreComponentEvent.eventInfo.path);

        // Create the tags Event object
        var launchEvent = {
            // Include the ID of the AEM Component that triggered the event
            id: coreComponentEvent.eventInfo.path,
            // Get the state of the AEM Component that triggered the event
            component: window.adobeDataLayer.getState(coreComponentEvent.eventInfo.path)
        };

        // Trigger the tags Rule, passing in the new `event` object
        // the `event` obj can now be referenced by the reserved name `event` by other tags data elements
        // i.e `event.component['someKey']`
        trigger(launchEvent);
   }
}

// With the AEM Core Component event handler, that proxies the event and relevant information to Data Collection, defined above...

// Initialize the adobeDataLayer global object in a safe way
window.adobeDataLayer = window.adobeDataLayer || [];

// Push the event custom listener onto the Adobe Data Layer
window.adobeDataLayer.push(function (dataLayer) {
   // Add event listener for the `cmp:show` event, and the custom `pageShownEventHandler` function as the callback
   dataLayer.addEventListener("cmp:show", pageShownEventHandler);
});

自訂函式會定義 pageShownEventHandler,會偵聽AEM核心元件發出的事件、衍生核心元件的相關資訊、將其封裝為事件物件,並在其裝載處以衍生的事件資訊觸發標籤事件。

使用標籤的 trigger(...) 函式: 僅限 可從規則事件的自訂程式碼片段定義中使用。

trigger(...) 函式會將事件物件視為引數,該引數又會以標籤中另一個保留名稱在標籤中公開,命名為 event. 標籤中的資料元素現在可以從參照此事件物件的資料 event 物件,使用類似以下的語法 event.component['someKey'].

如果 trigger(...) 在事件的自訂程式碼事件型別內容之外使用(例如,在動作中),即JavaScript錯誤 trigger is undefined 在與tags屬性整合的網站上擲回。

資料元素

資料元素

標籤資料元素會對應來自事件物件的資料 在自訂頁面顯示事件中觸發 至可在Adobe Target中取得的變數,透過核心擴充功能的自訂程式碼資料元素型別。

頁面ID資料元素

if (event && event.id) {
    return event.id;
}

此程式碼會傳回核心元件的產生唯一ID。

頁面ID

頁面路徑資料元素

if (event && event.component && event.component.hasOwnProperty('repo:path')) {
    return event.component['repo:path'];
}

此程式碼會傳回AEM頁面的路徑。

頁面路徑

頁面標題資料元素

if (event && event.component && event.component.hasOwnProperty('dc:title')) {
    return event.component['dc:title'];
}

此程式碼會傳回AEM頁面的標題。

頁面標題

疑難排解

為何mbox沒有在我的網頁上觸發?

未設定mboxDisable Cookie時的錯誤訊息

Target Cookie網域錯誤

> AT: [page-init] Adobe Target content delivery is disabled. Ensure that you can save cookies to your current domain, there is no "mboxDisable" cookie and there is no "mboxDisable" parameter in the query string.

解決方案

客戶有時使用雲端型例項搭配Target進行Target測試或簡單的概念證明用途。 這些網域和許多其他網域均屬於公用字尾清單。
如果您使用這些網域,則現代瀏覽器不會儲存Cookie,除非您自訂 cookieDomain 設定,使用 targetGlobalSettings().

window.targetGlobalSettings = {
   cookieDomain: 'your-domain' //set the cookie directly on this subdomain, for example: 'publish-p1234-e5678.adobeaemcloud.com'
};

後續步驟

支援連結

recommendation-more-help
bb44cebf-d964-4e3c-b64e-ce882243fe4d