了解如何使用Launch规则从网站页面加载、将参数传递到页面请求和触发Target调用。 网页信息是使用Adobe客户端数据层检索并作为参数传递的,通过该数据层,您可以收集和存储有关访客在网页上的体验数据,然后轻松访问这些数据。
Adobe客户端数据层是一个事件驱动的数据层。 加载AEM Page数据层时,将触发一个事件 cmp:show
. 在视频中, Launch Library Loaded
使用自定义事件调用规则。 在下面,您可以找到视频中用于自定义事件和数据元素的代码片段。
在Launch资产中,添加新的 事件 到 规则
点按 打开编辑器 按钮并粘贴以下代码片段。 此代码 必须 已添加到 事件配置 和后续的 操作.
// 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规则是使用Launch的 trigger(...)
函数为 仅限 可从规则事件的Custom Code代码段定义中获取。
此 trigger(...)
函数将事件对象作为参数,该参数依次在Launch数据元素中公开,并使用Launch中另一个名为的保留名称 event
. Launch中的数据元素现在可以从以下位置引用此事件对象中的数据: event
对象使用语法,如 event.component['someKey']
.
如果 trigger(...)
在事件的Custom Code事件类型的上下文(例如,在操作中)之外使用,表示JavaScript错误 trigger is undefined
在与Launch属性集成的网站上引发。
Adobe启动数据元素映射来自事件对象的数据 在自定义页面显示事件中触发 到Adobe Target中可用的变量(通过核心扩展的Custom Code Data Element Type)。
if (event && event.id) {
return event.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页面的标题。
> 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'
};