入门
初次使用 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/succeededPOST /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 都能被正确识别。
链接 / 域名
可以自行指定 Short Code 吗?
创建链接时可通过 customCode 参数指定。未指定时,系统会自动生成一个 6 位的 base36 代码。
您可以通过 POST /api/links/check-short-code 预先检查是否重复。
已创建的链接可以修改吗?
可以,通过 PUT /api/links/:id 或控制台修改。可修改的字段如下。
name,description,tagsdeeplinkPath,deeplinkDataiosUrl,androidUrl,webUrlogTitle,ogDescription,ogImageUrlcampaign,channel,featureexpiresAt
但 linkType 本身无法更改。
链接的过期、停用和删除如何处理?
- 过期 — 超过
expiresAt时间后,跳转将被阻止 - 停用 — 可通过
suspendedAt临时暂停链接 - 删除 — 调用
DELETE /api/links/:id会执行记录deletedAt的软删除。如需恢复,可在管理后台处理
可以绑定自定义域名(如 go.mycompany.com)吗?
在控制台的 应用 → 域名 中注册。将 CNAME 目标设置为 edge.tapferry.com 后,DNS 验证和 SSL 签发将自动进行。
域名状态会按以下阶段显示。
pending_dns— 等待 DNS 验证dns_verified— DNS 验证完成ssl_provisioning— 正在签发 SSL 证书active— 可以使用
自定义域名在包含 customDomain 功能的套餐中可用。
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_idno_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)。
在哪里查看分析数据?
您可以在控制台的 应用 → 分析 页面查看点击、安装、各平台及各推广活动的统计数据。
深度链接
我只填写了应用信息(Bundle ID 等),尚未安装 SDK,正在测试中,为什么在某些平台上链接无法到达应用?
单纯“打开应用”由操作系统负责,但检查“该应用是否真正准备好接收此链接”的逻辑因平台而异。
- 症状 — 即使通过链接打开了应用,未集成 SDK 的应用也无法解析用户点击带来的参数(例如推荐码、特定商品编号),因此会停留在主界面或报错。
- 平台差异 — 尤其是在使用延迟深度链接(未安装应用的用户在安装后到达预定页面)时,如果应用内没有 SDK,就无法将商店的安装信息与链接点击信息进行匹配,流程会因此中断。
- 解决方法 — 仅完成应用设置只算完成了一半。必须在应用内嵌入深度链接 SDK,作为接收系统调用的“天线”,只有这样才能在所有平台上稳定地到达应用内的预定页面。
我已完成 Universal Links 设置,但从 Instagram、Facebook、Threads 仍无法启动应用。可能是什么问题?
是否遗漏了 Custom URL Scheme?(跳出社交应用的关键)
Instagram、Facebook、Threads 等封闭的社交平台不会直接接受 Universal Links,而是将用户困在其自有的应用内浏览器中。
- 症状 — 如果只设置了 Universal Links 而跳过了 Custom URL Scheme 设置,在应用内浏览器中点击“在应用中打开”将毫无反应,因为没有可用于调用应用的“地址”。
- 解决方法 — 必须在应用设置(
Info.plist)中注册您应用专属的 URL Scheme,并在深度链接 SDK 配置中正确填写相同的 Scheme 值。只有这样,才能突破封闭平台的壁垒并打开应用。
我修改了 Universal Links 设置,为什么没有立即生效?
这很可能是缓存导致的,而非配置错误。Universal Links 依赖于由 Apple 作为中间“担保人”来保障安全和性能的结构,这些信息的更新确实需要时间。
1. 为什么不能立即生效?(三级缓存结构)
在 Universal Links 生效之前,信息需要经过三个阶段。每个阶段保留信息的时长各不相同。
- 阶段 1 — Apple 的 CDN 服务器(最长 48 小时) — Apple 并不会时刻检查全球所有应用的配置。它将信息存储在自己的 CDN(数据存储)中,大约每 24–48 小时更新一次。
- 阶段 2 — 用户的 iOS 设备(最长 1 周) — iOS 不会每次都向服务器确认,而是将信息存储在设备本地。通常大约每周刷新一次。
- 阶段 3 — 各平台的应用内浏览器缓存 — Naver、Facebook 等应用拥有自己的浏览器缓存,可能仍记着之前失败的连接。
2. 如果想立即测试(用于开发/QA)
如果无法等待生产环境的缓存清除,请尝试以下方法。
- 方法 1 — 使用开发者模式(最推荐) — 在 iPhone 上启用 [设置 > 开发者 > Associated Domains Development]。在链接后附加
?mode=developer参数,即可绕过 Apple CDN,直接从服务器获取最新信息。 - 方法 2 — 重新安装应用 — 删除并重新安装应用会重置设备上的部分缓存信息,使其读取新的设置。
- 方法 3 — 在链接中添加随机参数 — 访问从未使用过的地址,例如用
tapferry.com/abcd?refresh=1代替tapferry.com/abcd,有时可以绕过缓存。
认证
查询、创建链接以及支付尝试上报(/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创建链接
创建新的深度链接。
请求参数
linkType 模式对比
- ·
static(默认) — 固定的单一入口。如果在签发的 URL 后附加令牌,将按 404 处理(阻止搜索引擎收录)。 - ·
dynamic— 在签发的 URL 后附加/yourValue或?key=value,该值会自动传递到点击记录和 SDK 响应中。
请求示例
POST /api/links
Content-Type: application/json
X-API-Key: <your_api_key>
{
"linkType": "static",
"deeplinkPath": "/product/12345",
"deeplinkData": { "product_id": "12345" },
"campaign": "summer_sale",
"channel": "email",
"feature": "product_share",
"ogTitle": "Summer Sale Special",
"ogDescription": "Check it out now!",
"ogImageUrl": "https://cdn.example.com/promo.jpg",
"iosUrl": "https://apps.apple.com/app/id123456",
"androidUrl": "https://play.google.com/store/apps/...",
"webUrl": "https://www.example.com/product/12345",
"tags": ["summer", "sale"],
"expiresAt": "2026-12-31T23:59:59Z",
"customCode": "summer-sale-2026",
"name": "2026 Spring IG ad",
"description": "Instagram story ad only. Expires end of June."
}响应(201 Created)
{
"id": 1,
"shortCode": "summer-sale-2026",
"shortUrl": "https://tapferry.com/{your-slug}/summer-sale-2026",
"deeplinkPath": "/product/12345",
"linkType": "static",
"name": "2026 Spring IG ad",
"description": "Instagram story ad only. Expires end of June.",
"createdAt": "2026-04-06T12:00:00Z"
}错误(400 Bad Request)
当 linkType 显式传入 dynamic/static 以外的值时(省略该字段则自动保存为 static):
{
"error": "linkType must be either 'dynamic' or 'static'."
}错误(409 Conflict)
当 customCode 在同一应用内已被使用时(不区分大小写检查):
{
"error": "This short code is already in use."
}错误(403 Forbidden)
当应用的链接数达到套餐的链接上限时 (控制台和 API 创建的链接合并计算,已删除的链接不计入)。响应中的 code 为 quota_exceeded,已创建链接的查询、修改和跳转不受影响:
{
"error": "...",
"code": "quota_exceeded",
"quotaKey": "deeplinkLimit",
"current": 5,
"limit": 5
}获取链接
获取指定链接的完整信息。
路径参数
响应(200 OK)
{
"id": 1,
"shortCode": "aB3xK",
"shortUrl": "https://tapferry.com/{your-slug}/aB3xK",
"linkType": "static",
"deeplinkPath": "/product/12345",
"deeplinkData": { "product_id": "12345" },
"campaign": "summer_sale",
"channel": "email",
"feature": "product_share",
"ogTitle": "Summer Sale Special",
"ogDescription": "Check it out now!",
"ogImageUrl": "https://cdn.example.com/promo.jpg",
"iosUrl": "https://apps.apple.com/app/id123456",
"androidUrl": "https://play.google.com/store/apps/...",
"webUrl": "https://www.example.com/product/12345",
"expiresAt": "2026-12-31T23:59:59Z",
"name": "2026 Spring IG ad",
"description": "Instagram story ad only. Expires end of June.",
"createdAt": "2026-04-06T12:00:00Z",
"updatedAt": "2026-04-06T12:00:00Z"
}更新链接
更新现有链接。只需发送要修改的字段。除 X-API-Key 外还需要 X-Api-Secret 请求头,因此请仅从您的后端调用(切勿将 Secret 放入应用或浏览器中)。
请求参数
linkType 不可更改
如果此端点的请求体中包含 linkType 键,将以 400 拒绝。如需更改模式,请创建新链接。
分配给合作伙伴的链接不能更改目标
分配给合作伙伴的追踪链接(已设置 partnerId)不能更改目标字段(deeplinkPath、deeplinkData、iosUrl、androidUrl、webUrl),尝试更改将返回 400。campaign/channel 等元数据字段以及合作伙伴重新分配(partnerId)可以编辑。
请求示例
PUT /api/links/1
Content-Type: application/json
X-API-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
{
"ogTitle": "Updated title",
"webUrl": "https://www.example.com/new-page",
"name": "2026 Summer ad",
"description": "Updated for the summer campaign."
}响应(200 OK)
返回更新后的完整链接对象(包含 name 和 description)。
错误(400 Bad Request)
当请求体中包含 linkType 键时:
{
"error": "Mode cannot be changed. Please create a new link."
}删除链接
删除链接(软删除)。已删除链接的 URL 将不再生效。与更新相同,需要 X-Api-Secret 请求头,且只能从您的后端调用。
路径参数
分配给合作伙伴的链接不能删除
分配给合作伙伴的追踪链接(已设置 partnerId)无法通过此端点删除,会返回 403(以保留归因及历史点击/转化)。如需结束合作关系,请使用合作伙伴状态(暂停/移除)。
响应(200 OK)
{
"success": true
}链接列表
获取已创建的链接列表。
返回通过 API Key 认证的应用的链接列表。
响应(200 OK)
{
"links": [
{
"id": 1,
"shortCode": "summer-sale-2026",
"shortUrl": "https://tapferry.com/{your-slug}/summer-sale-2026",
"linkType": "static",
"deeplinkPath": "/product/12345",
"name": "2026 Spring IG ad",
"description": "Instagram story ad only. Expires end of June.",
"createdAt": "2026-04-06T12:00:00Z"
}
],
"total": 50
}检查短码
在创建链接前实时检查 customCode 是否可用。认证:需要会话 Cookie 以及该租户的 ADMIN 及以上角色。
查询参数
请求示例
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)
用户打开支付页面时 SDK 调用的端点。即使使用相同的 order_id 多次调用,也会每次新建一行(用于追踪卡信息输错等重试情况)。此阶段不进行匹配,匹配会在之后调用 /v1/payments/succeeded 时同步执行。
请求头
X-Api-Key: <your_api_key>
Content-Type: application/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"
}错误响应
支付成功(S2S)
客户后端收到 PG 回调后调用的服务器到服务器(Server-to-Server)端点。匹配流程同步执行,因此响应中包含 attributed 对象。请勿从 SDK 直接调用(会暴露 apiSecret)。
请求头
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/jsonapiSecret 以 bcrypt 哈希形式存储在数据库中,并通过 bcrypt.compare 而非明文比较进行验证。认证失败统一返回 "Authentication failed." 这一条消息,不会透露在哪个阶段失败(apiKey 是否存在 / apiSecret 是否匹配 / 租户是否启用)。
请求参数
请求示例
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 种取值。
错误响应
支付失败(S2S)
客户后端收到 PG 支付失败 Webhook 后调用。为进行漏斗分析,同样会执行匹配并保存到数据库,但响应中不公开 attributed 对象(失败时将点击/安装匹配结果传给客户端没有意义)。
请求头
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/json请求参数
请求示例
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"
}错误响应
记录合作伙伴转化 — 含非支付转化(S2S)
将注册、线索、购买等转化归因到推广合作伙伴效果(转化率·佣金)。请从您的后端以服务器到服务器方式调用(切勿从浏览器调用 — 会暴露 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请求参数
请求示例
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。
错误响应
撤销合作伙伴转化(退款)— S2S
撤销(退款)通过 POST /v1/conversions 记录的转化。请从您的后端以服务器到服务器方式调用。被撤销的转化会变为 status: "reversed",并从合作伙伴效果统计(转化 / 收入 / 佣金)中排除。
请求头
X-Api-Key: <your_api_key>
X-Api-Secret: <your_api_secret>
Content-Type: application/json请求参数
请求示例
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
}错误响应
归因政策
决定支付成功/失败归因到哪次点击/安装的规则。采用最终点击(last_click)模型,并在调用 /v1/payments/succeeded 或 /v1/payments/failed 时同步(eager)执行匹配。匹配结果会立即记录到 payment_events 表的 attributed_* 列中。
时间窗口设置
归因时间窗口属于服务运营策略值,保存在 SystemConfig 中,以下默认值适用于所有应用。如需调整,请联系客服。
匹配步骤(伪代码)
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"匹配失败情况
安装
注册公开的 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")
}
}深度链接处理
注册深度链接回调,并在 Activity 中处理启动 Intent。SDK 3.1+:正常启动(如点击应用图标)时也会以 data == null 调用回调。
// Register a deep link callback (SDK 3.1+: (DeepLinkData?) -> Unit)
// Always called once on handleIntent:
// - data != null : App Link entry → route using data.path
// - data == null : normal launch (icon tap etc.) → keep the default screen
ViaLinkSDK.onDeepLink { data ->
if (data == null) {
Log.d("Tapferry", "Normal launch — keep the default screen")
return@onDeepLink
}
Log.d("Tapferry", "path: ${data.path}")
Log.d("Tapferry", "params: ${data.params}")
}
// Deferred deep link callback (SDK 3.2+: called once on every app launch)
// - First launch: called as soon as the match result is decided, within 5s (error on timeout/failure)
// - Non-first launch: called immediately with (null, null) — no /v1/open call (same meaning as organic)
ViaLinkSDK.onDeferredDeepLink { data, error ->
when {
error != null -> Log.w("Tapferry", "Deferred match failed: ${error.code}")
data == null -> Log.d("Tapferry", "Organic or non-first launch — normal entry")
else -> Log.d("Tapferry", "Deferred: ${data.path}")
}
}
// Handle the launch Intent in the Activity (SDK 3.1+: callback also fires on normal launches)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ViaLinkSDK.handleIntent(intent) // Always called
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
ViaLinkSDK.handleIntent(intent)
}
}事件跟踪
记录自定义事件。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
}
}创建链接
在应用内创建深度链接并分享。备用 URL、OG 元标签、渠道/标签/有效期等服务器支持的所有选项都可以通过命名参数传入。linkType 默认为 "static"(固定的单一入口,不跟踪);需要点击跟踪时请指定 "dynamic"。
lifecycleScope.launch {
val result = ViaLinkSDK.createLink(
path = "/product/12345",
data = mapOf("promo_code" to "FRIEND_SHARE"),
campaign = "referral",
linkType = "dynamic", // "dynamic" when you need click tracking (omit for "static")
iosUrl = "https://apps.apple.com/app/id123456",
androidUrl = "https://play.google.com/store/apps/details?id=com.example",
webUrl = "https://www.example.com/product/12345",
ogTitle = "Summer Sale",
ogDescription = "Check it out now!",
ogImageUrl = "https://cdn.example.com/promo.jpg",
channel = "email",
feature = "product_share",
tags = listOf("summer", "sale"),
expiresAt = "2026-12-31T23:59:59Z"
)
result.onSuccess { shortUrl ->
// shortUrl: "https://tapferry.com/{your-slug}/xYz12"
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, shortUrl)
type = "text/plain"
}
startActivity(Intent.createChooser(sendIntent, "Share"))
}
}创建链接(从 Java 调用)
如果应用源码是 Java,则无法直接调用 suspend fun。请使用 SDK 1.4.0+ 提供的 Callback/CompletableFuture 封装;从 1.5.0+ 起可通过 CreateLinkOptions Builder 传入全部选项。
import com.vialink.sdk.ViaLinkSDK;
import com.vialink.sdk.model.CreateLinkOptions;
import java.util.Map;
import java.util.List;
// Full options — using the CreateLinkOptions Builder (Callback)
CreateLinkOptions opts = new CreateLinkOptions.Builder()
.data(Map.of("promo_code", "FRIEND_SHARE"))
.campaign("referral")
.linkType("dynamic")
.iosUrl("https://apps.apple.com/app/id123456")
.androidUrl("https://play.google.com/store/apps/details?id=com.example")
.webUrl("https://www.example.com/product/12345")
.ogTitle("Summer Sale")
.ogImageUrl("https://cdn.example.com/promo.jpg")
.channel("email")
.feature("product_share")
.tags(List.of("summer", "sale"))
.expiresAt("2026-12-31T23:59:59Z")
.build();
ViaLinkSDK.createLinkAsync(
"/product/12345",
opts,
shortUrl -> { /* success (main thread) */ },
err -> Log.e("Tapferry", "Failed to create link", err)
);
// CompletableFuture style (minSdk 24+)
ViaLinkSDK.createLinkFuture("/product/12345", opts)
.thenAccept(shortUrl -> { /* success */ })
.exceptionally(err -> { /* failure */ return null; });
// Simple call — when you don't need fallback/OG options
ViaLinkSDK.createLinkAsync(
"/product/12345",
Map.of("promo_code", "FRIEND_SHARE"),
"referral",
"dynamic",
shortUrl -> {},
err -> {}
);App Links 设置
在 AndroidManifest.xml 中添加 App Links 的 intent filter。
<activity
android:name=".MainActivity"
android:exported="true">
<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>
</activity>安装
在 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)
}
}
}
}深度链接处理
注册深度链接回调,并在 SceneDelegate 中处理 Universal Links。SDK 3.1+:正常启动(如点击应用图标)时也会以 data == nil 调用回调。
// Register a deep link callback (SDK 3.1+: (DeepLinkData?) -> Void)
// Always called once when notified of app entry:
// - data != nil : Universal Link entry → route using data.path
// - data == nil : normal launch (icon tap etc.) → keep the default screen
ViaLinkSDK.shared.onDeepLink { data in
guard let data = data else {
print("Normal launch — keep the default screen")
return
}
print("path: \(data.path)")
print("params: \(data.params)")
}
// Deferred deep link callback (SDK 3.2+: called once on every app launch)
// - First launch: called as soon as the match result is decided, within 5s (error on timeout/failure)
// - Non-first launch: called immediately with (nil, nil) — no /v1/open call (same meaning as organic)
ViaLinkSDK.shared.onDeferredDeepLink { data, error in
if let error = error {
print("Deferred match failed: \(error.code.rawValue)")
} else if let data = data {
print("Deferred: \(data.path)")
} else {
print("Organic or non-first launch — normal entry")
}
}
// Handle Universal Links + normal-launch notification in SceneDelegate (3.1+)
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options: UIScene.ConnectionOptions) {
if let activity = options.userActivities.first {
ViaLinkSDK.shared.handleUniversalLink(activity)
} else if let urlContext = options.urlContexts.first {
ViaLinkSDK.shared.handleURL(urlContext.url)
} else {
ViaLinkSDK.shared.notifyAppLaunch() // Normal launch
}
}
func scene(_ scene: UIScene,
continue userActivity: NSUserActivity) {
ViaLinkSDK.shared.handleUniversalLink(userActivity)
}事件跟踪
记录自定义事件。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
}
}创建链接
在应用内创建深度链接。备用 URL、OG 元标签、渠道/标签/有效期等服务器支持的所有选项都可以通过命名参数传入。
let shortUrl = try await ViaLinkSDK.shared.createLink(
path: "/product/12345",
data: ["promo_code": "FRIEND_SHARE"],
campaign: "referral",
linkType: "dynamic", // "dynamic" when you need click tracking (omit for "static")
iosUrl: "https://apps.apple.com/app/id123456",
androidUrl: "https://play.google.com/store/apps/details?id=com.example",
webUrl: "https://www.example.com/product/12345",
ogTitle: "Summer Sale",
ogDescription: "Check it out now!",
ogImageUrl: "https://cdn.example.com/promo.jpg",
channel: "email",
feature: "product_share",
tags: ["summer", "sale"],
expiresAt: "2026-12-31T23:59:59Z"
)
// shortUrl: "https://tapferry.com/{your-slug}/xYz12"
let activityVC = UIActivityViewController(
activityItems: [shortUrl],
applicationActivities: nil
)
present(activityVC, animated: true)Universal Links 设置
在 Xcode 中配置 Associated Domains。
1. Xcode > Target > Signing & Capabilities
2. + Capability > Associated Domains
3. Add domain: applinks:tapferry.com安装
通过 npm 或 CDN 安装。
npm install vialink-web-sdk初始化
初始化 SDK。即使用户离开页面,事件也会被发送。
import { ViaLinkWebSDK } from 'vialink-web-sdk';
const sdk = ViaLinkWebSDK.init({
apiKey: 'YOUR_API_KEY'
});深度链接处理
解析当前 URL(同步)并查询短链接(resolveLink)。Web SDK 没有 onDeepLink。getDeepLinkData() 会把路径段不少于两段的任何 URL 都视为深度链接(path 始终为 '/'),且服务器不会在 Web 目标地址上附加深度链接参数,因此请勿根据此结果进行页面跳转。请在创建链接时将完整的页面路径设置到 webUrl。
// Warning: do not navigate (location.href / router) based on the result.
// Any URL with 2+ path segments is treated as a deep link
// (e.g. https://myshop.com/blog/hello-world → { path: '/', shortCode: 'hello-world' })
const data = sdk.getDeepLinkData();
if (data) {
console.log('shortCode:', data.shortCode);
}
// Parse an arbitrary URL using the static method (synchronous)
const parsed = ViaLinkWebSDK.parseDeepLinkFromURL(
'https://tapferry.com/{your-slug}/xYz12?ref=share'
);
// → { path: '/', params: { ref: 'share' }, shortCode: 'xYz12' }
// Look up the deep link behind a short link on the server (POST /v1/resolve)
const resolved = await sdk.resolveLink('https://tapferry.com/{your-slug}/xYz12');
if (resolved) {
console.log('path:', resolved.path);
console.log('params:', resolved.params);
}事件跟踪
记录包括非支付转化(注册、线索等)在内的自定义事件。每 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 上创建深度链接。备用 URL、OG 元标签、渠道/标签/有效期等附加选项通过第 5 个参数(对象)传入。
const shortUrl = await sdk.createLink(
'/product/12345',
{ promo_code: 'FRIEND_SHARE' },
'referral',
'dynamic', // "dynamic" when you need click tracking (omit for 'static')
{
iosUrl: 'https://apps.apple.com/app/id123456',
androidUrl: 'https://play.google.com/store/apps/details?id=com.example',
webUrl: 'https://www.example.com/product/12345',
ogTitle: 'Summer Sale',
ogDescription: 'Check it out now!',
ogImageUrl: 'https://cdn.example.com/promo.jpg',
channel: 'email',
feature: 'product_share',
tags: ['summer', 'sale'],
expiresAt: '2026-12-31T23:59:59Z',
}
);
console.log(shortUrl); // "https://tapferry.com/{your-slug}/xYz12"安装
通过 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>;
}深度链接处理
注册深度链接回调。仅在通过链接打开应用时触发,返回值为 void(通过 destroy() 解除)。React Navigation 的 navigate() 接收的是路由名称,因此请将 data.path 映射到路由。
import { ViaLinkSDK, type DeepLinkData } from 'vialink-react-native-sdk';
// navigate() takes a route name, not a path — map data.path to your app's route.
// navigationRef: NavigationContainer ref created with useNavigationContainerRef()
function navigateFromDeepLink(data: DeepLinkData) {
const m = data.path.match(/^\/product\/([^/?#]+)/);
if (m) navigationRef.navigate('Product', { id: m[1] });
}
// Deep link callback — called with data only when opened via a link (not on normal entry)
// Returns void (no unsubscribe function — release with destroy())
ViaLinkSDK.shared.onDeepLink((data) => {
console.log('path:', data.path);
console.log('params:', data.params);
navigateFromDeepLink(data);
});
// Deferred deep link callback (SDK 3.2+: called once on every app launch)
// - First launch: /v1/open match result delivered within 5s (error on timeout/failure)
// - Non-first launch: called immediately with (null, null) — no network call (same meaning as organic)
ViaLinkSDK.shared.onDeferredDeepLink((data, error) => {
if (error) {
console.warn('Deferred match failed:', error.code);
return;
}
if (!data) {
console.log('Organic or non-first launch — normal entry');
return;
}
navigateFromDeepLink(data);
});事件跟踪
记录自定义事件。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
}创建链接
在应用内创建深度链接并分享。备用 URL、OG、渠道等附加选项通过第 5 个参数(对象)传入。
const shortUrl = await ViaLinkSDK.shared.createLink(
'/product/12345',
{ promo_code: 'FRIEND_SHARE' },
'referral',
'dynamic', // "dynamic" when you need click tracking (omit for 'static')
{
iosUrl: 'https://apps.apple.com/app/id123456',
androidUrl: 'https://play.google.com/store/apps/details?id=com.example',
webUrl: 'https://www.example.com/product/12345',
ogTitle: 'Summer Sale',
ogImageUrl: 'https://cdn.example.com/promo.jpg',
channel: 'sms',
feature: 'product_share',
tags: ['summer', 'sale'],
expiresAt: '2026-12-31T23:59:59Z',
}
);
await Share.share({ message: shortUrl });平台设置
需要分别在 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"]
}]
}
}
}安装
通过 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 3.1+:正常启动(如点击应用图标)时也会以 data == null 触发该事件。
// Deep link callback (SDK 3.1+: also fires on normal launches — data == null)
ViaLinkSDK.Instance.OnDeepLink += (data) =>
{
if (data == null)
{
Debug.Log("Normal launch — keep the default screen");
return;
}
Debug.Log($"path: {data.Path}");
Debug.Log($"params: {data.Params}");
SceneManager.LoadScene(data.Path);
};
// Deferred deep link callback (SDK 3.2+: fires once on every app launch)
// - First launch: /v1/open match result delivered within 5s (error on timeout/failure)
// - Non-first launch: called immediately with (null, null) — no network call (same meaning as organic)
ViaLinkSDK.Instance.OnDeferredDeepLink += (data, error) =>
{
if (error != null)
{
Debug.LogWarning($"Deferred match failed: {error.Code}");
return;
}
if (data == null)
{
Debug.Log("Organic or non-first launch — normal entry");
return;
}
Debug.Log($"Deferred deep link: {data.Path}");
SceneManager.LoadScene(data.Path);
};事件跟踪
记录自定义事件。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}");
}
);创建链接
在游戏内创建邀请链接。备用 URL、OG 元标签、渠道/标签/有效期等服务器支持的所有选项都可以通过命名参数传入。
ViaLinkSDK.Instance.CreateLink(
path: "/invite",
data: new Dictionary<string, object>
{
{ "inviter_id", PlayerId },
{ "reward", "gem_50" }
},
campaign: "friend_invite",
linkType: "dynamic", // "dynamic" when you need click tracking (omit for "static")
iosUrl: "https://apps.apple.com/app/id123456",
androidUrl: "https://play.google.com/store/apps/details?id=com.example",
webUrl: "https://www.example.com/invite",
ogTitle: "Invite a Friend — Get a Reward",
ogImageUrl: "https://cdn.example.com/invite.jpg",
channel: "in_game",
feature: "friend_invite",
tags: new List<string> { "invite", "viral" },
expiresAt: "2026-12-31T23:59:59Z",
onSuccess: (shortUrl) =>
{
// shortUrl: "https://tapferry.com/{your-slug}/xYz12"
GUIUtility.systemCopyBuffer = shortUrl;
ShowToast("Invite link copied!");
},
onError: (error) =>
{
Debug.LogError($"Failed to create link: {error}");
}
);安装
在 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 会自动接收深度链接,您只需注册回调。传给 onDeepLink 的 data 不为 null,回调仅在通过深度链接进入时触发(正常启动时不会触发)。
// Deep link callback — void Function(DeepLinkData data), data is non-null (called only on deep link entry)
ViaLinkSDK.instance.onDeepLink((data) {
print('path: ${data.path}');
print('params: ${data.params}');
Navigator.pushNamed(context, data.path,
arguments: data.params);
});
// Deferred deep link callback (SDK 3.2+: called once on every app launch)
// - First launch: /v1/open match result delivered within 5s (error on timeout/failure)
// - Non-first launch: called immediately with (null, null) — no network call (same meaning as organic)
ViaLinkSDK.instance.onDeferredDeepLink((data, error) {
if (error != null) {
debugPrint('Deferred match failed: $error'); // error is String?
return;
}
if (data == null) {
debugPrint('Organic or non-first launch — normal entry');
return;
}
Navigator.pushNamed(context, data.path, arguments: data.params);
});事件跟踪
记录自定义事件。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
}创建链接
在应用内创建深度链接。备用 URL、OG 元标签、渠道/标签/有效期等服务器支持的所有选项都可以通过命名参数传入。
final shortUrl = await ViaLinkSDK.instance.createLink(
path: '/product/12345',
data: {'promo_code': 'FRIEND_SHARE'},
campaign: 'referral',
linkType: 'dynamic', // "dynamic" when you need click tracking (omit for 'static')
iosUrl: 'https://apps.apple.com/app/id123456',
androidUrl: 'https://play.google.com/store/apps/details?id=com.example',
webUrl: 'https://www.example.com/product/12345',
ogTitle: 'Summer Sale',
ogDescription: 'Check it out now!',
ogImageUrl: 'https://cdn.example.com/promo.jpg',
channel: 'email',
feature: 'product_share',
tags: ['summer', 'sale'],
expiresAt: '2026-12-31T23:59:59Z',
);
// shortUrl: "https://tapferry.com/{your-slug}/xYz12"
await Share.share(shortUrl);平台设置
需要分别在 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>