Tapferry/文档

入门

初次使用 Tapferry?请先查看以下问题。如需了解更详细的行为,请参阅下方的 REST API 和 SDK 指南。

Tapferry 是什么样的服务?

Tapferry 是一套深度链接/归因基础设施,它将来自您的应用、网页和广告推广活动的每一次点击整合为一个短链接,并追踪该链接在哪里被点击、哪位用户随后安装了应用并在应用内完成支付。

它在一处同时提供:Android App Links 与 iOS Universal Links 域名验证文件的自动托管、面向未安装应用用户的延迟深度链接,以及覆盖点击 → 安装 → 支付全流程的归因。

与现有的短网址服务(如 bit.ly)有什么不同?

短网址服务只决定点击“跳转到哪里”。Tapferry 还会自动完成以下工作。

  • 按操作系统 / 浏览器分流(iOS · Android · Web)
  • 将已安装应用的用户引导至应用,未安装的用户引导至应用商店
  • 延迟深度链接:安装后首次启动时,将用户带到原本预定的页面
  • 归因:匹配点击 · 安装 · 支付,并按广告渠道 / 推广活动汇总
支持哪些平台?

我们提供 6 个官方 SDK。所有功能也都可以仅通过 REST API 使用。

  • Android — Gradle 坐标 com.vialink:sdk
  • iOS — SPM 产品 ViaLinkCore
  • Web — npm vialink-web-sdk
  • React Native — npm vialink-react-native-sdk
  • Unity — UPM(通过 GitHub URL 安装)
  • Flutter — pub.dev vialink_flutter_plugin
如何注册并添加第一个应用?

在控制台注册并添加应用后,系统会立即为您签发 apiKey 和 apiSecret。之后只需将密钥填入 SDK 指南中的初始化代码,即可立即开始集成。

API 密钥 / 认证

在哪里获取 API 密钥?

您可以在控制台的 应用 → SDK 标签页中找到。创建应用时会自动签发,无需另行申请。

API 密钥和 API Secret 有什么区别?

API 密钥 是在 SDK 和客户端中使用的公开标识符,而 API Secret 是仅用于服务器到服务器(S2S)调用的私钥。切勿在客户端(应用/网页)代码中包含 Secret。

这一点也体现在存储方式上:Key 以明文(UUID)存储,而 Secret 以 bcrypt 哈希存储,因此即使是服务器也无法查看原始值。

哪些端点需要 Secret?

只有以下两个 S2S 端点需要 Secret。

  • POST /v1/payments/succeeded
  • POST /v1/payments/failed

其他所有 SDK 调用(/v1/resolve、/v1/deferred-match、/v1/events、/v1/payments/initiated 等)仅需 X-API-Key 即可工作。

密钥泄露了,如何重新签发?

您可以在控制台 SDK 标签页中通过 重新签发 API Secret 按钮立即重新签发。

注意: 没有宽限期。重新签发的瞬间原有 Secret 即失效,在新的 Secret 部署到服务器之前,仍使用原有 Secret 的请求都会失败。如果您有正在生产环境运行的服务器,请在流量较低的时段重新签发,并立即将新的 Secret 部署到服务器。

API 密钥是按账户还是按应用分配?

按应用(租户)分配。一个账户可以创建多个应用,每个应用都会签发各自独立的 Key / Secret。

认证请求头名称区分大小写吗?

HTTP 请求头不区分大小写。X-API-Key 和 x-api-key 都能被正确识别。

SDK 集成

App Links / Universal Links 的域名验证文件需要自己托管吗?

不需要,您无需自行托管。Bridge Server 会自动托管这两个文件。

  • Android — GET /.well-known/assetlinks.json。根据已注册的包名(Play Store · ONE Store)和 SHA-256 指纹动态生成
  • iOS — GET /.well-known/apple-app-site-association。根据 Bundle ID · Team ID · slug 动态生成

只需在控制台的应用设置中注册 Bundle ID / SHA-256,即可自动生效。

/v1/resolve 和 /v1/deferred-match 有什么区别?
  • POST /v1/resolve — 当应用通过 App Links / Universal Links 被直接打开时,按 short code 立即查询链接数据(优先使用 Redis 缓存)
  • POST /v1/deferred-match — 在应用首次启动时,通过支持的匹配方式关联此前的点击上下文(延迟深度链接)。能否匹配取决于可用的链接上下文(例如确定性令牌、Apple 提供的归因框架)。

只要按照 SDK 集成指南中的标准流程操作,这两个调用都会自动处理。

如何记录事件?
  • POST /v1/events — 单个事件
  • POST /v1/events/batch — 批量事件,每次请求最多 100 条(适用于离线排队)

服务器不会按固定标准单独校验事件名称。您可以自由定义 signup、purchase、app.open 等任何所需的名称。

支付 / 归因

支付归因的流程是怎样的?
  • SDK 通过 POST /v1/payments/initiated(X-API-Key)发送支付尝试
  • 您的后端收到 PG(支付网关)回调后,调用 POST /v1/payments/succeeded 或 /failed(X-API-Key + X-API-Secret)
  • 匹配在终态调用时同步进行,结果会立即记录到 payment_events 表的 attributed_* 列中

由于这不是异步批处理任务,您可以直接在调用的响应中看到归因结果。

