此文档用作客户端_satellite
对象(也称为Adobe Experience Platform Launch对象)的引用,以及您可以使用它执行的各种函数。
track
代码
_satellite.track(identifier: string [, detail: *] )
示例
_satellite.track('contact_submit', { name: 'John Doe' });
使用配置了给定标识符的核心扩展中的“直接调用”事件类型触发所有规则。以上示例使用“直接调用”事件类型触发所有规则,其中配置的标识符为 contact_submit
。此外,还会传递包含相关信息的可选对象。可以通过在条件或操作的文本字段中输入 %event.detail%
或者在“自定义代码”条件或操作的代码编辑器中输入 event.detail
来访问详细信息对象。
getVar
代码
_satellite.getVar(name: string) => *
示例
var product = _satellite.getVar('product');
如果存在具有匹配名称的数据元素,则将返回数据元素的值。如果不存在匹配的数据元素,则将检查以前是否使用 _satellite.setVar()
设置了具有匹配名称的自定义变量。如果找到匹配的自定义变量,则将返回其值。
请注意,在 Platform Launch 用户界面的许多表单字段中,您可以使用 %%
语法来引用变量,从而无需调用 _satellite.getVar()
。例如,使用 %product% 将访问产品数据元素或自定义变量的值。
setVar
代码
_satellite.setVar(name: string, value: *)
示例
_satellite.setVar('product', 'Circuit Pro');
设置具有给定名称和值的自定义变量。之后可以使用 _satellite.getVar()
访问该变量的值。
您可以选择一次设置多个变量,方法是传递一个对象,其中键是变量名称,值是各自的变量值。
_satellite.setVar({ 'product': 'Circuit Pro', 'category': 'hobby' });
getVisitorId
代码
_satellite.getVisitorId() => Object
示例
var visitorIdInstance = _satellite.getVisitorId();
如果资产上安装了 Adobe Experience Cloud ID 扩展,此方法将返回访客 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.');
将消息记录到浏览器控制台。仅当用户启用了 Platform Launch 调试(通过调用 _satellite.setDebug(true)
或使用适当的浏览器扩展)时,才会显示该消息。
_satellite.logger.deprecation(message: string)
示例
_satellite.logger.deprecation('This method is no longer supported, plese use [new example] instead.');
将警告记录到浏览器控制台。 无论用户是否启用Platform Launch调试,都将显示消息。
cookie
代码
_satellite.cookie.set(name: string, value: string[, attributes: Object])
_satellite.cookie.get(name: string) => string
_satellite.cookie.remove(name: string)
示例
// Writing a cookie that expires in one week.
_satellite.cookie.set('product', 'Circuit Pro', { expires: 7 });
// Reading a previously set cookie.
var product = _satellite.cookie.get('product');
// Removing a previously set cookie.
_satellite.cookie.remove('product');
用于读取和写入 Cookie 的实用程序。这是第三方库 js-cookie 的公开副本。有关更高级的使用,请查阅 js-cookie 使用文档(外部链接)。
buildInfo
代码
_satellite.buildInfo
此对象包含有关当前 Platform Launch 运行时库的生成信息。该对象包含以下属性:
turbineVersion
当前库中使用的 Turbine 版本。
turbineBuildDate
生成容器内使用的 Turbine 版本的 ISO 8601 日期。
buildDate
生成当前库的 ISO 8601 日期。
environment
生成此库的环境。可能的值包括:
以下示例展示了对象值:
{
turbineVersion: "14.0.0",
turbineBuildDate: "2016-07-01T18:10:34Z",
buildDate: "2016-03-30T16:27:10Z",
environment: "development"
}
notify
此方法已弃用。请改用 _satellite.logger.log()
。
代码
_satellite.notify(message: string[, level: number])
示例
_satellite.notify('Hello world!');
将消息记录到浏览器控制台。仅当用户启用了 Platform Launch 调试(通过调用 _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
示例
不应从生产代码访问此函数。此函数仅用于调试目的,并将根据需要随时间发生更改。
样例
在运行 Platform Launch 库的网页上,向 HTML 中添加一个代码片段。通常,代码会放置在加载 Platform Launch 库的 <script>
标记之前的 <head>
标记中。这允许监视器捕获 Platform Launch 库中最早发生的系统事件。例如:
<!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>
在第一个脚本标记中,由于尚未加载 Platform Launch 库,因此创建了初始 _satellite
对象,并对 _satellite._monitors
上的数组进行了初始化。然后,此脚本将一个监视器对象添加到该数组。该监视器对象可以指定以下方法,Platform Launch 库稍后将调用这些方法:
ruleTriggered
在事件触发规则之后,但在处理规则的条件和操作之前调用。传递给 ruleTriggered
的事件对象包含有关已触发的规则的信息。
ruleCompleted
在规则完全处理之后调用。换句话说,在事件已经发生,所有条件都已传递,并且所有操作都已执行之后调用。传递给 ruleCompleted
的事件对象包含有关已完成的规则的信息。
ruleConditionFailed
在触发规则并且其中一个条件失败之后调用。传递给 ruleConditionFailed
的事件对象包含有关已触发的规则和失败的条件的信息。
如果调用 ruleTriggered
,则此后不久将调用 ruleCompleted
或 ruleConditionFailed
。
监视器不必指定所有三种方法(ruleTriggered
、ruleCompleted
和 ruleConditionFailed
)。Platform Launch 可与监视器提供的任何受支持的方法配合使用。
上面的示例在监视器中指定了所有三种方法。当这些方法被调用时,监视器会记录相关信息。要测试此监视器,请在 Platform Launch 库中设置以下两个规则:
如果您在 Chrome 中打开页面,打开浏览器控制台,然后选择该页面,则控制台中会显示以下内容:
可以根据需要向这些处理程序中添加其他挂接或附加信息。