加载和触发Target调用

了解如何加载参数并将参数传递到页面请求,以及如何使用Launch规则从您的网站页面触发Target调用。 使用Adobe客户端数据层可检索网页信息并将其作为参数进行传递,该数据层允许您收集和存储有关访客在网页上的体验的数据,然后使访客能够轻松访问这些数据。

页面加载规则

Adobe客户端数据层是事件驱动的数据层。 加载AEM页面数据层时,将触发事件cmp:show 。 在视频中,使用自定义事件调用Launch Library Loaded规则。 在下面,您可以找到视频中用于自定义事件和数据元素的代码片段。

自定义页面显示事件

页面显示的事件配置和自定义代码

在Launch属性中,将新的​Event​添加到​Rule​中

  • 扩展: 核心
  • 事件类型: 自定义代码
  • 名称: 页面显示事件处理程序(或某些描述性内容)

点按​打开编辑器​按钮,然后在以下代码片段中粘贴。 此代码​必须​添加到​事件配置​和后续的​操作​中。

// 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 Launch 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 Launch Rule, passing in the new `event` object
        // the `event` obj can now be referenced by the reserved name `event` by other Launch data elements
        // i.e `event.component['someKey']`
        trigger(launchEvent);
   }
}

// With the AEM Core Component event handler, that proxies the event and relevant information to Adobe Launch, 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核心组件发出的事件,导出核心组件的相关信息,将其打包到事件对象中,并在有效负荷时使用派生事件信息触发启动事件。

Launch规则使用Launch的trigger(...)函数触发,该函数​​可从规则事件的自定义代码片段定义中获取。

trigger(...)函数将事件对象作为参数,该参数又在Launch数据元素中以名为event的其他保留名称显示。 Launch中的数据元素现在可以使用event.component['someKey']之类的语法来引用event对象中此事件对象的数据。

如果在事件的“自定义代码”事件类型(例如,在操作中)的上下文之外使用trigger(...),则在与Launch属性集成的网站上会引发JavaScript错误trigger is undefined

数据元素

数据元素

AdobeLaunch数据元素通过核心扩展的自定义代码数据元素类型,将在自定义显示页面事件🔗中触发的事件对象的数据映射到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结合使用来进行测试或简单的概念验证。 这些域以及许多其他域都是公共后缀列表的一部分。
除非使用targetGlobalSettings()自定义cookieDomain设置,否则在使用这些域时,新式浏览器将不会保存Cookie。

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

后续步骤

支持链接

在此页面上