使用哪种归因模型?

我们采用 最终点击(last_click)模型。同一设备上最近的一次点击将获得归因。

归因窗口的默认值是多少?
  • 点击 → 安装匹配:7 天(attribution.click_to_install_days)
  • 安装 → 支付匹配:30 天(attribution.install_to_purchase_days)
  • initiated → succeeded/failed 匹配:24 小时(attribution.initiated_to_succeeded_hours)

这三个值都可以在管理后台的系统设置中调整。详细伪代码请参阅下方的归因策略部分。

匹配失败会怎样?

调用仍会返回 200,但 attributed.method 会被记录为以下值之一。

  • no_initiated_or_no_device — 没有 initiated 调用,或缺少 device_id
  • no_install_in_window — 窗口期内同一设备没有 app.install 事件
  • organic_install — 已捕获安装,但属于没有 link_id 的自然安装
  • last_click_install_only — 安装已匹配,但没有点击事件
  • error — DB 查询失败(会发送 Telegram 告警)

各情况的含义及匹配步骤,请参阅归因策略部分中的伪代码。

套餐 / 运营

有哪些套餐?

共有 6 种套餐。

  • Free
  • Plus
  • Premium
  • Pro
  • Ultra
  • Enterprise

您可以在控制台的套餐页面查看各套餐的每月额度、API 调用次数、应用数量和深度链接数量上限,以及可用功能(customDomain、customLanding、teamInvite、paymentTracking、customEvent)。

在哪里查看分析数据?

您可以在控制台的 应用 → 分析 页面查看点击、安装、各平台及各推广活动的统计数据。

认证

查询、创建链接以及支付尝试上报(/v1/payments/initiated,由 SDK 调用)仅需 X-API-Key 请求头认证。更新、删除链接以及 S2S 调用(/v1/payments/succeeded、/v1/payments/failed、/v1/conversions)需要同时发送 X-API-Key 和 X-API-Secret,Secret 仅可在后端使用。在控制台中注册应用后即会签发 API Key 和 Secret。

请求头

代码已复制到剪贴板
X-API-Key: <your_api_key>
X-API-Secret: <your_api_secret>   # update/delete/S2S only (backend)

Base URL

所有 API 请求的基础 URL。

代码已复制到剪贴板
https://tapferry.com

检查短码

GET/api/links/check-short-code

在创建链接前实时检查 customCode 是否可用。认证:需要会话 Cookie 以及该租户的 ADMIN 及以上角色。

查询参数

tenantIdstring必填
应用(租户)ID
codestring必填
要检查是否重复的短码字符串

请求示例

代码已复制到剪贴板
GET /api/links/check-short-code?tenantId=tenant_abc&code=summer-sale-2026

响应(200 OK — 可用)

代码已复制到剪贴板
{
  "available": true
}

响应(200 OK — 已被使用)

代码已复制到剪贴板
{
  "available": false,
  "reason": "This short code is already in use."
}

短码政策

  • · 自动生成:Base36 小写(a–z、0–9),6 个字符。(由原来的大小写混合 Base62 变更而来。)
  • · 自定义:/^[a-z0-9_-]{3,24}$/ — 小写字母、数字、连字符、下划线,3–24 个字符。
  • · 不区分大小写的路由:tapferry.com/\{slug\}/PTMLWT 和 tapferry.com/\{slug\}/ptmlwt 匹配同一个链接。

支付发起(SDK)

POST/v1/payments/initiated

用户打开支付页面时 SDK 调用的端点。即使使用相同的 order_id 多次调用,也会每次新建一行(用于追踪卡信息输错等重试情况)。此阶段不进行匹配,匹配会在之后调用 /v1/payments/succeeded 时同步执行。

请求头

代码已复制到剪贴板
X-Api-Key: <your_api_key>
Content-Type: application/json

请求参数

order_idstring必填
订单标识。1–100 个字符,允许字母/数字/连字符/下划线(^[A-Za-z0-9_-]{1,100}$)。
amountnumber必填
支付金额。大于 0 的数字。以该币种自身的单位表示(例:KRW = 韩元,USD = 美元)。
currencystring必填
ISO 4217 币种代码(大写)。仅允许 SystemConfig 中 payments.allowed_currencies 已登记的值。
link_idnumber可选
与支付直接关联的链接 ID。归因会通过基于 device_id 的安装/点击追踪另行进行。
payment_methodstring可选
支付方式(card / transfer / kakaopay 等)。最多保存 50 个字符。
device_infoobject可选
设备信息。由 SDK 自动采集(device_id、country 等)。用于归因匹配。
metadataobject可选
自由格式的附加数据。按 JSON 对象原样保存。

请求示例

代码已复制到剪贴板
POST /v1/payments/initiated
X-Api-Key: <your_api_key>
Content-Type: application/json

{
  "order_id": "ORD-2026-0001",
  "amount": 19900,
  "currency": "KRW",
  "payment_method": "card",
  "device_info": { "device_id": "abc-123", "country": "KR" },
  "metadata": { "product_id": "prod-001" }
}

响应(200 OK)

代码已复制到剪贴板
{
  "success": true,
  "payment_event_id": "9876543210"
}

错误响应

