Affise Web SDK 是一款功能强大且符合隐私保护规范的追踪解决方案,它能直接从追踪链接参数中捕获数据,并通过像素进行处理。该 SDK 无需依赖面临日益严格浏览器限制的第三方 Cookie,即可无缝生成点击和转化数据,在确保用户隐私不受侵害的同时,实现精准追踪。
🔎 您可在此处进一步了解集成类型。
Affise Web SDK
Affise Web SDK 可与 Affise 平台无缝集成,无需通过第三方追踪系统重定向即可追踪用户互动。
主要功能:
无需重定向用户即可在客户端生成点击
支持产品数据源的转化跟踪
多种存储机制,并针对浏览器限制提供备用方案
内置 polyfill 实现跨浏览器兼容
存储机制
该 SDK 采用多种存储机制并提供备用方案:
Cookies(主要存储)
localStorage(次要存储)
sessionStorage(备用方案)
如果一种机制失败,SDK 将自动尝试下一种。
浏览器兼容性
该 SDK 包含现代 JavaScript 功能的 polyfill,确保与以下浏览器兼容:
Chrome 45 及以上版本
Firefox 38+
Safari 9 及以上
Edge 12 及以上
Internet Explorer 11
安全注意事项
SDK 将数据保存在 Cookie 和浏览器存储中,但浏览器有控制其运作方式的规则。
大多数浏览器会阻止第三方 Cookie,因此跨不同网站追踪用户可能无法完美运行。
即使浏览器阻止了某些功能,SDK 也会尝试采用不同的方法来保存数据。
如果浏览器的隐私设置非常严格,您可能需要使用服务器端跟踪以获得更好的效果。
🔎 现在,您可以使用我们的 WebSDK 并通过域名 https://trk.affattr.com 在 Google Ads 上启动广告活动,该域名已在广告审核中成功通过。
要实现此功能,只需在代码中包含以下配置:
<script src="https://trk.affattr.com/websdk.js"></script> - Standard integration, but with a dedicated domain
<script>
// Configure the SDK TO WORK WITH GOOGLE TRANSPARENCY DOMAIN
ASDK.configure({
use_google_transparency: true, <--- Required when using https://trk.affattr.com
client_id: 2, <--- Required when using https://trk.affattr.com
tracking_domain: "https://trk.affattr.com" <--- Must be manually specified; otherwise, it won't work
});
</script>
每个客户都有唯一的 client_id。如需获取,请联系支持团队或您的客户经理。
基本设置
使用前请使用广告方案中的跟踪域名配置 SDK(可能是默认或自定义的):
<!-- Load the SDK --> <script src="https://{your-tracking-domain}/websdk.js"></script>点击追踪
click() 方法可在不重定向用户的情况下生成点击事件,非常适合着陆页:
// Basic click tracking
ASDK.click({
offer_id: 'OFFER123', // Required
affiliate_id: 'AFF456' // Required
})
.then(clickId => {
console.log('Click tracked successfully:', clickId);
})
.catch(error => {
console.error('Error tracking click:', error);
});
转化跟踪
该 conversion() 该方法用于跟踪用户完成预期操作(购买、注册等)的情况:
// Basic conversion tracking using click ID
ASDK.conversion({
click_id: ASDK.clickId('OFFER123'), // Get the stored click ID for this offer
offer_id: 'OFFER123',
status: '1', // 1 = confirmed
sum: '99.99'
})
.then(() => {
console.log('Conversion tracked successfully');
})
.catch(error => {
console.error('Error tracking conversion:', error);
});
// Alternative: conversion tracking using promo code
ASDK.conversion({
promo_code: 'SUMMER20',
offer_id: 'OFFER123',
status: '1',
sum: '99.99'
})
.then(() => {
console.log('Conversion tracked successfully');
})
.catch(error => {
console.error('Error tracking conversion:', error);
});
集成示例
电子商务着陆页:
document.addEventListener('DOMContentLoaded', function() {
// 1. Get tracking parameters from URL
const offerId = ASDK.urlParameter('offer_id') || 'DEFAULT_OFFER';
const affiliateId = ASDK.urlParameter('aff_id') || 'DEFAULT_AFFILIATE';
// 2. Generate a click
ASDK.click({
offer_id: offerId,
affiliate_id: affiliateId,
user_agent: navigator.userAgent
})
.then(clickId => {
console.log('Tracking initialized:', clickId);
})
.catch(error => {
console.error('Tracking error:', error.message);
});
});
电商结账/感谢页面:
document.addEventListener('DOMContentLoaded', function() {
// 1. Get order information
const orderDetails = {
id: 'ORD-12345',
total: 149.99,
currency: 'USD',
products: [
{ id: 'SKU001', name: 'Product 1', price: 99.99, quantity: 1 },
{ id: 'SKU002', name: 'Product 2', price: 24.99, quantity: 2 }
]
};
// 2. Get the offer ID and click ID
const offerId = ASDK.urlParameter('offer_id') || 'DEFAULT_OFFER';
const clickId = ASDK.clickId(offerId);
// 3. Track the conversion with product feed
ASDK.conversion({
click_id: clickId,
offer_id: offerId,
status: '1', // 1 = confirmed
sum: orderDetails.total.toString(),
order_currency: orderDetails.currency,
comment: `Order ${orderDetails.id}`,
items: orderDetails.products.map(product => ({
order_id: orderDetails.id,
sku: product.id,
quantity: product.quantity.toString(),
price: product.price.toString()
}))
})
.then(() => {
console.log('Conversion tracked successfully');
})
.catch(error => {
console.error('Error tracking conversion:', error);
});
});错误处理
ASDK.click({
offer_id: 'OFFER123',
affiliate_id: 'AFF456'
})
.then(clickId => {
console.log('Click tracked successfully:', clickId);
})
.catch(error => {
// Handle specific error types
switch(error.code) {
case 'NETWORK_ERROR':
console.error('Network unavailable:', error.message);
// Retry logic or offline handling
break;
case 'SERVER_ERROR':
console.error('Server error:', error.details.status);
// Log to your monitoring system
break;
case 'MISSING_REQUIRED_PARAMS':
console.error('Missing parameters:', error.details.provided);
// Show feedback about missing data
break;
default:
console.error('Error tracking click:', error.message);
}
});
API 参考
配置选项
参数 | 类型 | 描述 |
tracking_domain | 字符串 | 用于跟踪点击和转化的域名 |
点击方法参数
该 click() 方法接受一个包含以下参数的选项对象:
必填参数
参数 | 类型 | 描述 | API 参数 |
offer_id | 字符串 | 必填。优惠的标识符 | offer_id |
affiliate_id | 字符串 | 必填。联盟成员的标识符 | pid |
可选参数
参数 | 类型 | 描述 | API 参数 |
tracking_domain | 字符串 | 覆盖默认跟踪域名 | - |
ip | 字符串 | 用户的 IP 地址 | ip |
user_agent | 字符串 | 用户的浏览器用户代理字符串 | ua |
ref_id | 字符串 | 引用 ID | ref_id |
ref_android_id | 字符串 | Android 参考 ID | ref_android_id |
ref_device_id | 字符串 | 设备引用 ID | ref_device_id |
mac_address | 字符串 | MAC 地址 | mac_address |
os_id | 字符串 | 操作系统 ID | os_id |
user_id | 字符串 | 用户 ID | user_id |
ext1 | 字符串 | 额外参数 1 | ext1 |
ext2 | 字符串 | 额外参数 2 | ext2 |
ext3 | 字符串 | 额外参数 3 | ext3 |
imp_id | 字符串 | 展示 ID | imp_id |
unid | 字符串 | 唯一标识符 | unid |
fbclid | 字符串 | Facebook 点击 ID | fbclid |
landing_id | 字符串 | 着陆页 ID | l |
sub1 | 字符串 | 自定义子参数 1 | sub1 |
sub2 | 字符串 | 自定义子参数 2 | sub2 |
sub3 | 字符串 | 自定义子参数 3 | sub3 |
sub4 | 字符串 | 自定义子参数 4 | sub4 |
sub5 | 字符串 | 自定义子参数 5 | sub5
|
注意:sub6 至 sub30 也支持相同的模式。
转换方法参数
该 conversion() 方法接受一个包含以下参数的选项对象:
必填参数
参数 | 类型 | 描述 | API 参数 |
click_id | 字符串 | 点击 ID(通过 SDK 获取) | afclick |
promo_code | 字符串 | 促销代码(click_id 的替代方案) | promo_code |
注意:必须提供其中一个参数。
可选参数
参数 | 类型 | 描述 | API 参数 |
tracking_domain | 字符串 | 覆盖默认跟踪域名 | - |
offer_id | 字符串 | 优惠的标识符 | offer_id |
status | 字符串 | 转化状态(参见下方的状态代码) | afstatus |
secure | 字符串 | 用于回发验证的安全令牌 | afsecure |
comment | 字符串 | 关于转换的附加注释 | afcomment |
action_id | 字符串 | 外部转换 ID | afid |
sum | 字符串 | 转换金额 | afprice |
goal | 字符串 | 转换目标标识符 | afgoal |
order_sum | 字符串 | 订单总额(用于更新) | order_sum |
order_currency | 字符串 | 订单货币 | order_currency |
user_id | 字符串 | 用户标识符 | user_id |
custom_field1 | 字符串 | 自定义字段 1 | custom_field1 |
custom_field2 | 字符串 | 自定义字段 2 | custom_field2 |
custom_field3 | 字符串 | 自定义字段 3 | custom_field3 |
custom_field4 | 字符串 | 自定义字段 4 | custom_field4 |
custom_field5 | 字符串 | 自定义字段 5 | custom_field5 |
注意:custom_field6 至 custom_field15 也支持相同的模式。
状态代码
值 | 描述 |
1 | 已确认 |
2 | 待处理 |
3 | 已拒绝 |
5 | 暂存 |
产品数据源条目格式
数组中的每个项目 items 数组中的每个项目应是一个具有以下属性的对象:
{ order_id: string, // Order identifier sku: string, // Product SKU quantity: string, // Product quantity price: string // Product price }
辅助方法
方法 | 描述 |
ASDK.urlParameter(name) | 根据名称获取 URL 参数的值 |
ASDK.clickId(offerId) | 获取特定广告活动 ID 的存储点击 ID |
常见问题及解决方案
未生成点击
未返回点击 ID,Promise 被拒绝。
解决方案:
验证必填参数
offer_id且affiliate_id是否已提供。检查跟踪域是否配置正确。
验证与跟踪域的网络连接。
检查浏览器控制台是否有具体的错误消息。
点击 ID 未存储
点击后已生成,但在使用时不可用 ASDK.clickId().
解决方案:
检查浏览器是否阻止了 Cookie。
确认您的域名未处于无痕/隐私模式。
确保点击和检索时的优惠 ID 一致。
未追踪到转化
转化流程已完成,但仪表盘中未显示转化。
解决方案:
请确认您提供的
click_id或promo_code.检查点击 ID 是否与原始点击的 ID 匹配。
确保
offer_id与点击时使用的 ID 一致。请确认状态码是否正确(确认状态请使用“1”)。
如有任何疑问,请通过电子邮件 [email protected] 联系 Affise 客户支持团队。
