加载和触发Target调用 load-fire-target
了解如何使用Launch规则加载参数并将参数传递到页面请求,以及从网站页面触发Target调用。 网页信息是使用Adobe客户端数据层检索并作为参数传递的,通过该数据层,您可以收集和存储有关访客在网页上的体验数据,然后轻松访问这些数据。
页面加载规则
Adobe客户端数据层是事件驱动的数据层。 加载AEM Page数据层时,它会触发一个事件 cmp:show
. 在视频中, Launch Library Loaded
使用自定义事件调用规则。 在下面,您可以找到视频中用于自定义事件和数据元素的代码片段。
自定义页面显示事件 page-event
在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属性集成的网站上引发。
数据元素
AdobeLaunch数据元素映射来自事件对象的数据 在自定义页面显示事件中触发 到Adobe Target中可用的变量(通过核心扩展的Custom Code数据元素类型)。
页面ID数据元素
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页面的标题。
疑难解答
为何mbox没有在我的网页上触发?
未设置mboxDisable 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结合使用来进行测试或简单的概念验证。 这些域以及许多其他域均包含在公共后缀列表中。
如果您使用这些域,则现代浏览器不会保存Cookie,除非您自定义 cookieDomain
使用设置 targetGlobalSettings()
.
window.targetGlobalSettings = {
cookieDomain: 'your-domain' //set the cookie directly on this subdomain, for example: 'publish-p1234-e5678.adobeaemcloud.com'
};