400Bad Request可选
输入格式错误。例:{ "error": "order_id is invalid (1-100 chars, alphanumeric/-/_)." }
401Unauthorized可选
缺少请求头。{ "error": "API key is required." }
403Forbidden可选
API Key 无效或租户未启用。{ "error": "Invalid API key." }
500Server Error可选
服务器内部错误。{ "error": "An internal server error occurred." }

支付成功(S2S)

POST/v1/payments/succeeded

客户后端收到 PG 回调后调用的服务器到服务器(Server-to-Server)端点。匹配流程同步执行,因此响应中包含 attributed 对象。请勿从 SDK 直接调用(会暴露 apiSecret)。

请求头

代码已复制到剪贴板
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/json

apiSecret 以 bcrypt 哈希形式存储在数据库中,并通过 bcrypt.compare 而非明文比较进行验证。认证失败统一返回 "Authentication failed." 这一条消息,不会透露在哪个阶段失败(apiKey 是否存在 / apiSecret 是否匹配 / 租户是否启用)。

请求参数

order_idstring必填
与 initiated 阶段相同的订单标识。1–100 个字符,字母/数字/连字符/下划线。
amountnumber必填
实际支付金额。大于 0 的数字。
currencystring必填
ISO 4217 币种代码(大写)。
transaction_idstring可选
PG 交易号。最多保存 200 个字符。
payment_methodstring可选
支付方式。最多保存 50 个字符。
metadataobject可选
自由格式的附加数据。JSON 对象。

请求示例

代码已复制到剪贴板
curl -X POST https://tapferry.com/v1/payments/succeeded \
  -H "X-Api-Key: <your_api_key>" \
  -H "X-Api-Secret: <your_api_secret>" \
  -H "Content-Type: application/json" \
  -d '{
    "order_id": "ORD-2026-0001",
    "amount": 19900,
    "currency": "KRW",
    "transaction_id": "PG-20260428-9988",
    "payment_method": "card",
    "metadata": { "channel": "checkout-v2" }
  }'

响应(200 OK,正常)

代码已复制到剪贴板
{
  "success": true,
  "payment_event_id": "9876543220",
  "attributed": {
    "matched": true,
    "method": "last_click",
    "link_id": 12345,
    "click_event_id": 678901,
    "install_event_id": "5544332211"
  }
}

响应(200 OK,幂等 — 以相同状态重复调用)

代码已复制到剪贴板
{
  "success": true,
  "payment_event_id": "9876543220",
  "idempotent": true,
  "attributed": {
    "matched": true,
    "method": "last_click",
    "link_id": 12345,
    "click_event_id": 678901,
    "install_event_id": "5544332211"
  }
}

响应(409 Conflict — 不同的终态)

当相同的 order_id 已处于其他终态(例:failed、refunded、canceled)时发生。

代码已复制到剪贴板
{
  "error": "payment already in terminal state",
  "existing_status": "failed"
}

attribution_method 取值

attributed.method 可能的 7 种取值。

last_clickmatched可选
安装 → 点击均已匹配(最正常的情况)。link_id、click_event_id、install_event_id 均有值。
last_click_install_onlymatched可选
安装已匹配,但时间窗口内没有点击(例:已安装的应用通过推送被唤起)。link_id 和 install_event_id 有值,click_event_id 为 null。
organic_installunmatched可选
存在安装,但 link_id 为 null(自然安装)。仅 install_event_id 有值。
no_install_in_windowunmatched可选
在 install_to_purchase_days 时间窗口内,initiated 阶段的 device_id 没有安装事件。
no_initiated_or_no_deviceunmatched可选
没有 initiated 记录,或 device_id 为空,因此无法尝试匹配。
errorunmatched可选
数据库查询失败等匹配流程内部错误。响应仍正常返回 200,错误会另行记录日志。
unmatchedunmatched可选
默认/保留值。实际上响应总会落入上述 6 种分支之一。

错误响应

400Bad Request可选
输入格式错误(order_id 格式、amount 范围、不允许的 currency 等)。
401Unauthorized可选
缺少 X-Api-Key 或 X-Api-Secret 请求头。{ "error": "API key is required." } 或 { "error": "API secret is required." }
403Forbidden可选
认证失败(apiKey/apiSecret 不匹配、租户未启用)。{ "error": "Authentication failed." } — 详细原因仅记录在服务器日志中。
409Conflict可选
已存在其他终态。existing_status 字段会指明是哪种状态。
500Server Error可选
服务器内部错误。

支付失败(S2S)

POST/v1/payments/failed

客户后端收到 PG 支付失败 Webhook 后调用。为进行漏斗分析,同样会执行匹配并保存到数据库,但响应中不公开 attributed 对象(失败时将点击/安装匹配结果传给客户端没有意义)。

请求头

代码已复制到剪贴板
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/json

请求参数

order_idstring必填
与 initiated 阶段相同的订单标识。
amountnumber必填
尝试支付的金额。大于 0 的数字。
currencystring必填
ISO 4217 币种代码(大写)。
failure_reasonstring可选
从 PG 收到的失败原因。最多保存 500 个字符。
transaction_idstring可选
PG 交易号。最多保存 200 个字符。
payment_methodstring可选
支付方式。最多保存 50 个字符。
metadataobject可选
自由格式的附加数据。

请求示例

代码已复制到剪贴板
curl -X POST https://tapferry.com/v1/payments/failed \
  -H "X-Api-Key: <your_api_key>" \
  -H "X-Api-Secret: <your_api_secret>" \
  -H "Content-Type: application/json" \
  -d '{
    "order_id": "ORD-2026-0001",
    "amount": 19900,
    "currency": "KRW",
    "failure_reason": "card_declined",
    "transaction_id": "PG-20260428-9988",
    "payment_method": "card"
  }'

响应(200 OK)

代码已复制到剪贴板
{
  "success": true,
  "payment_event_id": "9876543230"
}

响应(200 OK,幂等)

使用相同的 order_id 再次调用 failed 时,会按幂等方式处理(用于应对 PG Webhook 重试)。

代码已复制到剪贴板
{
  "success": true,
  "payment_event_id": "9876543230",
  "idempotent": true
}

响应(409 Conflict)

对已处于 succeeded/refunded/canceled 状态的订单调用 failed 时发生。

代码已复制到剪贴板
{
  "error": "payment already in terminal state",
  "existing_status": "succeeded"
}

错误响应

400Bad Request可选
输入格式错误。
401Unauthorized可选
缺少 X-Api-Key 或 X-Api-Secret 请求头。
403Forbidden可选
认证失败。{ "error": "Authentication failed." }
409Conflict可选
已以其他终态存在。
500Server Error可选
服务器内部错误。

记录合作伙伴转化 — 含非支付转化(S2S)

POST/v1/conversions

将注册、线索、购买等转化归因到推广合作伙伴效果(转化率·佣金)。请从您的后端以服务器到服务器方式调用(切勿从浏览器调用 — 会暴露 Secret)。将自动附加到目标 URL 的 ?vlref= 值作为 referral_key 传入即可显式归因;移动应用则通过 device_id 自动归因。SDK 的 track() 自定义事件仅用于事件标签页,不影响合作伙伴转化率。

请求头

代码已复制到剪贴板
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/json

请求参数

referral_keystring可选
合作伙伴推荐键(≤32 个字符)。referral_key / device_id 二者必填其一。
device_idstring可选
移动 SDK 的 deviceId(≤100 个字符)— 通过安装匹配自动归因。您的应用必须在首次启动时调用一次 SDK 的 track("app.install"),以便用相同的值记录安装(SDK 不会自动发送)。
typestring必填
signup | purchase | lead | custom。
order_idstring必填
幂等键(1–100 个字符,字母数字/-/_,在应用内唯一)。重复调用会返回已有的转化。
amountnumber可选
转化金额。默认为 0(signup/lead 允许 0;负数会被拒绝)。
currencystring必填
币种代码 — 大写,必填;缺失时返回 400(默认允许列表:KRW·USD·JPY·EUR·GBP)。
occurred_atstring可选
转化发生时间(ISO 8601)。
metadataobject可选
自由格式的附加数据。

请求示例

代码已复制到剪贴板
curl -X POST https://tapferry.com/v1/conversions \
  -H "X-Api-Key: <your_api_key>" \
  -H "X-Api-Secret: <your_api_secret>" \
  -H "Content-Type: application/json" \
  -d '{
    "referral_key": "aB3xK9",
    "type": "signup",
    "order_id": "SIGNUP-20260702-001",
    "amount": 0,
    "currency": "KRW"
  }'

响应(200 OK)

代码已复制到剪贴板
{
  "ok": true,
  "conversion_id": "412",
  "partner_id": "cmr2yofyb0003...",
  "attribution_method": "explicit_ref",
  "commission_amount": 0,
  "status": "confirmed"
}

attribution_method 为 explicit_ref(referral_key 匹配)| auto_device(安装匹配)| unmatched(无合作伙伴)之一。佣金按转化发生时的合作伙伴/计划设置进行快照。如遇取消/退款,请携带 order_id 调用 POST /v1/conversions/reverse。

错误响应

400Bad Request可选
输入无效(type/order_id/amount 等)。
401Unauthorized可选
缺少 X-Api-Key 或 X-Api-Secret 请求头。
404Not Found可选
未知的 referral_key。
409Conflict可选
并发重复插入(相同的 order_id)。
500Server Error可选
服务器错误。

撤销合作伙伴转化(退款)— S2S

POST/v1/conversions/reverse

撤销(退款)通过 POST /v1/conversions 记录的转化。请从您的后端以服务器到服务器方式调用。被撤销的转化会变为 status: "reversed",并从合作伙伴效果统计(转化 / 收入 / 佣金)中排除。

请求头

代码已复制到剪贴板
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/json

请求参数

order_idstring必填
要撤销的转化的幂等键(记录时发送的值)。

请求示例

代码已复制到剪贴板
curl -X POST https://tapferry.com/v1/conversions/reverse \
  -H "X-Api-Key: <your_api_key>" \
  -H "X-Api-Secret: <your_api_secret>" \
  -H "Content-Type: application/json" \
  -d '{
    "order_id": "ORDER-20260702-001"
  }'

响应(200 OK)

代码已复制到剪贴板
{
  "ok": true,
  "conversion_id": "412",
  "status": "reversed"
}

幂等响应 — 已撤销

对已撤销的转化再次调用时,会原样返回现有状态(idempotent: true)。

代码已复制到剪贴板
{
  "ok": true,
  "conversion_id": "412",
  "status": "reversed",
  "idempotent": true
}

错误响应

400Bad Request可选
缺少 order_id。
401Unauthorized可选
缺少 X-Api-Key 或 X-Api-Secret 请求头。
403Forbidden可选
认证失败(密钥/Secret 无效、租户未启用)。
404Not Found可选
找不到该 order_id 对应的转化。
500Server Error可选
服务器错误。

归因政策

决定支付成功/失败归因到哪次点击/安装的规则。采用最终点击(last_click)模型,并在调用 /v1/payments/succeeded 或 /v1/payments/failed 时同步(eager)执行匹配。匹配结果会立即记录到 payment_events 表的 attributed_* 列中。

时间窗口设置

归因时间窗口属于服务运营策略值,保存在 SystemConfig 中,以下默认值适用于所有应用。如需调整,请联系客服。

attribution.click_to_install_daysinteger (days)可选
点击 → 安装匹配窗口。仅安装时间前 N 天内的点击会成为归因候选。默认 7。
attribution.install_to_purchase_daysinteger (days)可选
安装 → 支付匹配窗口。仅支付终态时间前 N 天内的安装会成为归因候选。默认 30。
attribution.initiated_to_succeeded_hoursinteger (hours)可选
initiated → succeeded/failed 匹配窗口。仅终态时间前 N 小时内的 initiated 记录会用于提取 device_id。默认 24。
payments.allowed_currenciesstring[] (CSV)可选
允许的币种白名单。ISO 4217 大写。默认包括 KRW、USD、EUR、JPY 等(参见系统默认值)。

匹配步骤(伪代码)

代码已复制到剪贴板
function attributePayment(tenant_id, order_id, terminal_at):
  cfg = loadAttributionConfig()  // read SystemConfig

  # 1) find the initiated row (within terminal_at - initiated_to_succeeded_hours)
  #    if the order_id has several initiated rows, prefer the most recent one with a device_id,
  #    otherwise fall back to the most recent row
  init = paymentEvent.findFirst({
    tenantId, orderId, status: "initiated", deviceId != null,
    createdAt >= terminal_at - cfg.initiated_to_succeeded_hours
  }) ?? paymentEvent.findFirst({ ...same conditions, without the deviceId condition })
  if init == null or init.deviceId == null:
    return method="no_initiated_or_no_device"

  # 2) find the install event (by device_id, within terminal_at - install_to_purchase_days)
  install = sdkEvent.findFirst({
    tenantId, deviceId: init.deviceId,
    eventName: "app.install",
    createdAt >= terminal_at - cfg.install_to_purchase_days
  })
  if install == null:
    return method="no_install_in_window"
  if install.linkId == null:
    return method="organic_install" (only install_event_id is filled)

  # 3) find the click event (by link_id, within click_to_install_days before the install)
  click = clickEvent.findFirst({
    tenantId, linkId: install.linkId,
    createdAt <= install.createdAt,
    createdAt >= install.createdAt - cfg.click_to_install_days
  })

  return method = click ? "last_click" : "last_click_install_only"

匹配失败情况

no_initiated_or_no_deviceunmatched可选
没有 initiated 调用,或 SDK 未发送 device_id。最常见原因:SDK 未初始化 / 超出 initiated_to_succeeded_hours 时间窗口。
no_install_in_windowunmatched可选
在 install_to_purchase_days 内没有相同 device_id 的 app.install 事件。应用在首次启动时未调用 track("app.install")(SDK 不会自动发送),或已超出时间窗口。
organic_installunmatched可选
捕获到了安装,但 link_id 为 null(自然安装,例:在应用商店直接搜索)。
last_click_install_onlymatched可选
安装已匹配,但在 click_to_install_days 内没有点击事件(例:已安装后通过推送唤起)。
errorunmatched可选
数据库查询失败。响应为 200,但会显示 attributed.method = error,并发送 Telegram 告警。
unmatchedunmatched可选
理论上不会到达的兜底值。设计上会分流到上述情况之一。
last_clickmatched可选
唯一的正常匹配情况。link_id、click_event_id、install_event_id 均有值。

Android SDK

API 24 (7.0)+, Kotlin 1.9+ · Gradle

安装

注册公开的 Maven 仓库(无需认证),并在 Gradle 中添加依赖。

代码已复制到剪贴板
// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://aresjoydev.github.io/vialink-android-sdk") }
    }
}

// build.gradle.kts (app)
dependencies {
    implementation("com.vialink:sdk:3.2.25")
}

初始化

在 Application.onCreate() 中初始化 SDK。

代码已复制到剪贴板
// Application.kt
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()

        ViaLinkSDK.init(this, "YOUR_API_KEY")
    }
}

事件跟踪

记录自定义事件。SDK 每 30 秒批量发送一次。SDK 不会自动发送安装事件(app.install);如果使用推广合作伙伴转化或支付归因,请在首次启动时自行调用一次。

代码已复制到剪贴板
// Once on the first launch after install (the SDK does not send app.install)
// Required for partner conversion and payment attribution
// isFirstLaunch: first-launch flag your app keeps in its own storage
if (isFirstLaunch) {
    ViaLinkSDK.track("app.install")
}

// Purchase completed
ViaLinkSDK.track("purchase", mapOf(
    "product_id" to "12345",
    "revenue" to 29900,
    "currency" to "KRW"
))

// Sign up
ViaLinkSDK.track("signup")

// Add to cart
ViaLinkSDK.track("add_to_cart", mapOf("product_id" to "12345"))

支付跟踪

将支付尝试发送到 Tapferry 服务器(/v1/payments/initiated)。payment_method/metadata 为可选项,device_info 由 SDK 自动采集。响应中的 paymentEventId 用于标识同一 order_id 的支付生命周期。收到 PG 回调后,您的后端需另行调用 /v1/payments/succeeded 或 /failed(S2S 认证 + bcrypt 校验)。SDK 1.1.1+ 起可用。

代码已复制到剪贴板
import com.vialink.sdk.ViaLinkSDK
import com.vialink.sdk.model.PaymentInitiatedArgs
import kotlinx.coroutines.launch

// Right before showing the payment screen (inside a coroutine scope)
lifecycleScope.launch {
    try {
        val result = ViaLinkSDK.payment.initiated(
            PaymentInitiatedArgs(
                orderId = "ORD-2026-0001",
                amount = 19900.0,
                currency = "KRW",
                paymentMethod = "card",
                metadata = mapOf("productId" to "prod-001"),
            )
        )
        // result.success, result.paymentEventId
        Log.d("Tapferry", "payment_event_id=${result.paymentEventId}")
    } catch (e: IllegalArgumentException) {
        // Input validation failed (orderId format, amount, currency)
    } catch (e: Exception) {
        // Network error
    }
}

iOS SDK

iOS 15.0+, Swift 5.9+ · Swift Package Manager

安装

在 Xcode 中添加 Swift Package。

代码已复制到剪贴板
Xcode > File > Add Package Dependencies
URL: https://github.com/aresjoydev/vialink-ios-sdk

初始化

在 AppDelegate 或 SwiftUI App 的 init 中初始化 SDK。

代码已复制到剪贴板
import ViaLinkCore

// AppDelegate
func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions ...) -> Bool {
    ViaLinkSDK.shared.configure(apiKey: "YOUR_API_KEY")
    return true
}

// Or SwiftUI App
@main
struct MyApp: App {
    init() {
        ViaLinkSDK.shared.configure(apiKey: "YOUR_API_KEY")
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    ViaLinkSDK.shared.handleURL(url)
                }
        }
    }
}

事件跟踪

记录自定义事件。SDK 不会自动发送安装事件(app.install);如果使用推广合作伙伴转化或支付归因,请在首次启动时自行调用一次。

代码已复制到剪贴板
// Once on the first launch after install (the SDK does not send app.install)
// Required for partner conversion and payment attribution
// isFirstLaunch: first-launch flag your app keeps in its own storage
if isFirstLaunch {
    ViaLinkSDK.shared.track("app.install")
}

// Purchase completed
ViaLinkSDK.shared.track("purchase", data: [
    "product_id": "12345",
    "revenue": "29900",
    "currency": "KRW"
])

// Sign up
ViaLinkSDK.shared.track("signup")

支付跟踪

将支付尝试发送到 Tapferry 服务器(/v1/payments/initiated)。基于 async/await,可通过 PaymentError 分别处理输入校验失败和网络错误。收到 PG 回调后,您的后端需另行调用 /v1/payments/succeeded 或 /failed(S2S 认证 + bcrypt 校验)。SDK 1.1.1+ 起可用。

代码已复制到剪贴板
import ViaLinkCore

// Right before showing the payment screen (inside an async context)
Task {
    do {
        let result = try await ViaLinkSDK.shared.payment.initiated(
            PaymentInitiatedArgs(
                orderId: "ORD-2026-0001",
                amount: 19900,
                currency: "KRW",
                paymentMethod: "card",
                metadata: ["productId": "prod-001"]
            )
        )
        print("payment_event_id=\(result.paymentEventId)")
    } catch let error as PaymentError {
        // .invalidOrderId / .invalidAmount / .invalidCurrency / .sdkNotInitialized / .networkFailure
    } catch {
        // Other errors
    }
}

Web SDK

Chrome 80+, Safari 14+, Firefox 78+ · npm / CDN

安装

通过 npm 或 CDN 安装。

代码已复制到剪贴板
npm install vialink-web-sdk

初始化

初始化 SDK。即使用户离开页面,事件也会被发送。

代码已复制到剪贴板
import { ViaLinkWebSDK } from 'vialink-web-sdk';

const sdk = ViaLinkWebSDK.init({
  apiKey: 'YOUR_API_KEY'
});

事件跟踪

记录包括非支付转化(注册、线索等)在内的自定义事件。每 30 秒批量发送,用户离开页面时还会通过 sendBeacon 发送,并在控制台的「事件」标签页中汇总。若要将转化归因到推广合作伙伴的业绩(转化率/佣金),请不要使用 track,而是在服务器之间(S2S)调用 POST /v1/conversions,并将目标 URL 上自动附加的 ?vlref= 值作为 referral_key 传入(参见 REST API 文档)。

代码已复制到剪贴板
// Purchase completed
sdk.track('purchase', {
  product_id: '12345',
  revenue: 29900,
  currency: 'KRW'
});

// Signup completed (non-payment conversion — aggregated in the Events tab)
sdk.track('signup_completed');

// Flush immediately
await sdk.flush();

非支付转化跟踪(合作伙伴归因)

sdk.track() 的事件只会反映在「事件」标签页中,不影响推广合作伙伴的业绩(转化率/佣金)。要归因到合作伙伴:用户通过合作伙伴链接进入时,保存目标 URL 上自动附加的 ?vlref= 值,在转化确认后于服务器之间调用 POST /v1/conversions(type: signup | purchase | lead | custom,以 order_id 保证幂等,参见下方 REST API 部分的合作伙伴转化记录)。

代码已复制到剪贴板
// Recommended event names — for Events tab analytics
sdk.track('signup_completed');                     // Signup completed
sdk.track('lead_submitted', { form: 'consult' });  // Consultation/inquiry submitted
sdk.track('trial_started');                        // Free trial started

// For partner attribution — capture (store) vlref on landing, then
// call POST /v1/conversions from the backend once the conversion is confirmed (pass as referral_key)
const vlref = new URLSearchParams(location.search).get('vlref');
if (vlref) sessionStorage.setItem('vialink_ref', vlref);

支付跟踪

将支付尝试发送到 Tapferry 服务器(/v1/payments/initiated)。SDK 1.1.0+ 起可用。收到 PG 回调后,您的后端需另行调用 /v1/payments/succeeded 或 /failed(S2S 认证 + bcrypt 校验)。

代码已复制到剪贴板
import { ViaLinkWebSDK } from 'vialink-web-sdk';

ViaLinkWebSDK.init({ apiKey: 'YOUR_API_KEY' });

// Right before showing the payment screen:
try {
  const result = await ViaLinkWebSDK.payment.initiated({
    orderId: 'ORD-2026-0001',
    amount: 19900,
    currency: 'KRW',
    paymentMethod: 'card',
    metadata: { productId: 'prod-001' },
  });
  console.log('payment_event_id=', result.paymentEventId);
} catch (e) {
  // Input validation failed or network error
  console.error(e);
}

智能应用横幅

在移动 Web 上显示提示用户安装应用的横幅。

代码已复制到剪贴板
sdk.showBanner({
  title: 'View in App',
  description: 'Use the app for a faster experience',
  buttonText: 'Open',
  iosStoreUrl: 'https://apps.apple.com/app/id123456',
  androidStoreUrl: 'https://play.google.com/store/apps/...',
  position: 'bottom',
  theme: 'light'
});

// Hide the banner
sdk.hideBanner();

React Native SDK

React Native 0.73+, TypeScript 5+ · npm / yarn

安装

通过 npm 或 yarn 安装。

代码已复制到剪贴板
npm install vialink-react-native-sdk
# or
yarn add vialink-react-native-sdk

初始化

在 App.tsx 的顶层初始化 SDK。

代码已复制到剪贴板
import { useEffect } from 'react';
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import { ViaLinkSDK } from 'vialink-react-native-sdk';

// App.tsx
function App() {
  const navigationRef = useNavigationContainerRef();

  useEffect(() => {
    ViaLinkSDK.shared.configure('YOUR_API_KEY');

    return () => {
      ViaLinkSDK.shared.destroy();
    };
  }, []);

  return <NavigationContainer ref={navigationRef}>{/* screens */}</NavigationContainer>;
}

事件跟踪

记录自定义事件。SDK 不会自动发送安装事件(app.install);如果使用推广合作伙伴转化或支付归因,请在首次启动时自行调用一次。

代码已复制到剪贴板
// Once on the first launch after install (the SDK does not send app.install)
// Required for partner conversion and payment attribution
// isFirstLaunch: first-launch flag your app keeps in its own storage
if (isFirstLaunch) {
  ViaLinkSDK.shared.track('app.install');
}

// Purchase completed
ViaLinkSDK.shared.track('purchase', {
  product_id: '12345',
  revenue: 29900,
  currency: 'KRW'
});

// Sign up
ViaLinkSDK.shared.track('signup');

支付跟踪

将支付尝试发送到 Tapferry 服务器(/v1/payments/initiated)。通过原生桥调用 Android/iOS 原生 SDK 的 payment.initiated(SDK 2.1.0+)。收到 PG 回调后,您的后端需另行调用 /v1/payments/succeeded 或 /failed。

代码已复制到剪贴板
import { ViaLinkSDK } from 'vialink-react-native-sdk';

// Right before showing the payment screen:
try {
  const result = await ViaLinkSDK.shared.payment.initiated({
    orderId: 'ORD-2026-0001',
    amount: 19900,
    currency: 'KRW',
    paymentMethod: 'card',
  });
  console.log('payment_event_id=', result.paymentEventId);
} catch (e) {
  // Input validation failed or network error
}

平台设置

需要分别在 iOS 和 Android 上进行深度链接配置。

代码已复制到剪贴板
// app.json (Expo)
{
  "expo": {
    "ios": {
      "associatedDomains": ["applinks:tapferry.com"]
    },
    "android": {
      "intentFilters": [{
        "action": "VIEW",
        "autoVerify": true,
        "data": [{
          "scheme": "https",
          "host": "tapferry.com",
          "pathPrefix": "/{your-slug}/"
        }],
        "category": ["BROWSABLE", "DEFAULT"]
      }]
    }
  }
}

Unity SDK

Unity 2021.3+ LTS, C# 9+ · Unity Package Manager (UPM)

安装

通过 UPM 添加软件包。

代码已复制到剪贴板
Window > Package Manager > + > Add package from git URL:
https://github.com/aresjoydev/vialink-unity-sdk.git

初始化

在第一个场景中放置 ViaLinkSDK 预制体并进行初始化。

代码已复制到剪贴板
using Tapferry;

public class GameManager : MonoBehaviour
{
    void Start()
    {
        ViaLinkSDK.Instance.Initialize("YOUR_API_KEY");
    }
}

事件跟踪

记录自定义事件。SDK 不会自动发送安装事件(app.install);如果使用推广合作伙伴转化或支付归因,请在首次启动时自行调用一次。

代码已复制到剪贴板
// Once on the first launch after install (the SDK does not send app.install)
// Required for partner conversion and payment attribution
// isFirstLaunch: first-launch flag your app keeps in its own storage
if (isFirstLaunch)
{
    ViaLinkSDK.Instance.TrackEvent("app.install");
}

// In-app purchase
ViaLinkSDK.Instance.TrackEvent("purchase",
    new Dictionary<string, object>
    {
        { "product_id", "gem_pack_100" },
        { "revenue", 4900 },
        { "currency", "KRW" }
    });

// Level cleared
ViaLinkSDK.Instance.TrackEvent("level_clear",
    new Dictionary<string, object>
    {
        { "level", 10 }
    });

支付跟踪

将支付尝试发送到 Tapferry 服务器(/v1/payments/initiated)。Unity SDK 使用回调模式(onSuccess/onError)(SDK 1.1.0+)。收到 PG 回调后,您的后端需另行调用 /v1/payments/succeeded 或 /failed。

代码已复制到剪贴板
using Tapferry.SDK;

// Right before showing the payment screen (inside a MonoBehaviour)
ViaLinkSDK.Payment.Initiated(
    new PaymentInitiatedArgs {
        OrderId = "ORD-2026-0001",
        Amount = 19900,
        Currency = "KRW",
        PaymentMethod = "card",
    },
    onSuccess: (result) => {
        Debug.Log($"payment_event_id={result.PaymentEventId}");
    },
    onError: (error) => {
        Debug.LogError($"Payment attempt failed: {error}");
    }
);

Flutter SDK

Flutter 3.44+, Dart 3.12+ · pub.dev

安装

在 pubspec.yaml 中添加依赖。

代码已复制到剪贴板
flutter pub add vialink_flutter_plugin

初始化

在应用启动时初始化 SDK。

代码已复制到剪贴板
import 'package:vialink_flutter_plugin/vialink_flutter_plugin.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await ViaLinkSDK.instance.configure(apiKey: 'YOUR_API_KEY');

  runApp(const MyApp());
}

事件跟踪

记录自定义事件。SDK 不会自动发送安装事件(app.install);如果使用推广合作伙伴转化或支付归因,请在首次启动时自行调用一次。

代码已复制到剪贴板
// Once on the first launch after install (the SDK does not send app.install)
// Required for partner conversion and payment attribution
// isFirstLaunch: first-launch flag your app keeps in its own storage
if (isFirstLaunch) {
  ViaLinkSDK.instance.track('app.install');
}

// Purchase completed
ViaLinkSDK.instance.track('purchase', data: {
  'product_id': '12345',
  'revenue': '29900',
  'currency': 'KRW',
});

// Sign up
ViaLinkSDK.instance.track('signup');

支付跟踪

将支付尝试发送到 Tapferry 服务器(/v1/payments/initiated)。ViaLinkSDK.instance.trackPayment() 通过 Pigeon 通道调用原生 SDK。收到 PG 回调后,您的后端需另行调用 /v1/payments/succeeded 或 /failed。

代码已复制到剪贴板
import 'package:vialink_flutter_plugin/vialink_flutter_plugin.dart';

// Right before showing the payment screen:
try {
  final result = await ViaLinkSDK.instance.trackPayment(
    orderId: 'ORD-2026-0001',
    amount: 19900,
    currency: 'KRW',
    paymentMethod: 'card',
    metadata: {'productId': 'prod-001'},
  );
  print('payment_event_id=${result.paymentEventId}');
} catch (e) {
  // Native errors such as PlatformException
}

平台设置

需要分别在 iOS 和 Android 上进行深度链接配置。

代码已复制到剪贴板
# iOS: ios/Runner/Runner.entitlements
# Add Associated Domains:
#   applinks:tapferry.com

# Android: android/app/src/main/AndroidManifest.xml
# <intent-filter android:autoVerify="true">
#   <action android:name="android.intent.action.VIEW" />
#   <category android:name="android.intent.category.DEFAULT" />
#   <category android:name="android.intent.category.BROWSABLE" />
#   <data
#     android:scheme="https"
#     android:host="tapferry.com"
#     android:pathPrefix="/{your-slug}/" />
# </intent-filter>