เริ่มต้นใช้งาน
เพิ่งเริ่มใช้ Tapferry ใช่ไหม เริ่มจากคำถามด้านล่าง สำหรับรายละเอียดการทำงานเพิ่มเติม โปรดดูคู่มือ REST API และ SDK ด้านล่าง
Tapferry เป็นบริการแบบไหน
Tapferry คือโครงสร้างพื้นฐานด้านดีปลิงก์และการระบุแหล่งที่มา (Attribution) ที่รวมทุกคลิกจากแอป เว็บ และแคมเปญโฆษณาของคุณไว้ในลิงก์สั้นเพียงลิงก์เดียว พร้อมติดตามว่าลิงก์นั้นถูกคลิกจากที่ใด และผู้ใช้คนใดติดตั้งแอปและชำระเงินในแอปต่อจากนั้น
ในที่เดียว Tapferry มีทั้งการโฮสต์ไฟล์ยืนยันโดเมนสำหรับ Android App Links และ iOS Universal Links โดยอัตโนมัติ ดีปลิงก์แบบเลื่อนเวลา (Deferred Deep Link) สำหรับผู้ใช้ที่ยังไม่ได้ติดตั้งแอป และการระบุแหล่งที่มาตลอดเส้นทาง คลิก → การติดตั้ง → การชำระเงิน
แตกต่างจากบริการย่อ URL ที่มีอยู่ (เช่น bit.ly) อย่างไร
บริการย่อ URL ทำได้เพียงกำหนดว่าจะ "ส่งคลิกไปที่ไหน" แต่ Tapferry ยังทำสิ่งต่อไปนี้ให้โดยอัตโนมัติด้วย
- แยกเส้นทางตามระบบปฏิบัติการ / เบราว์เซอร์ (iOS · Android · Web)
- ส่งผู้ใช้ที่ติดตั้งแอปแล้วไปยังแอป และส่งผู้ใช้ที่ยังไม่ได้ติดตั้งไปยังสโตร์แอป
- ดีปลิงก์แบบเลื่อนเวลาที่พาผู้ใช้ไปยังหน้าจอที่ตั้งใจไว้ตั้งแต่แรกเมื่อเปิดแอปครั้งแรกหลังติดตั้ง
- การระบุแหล่งที่มาที่จับคู่ คลิก · การติดตั้ง · การชำระเงิน แล้วสรุปผลตามช่องทางโฆษณา / แคมเปญ
รองรับแพลตฟอร์มใดบ้าง
เรามี SDK อย่างเป็นทางการ 6 ตัว และทุกฟีเจอร์ยังใช้งานได้ผ่าน REST API เพียงอย่างเดียวด้วย
- Android — พิกัด Gradle
com.vialink:sdk - iOS — ผลิตภัณฑ์ SPM
ViaLinkCore - Web — npm
vialink-web-sdk - React Native — npm
vialink-react-native-sdk - Unity — UPM (ติดตั้งผ่าน URL ของ GitHub)
- Flutter — pub.dev
vialink_flutter_plugin
สมัครสมาชิกและลงทะเบียนแอปแรกได้อย่างไร
หลังจากสมัครสมาชิกในแดชบอร์ดและเพิ่มแอป ระบบจะออก apiKey และ apiSecret ให้ทันที จากนั้นคุณเริ่มการผสานรวมได้เลยโดยใส่คีย์ลงในโค้ดเริ่มต้นตามคู่มือ SDK
คีย์ API / การยืนยันตัวตน
รับคีย์ API ได้จากที่ไหน
ดูได้ที่แท็บ แอป → SDK ในแดชบอร์ด ระบบจะออกคีย์ให้อัตโนมัติเมื่อคุณสร้างแอป จึงไม่ต้องยื่นขอแยกต่างหาก
API Key กับ API Secret ต่างกันอย่างไร
API Key คือตัวระบุสาธารณะที่ใช้ใน 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 เป็นแบบต่อบัญชีหรือต่อแอป
เป็นแบบต่อแอป (tenant) หนึ่งบัญชีสร้างได้หลายแอป และแต่ละแอปจะได้รับ Key / Secret แยกของตัวเอง
ตัวพิมพ์ใหญ่-เล็กของชื่อเฮดเดอร์ยืนยันตัวตนมีผลหรือไม่
เฮดเดอร์ HTTP ไม่แยกตัวพิมพ์ใหญ่-เล็ก ทั้ง X-API-Key และ x-api-key จะถูกจดจำได้ถูกต้อง
ลิงก์ / โดเมน
กำหนด Short Code เองได้หรือไม่
กำหนดได้ด้วยพารามิเตอร์ customCode ตอนสร้างลิงก์ หากไม่กำหนด ระบบจะสร้างโค้ด base36 ความยาว 6 ตัวอักษรให้อัตโนมัติ
ตรวจสอบโค้ดซ้ำล่วงหน้าได้ด้วย 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เป็นการลบแบบ soft delete ที่บันทึกdeletedAtหากต้องการกู้คืนสามารถทำได้จากหน้าผู้ดูแลระบบ
เชื่อมต่อโดเมนที่กำหนดเอง (เช่น go.mycompany.com) ได้หรือไม่
ลงทะเบียนได้ที่ แอป → โดเมน ในแดชบอร์ด เมื่อตั้งค่าปลายทาง CNAME เป็น edge.tapferry.com แล้ว การยืนยัน DNS และการออกใบรับรอง SSL จะดำเนินการโดยอัตโนมัติ
สถานะของโดเมนจะแสดงตามขั้นตอนต่อไปนี้
pending_dns— รอการยืนยัน DNSdns_verified— ยืนยัน DNS เสร็จแล้วssl_provisioning— กำลังออกใบรับรอง SSLactive— พร้อมใช้งาน
โดเมนที่กำหนดเองใช้ได้ในแพ็กเกจที่มีฟีเจอร์ 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) - การจับคู่เกิดขึ้นแบบซิงโครนัสในตอนที่เรียกขั้นสุดท้าย — ผลลัพธ์จะถูกบันทึกลงคอลัมน์
attributed_*ของตารางpayment_eventsทันที
เนื่องจากไม่ใช่งานแบบชุดที่ทำงานแบบอะซิงโครนัส คุณจึงเห็นผลการระบุแหล่งที่มาได้ทันทีในการตอบกลับของการเรียกนั้น
ใช้โมเดลการระบุแหล่งที่มาแบบใด
เราใช้โมเดลคลิกสุดท้าย (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_idlast_click_install_only— จับคู่การติดตั้งได้ แต่ไม่มีอีเวนต์คลิกerror— การค้นหาในฐานข้อมูลล้มเหลว (มีการส่งการแจ้งเตือนทาง 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 การแตะ "เปิดในแอป" ในเบราว์เซอร์ภายในแอปจะไม่เกิดอะไรขึ้น เพราะไม่มี "ที่อยู่" สำหรับเรียกแอป
- วิธีแก้ — ต้องลงทะเบียน URL Scheme เฉพาะของแอปไว้ในการตั้งค่าแอป (
Info.plist) และต้องใส่ค่า Scheme เดียวกันนั้นในการตั้งค่า SDK ดีปลิงก์ให้ถูกต้องด้วย จึงจะทะลุกำแพงของแพลตฟอร์มแบบปิดและเปิดแอปได้
แก้ไขการตั้งค่า Universal Links แล้ว ทำไมจึงยังไม่มีผลทันที
มีความเป็นไปได้สูงว่าเกิดจากแคช ไม่ใช่การตั้งค่าผิดพลาด Universal Links ทำงานบนโครงสร้างที่ Apple ทำหน้าที่เป็น "ผู้รับรอง" ตัวกลางเพื่อความปลอดภัยและประสิทธิภาพ และข้อมูลนี้ต้องใช้เวลาจริงในการอัปเดต
1. ทำไมจึงไม่มีผลทันที (โครงสร้างแคชสามขั้น)
ข้อมูลต้องผ่านสามขั้นก่อนที่ Universal Links จะทำงาน แต่ละขั้นเก็บข้อมูลไว้นานไม่เท่ากัน
- ขั้นที่ 1 — เซิร์ฟเวอร์ CDN ของ Apple (สูงสุด 48 ชั่วโมง) — Apple ไม่ได้ตรวจการตั้งค่าของทุกแอปทั่วโลกอยู่ตลอดเวลา แต่เก็บข้อมูลไว้ใน CDN (ที่เก็บข้อมูล) ของตัวเองและอัปเดตเป็นรอบประมาณ 24–48 ชั่วโมง
- ขั้นที่ 2 — อุปกรณ์ iOS ของผู้ใช้ (สูงสุด 1 สัปดาห์) — iOS ไม่ได้ถามเซิร์ฟเวอร์ทุกครั้ง แต่เก็บข้อมูลไว้ในเครื่อง ซึ่งโดยทั่วไปจะรีเฟรชประมาณสัปดาห์ละครั้ง
- ขั้นที่ 3 — แคชเบราว์เซอร์ภายในแอปของแต่ละแพลตฟอร์ม — แอปอย่าง Naver หรือ Facebook มีแคชเบราว์เซอร์ของตัวเอง และอาจยังจำการเชื่อมต่อที่ล้มเหลวครั้งก่อนไว้
2. หากต้องการทดสอบทันที (สำหรับการพัฒนา/QA)
หากรอให้แคชของระบบใช้งานจริงหมดอายุไม่ได้ ให้ลองวิธีต่อไปนี้
- วิธีที่ 1 — ใช้โหมดนักพัฒนา (แนะนำที่สุด) — เปิด [การตั้งค่า > นักพัฒนา > Associated Domains Development] บน iPhone เมื่อเติมพารามิเตอร์
?mode=developerต่อท้ายลิงก์ ระบบจะดึงข้อมูลล่าสุดจากเซิร์ฟเวอร์โดยตรงโดยไม่ผ่าน CDN ของ Apple - วิธีที่ 2 — ติดตั้งแอปใหม่ — การลบแล้วติดตั้งแอปใหม่จะรีเซ็ตข้อมูลที่แคชไว้ในเครื่องบางส่วน ทำให้รับการตั้งค่าใหม่ได้
- วิธีที่ 3 — เพิ่มพารามิเตอร์สุ่มต่อท้ายลิงก์ — แทนที่จะใช้
tapferry.com/abcdการเข้าที่อยู่ที่ไม่เคยใช้มาก่อน เช่นtapferry.com/abcd?refresh=1บางครั้งช่วยเลี่ยงแคชได้
การยืนยันตัวตน
การอ่านข้อมูล การสร้างลิงก์ และการรายงานความพยายามชำระเงิน (/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
Base URL สำหรับคำขอ API ทั้งหมด
https://tapferry.comสร้างลิงก์
สร้างดีปลิงก์ใหม่
พารามิเตอร์ของคำขอ
เปรียบเทียบโหมด linkType
- ·
static(ค่าเริ่มต้น) — จุดเข้าเดียวแบบคงที่ หากมีการต่อท้ายโทเค็นที่ URL ที่ออกให้ จะถือเป็น 404 (ป้องกันการจัดทำดัชนีของเครื่องมือค้นหา) - ·
dynamic— การต่อท้าย/yourValueหรือ?key=valueที่ URL ที่ออกให้ จะส่งค่านั้นไปยังประวัติการคลิกและการตอบกลับของ 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)
เมื่อส่งค่าอื่นนอกจาก dynamic/static สำหรับ linkType อย่างชัดเจน (หากไม่ระบุฟิลด์ ระบบจะบันทึกเป็น 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
}ดูลิงก์
ดึงข้อมูลทั้งหมดของลิงก์ที่ระบุ
พารามิเตอร์ใน Path
การตอบกลับ (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-Secret นอกเหนือจาก X-API-Key จึงควรเรียกจากแบ็กเอนด์ของคุณเท่านั้น (ห้ามใส่ 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."
}ลบลิงก์
ลบลิงก์ (soft delete) URL ของลิงก์ที่ถูกลบจะใช้งานไม่ได้อีก เช่นเดียวกับการแก้ไข ต้องใช้เฮดเดอร์ X-Api-Secret และต้องเรียกจากแบ็กเอนด์ของคุณเท่านั้น
พารามิเตอร์ใน Path
ลิงก์ที่มอบหมายให้พาร์ทเนอร์ลบไม่ได้
ลิงก์ติดตามที่มอบหมายให้พาร์ทเนอร์ (มีการตั้ง 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 ใช้ได้หรือไม่ก่อนสร้างลิงก์ การยืนยันตัวตน: ต้องใช้คุกกี้เซสชัน + บทบาทผู้ดูแลขึ้นไปของแอป (tenant)
พารามิเตอร์ใน Query
ตัวอย่างคำขอ
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)
เอนด์พอยต์แบบ Server-to-Server ที่แบ็กเอนด์ของลูกค้าเรียกหลังได้รับ callback จาก PG ไปป์ไลน์การจับคู่ทำงานแบบซิงโครนัส การตอบกลับจึงมีออบเจ็กต์ 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 แบบ idempotent — เรียกซ้ำด้วยสถานะเดียวกัน)
{
"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
ค่าที่เป็นไปได้ 7 ค่าของ attributed.method
การตอบกลับเมื่อเกิดข้อผิดพลาด
ชำระเงินล้มเหลว (S2S)
แบ็กเอนด์ของลูกค้าเรียกหลังได้รับเว็บฮุกการชำระเงินล้มเหลวจาก PG เพื่อการวิเคราะห์ฟันเนล ระบบจะจับคู่แบบเดียวกันและบันทึกลงฐานข้อมูล แต่การตอบกลับจะไม่แสดงออบเจ็กต์ 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 แบบ idempotent)
หากเรียก failed ซ้ำด้วย order_id เดียวกัน ระบบจะจัดการแบบ idempotent (เพื่อรองรับการส่งเว็บฮุกซ้ำของ PG)
{
"success": true,
"payment_event_id": "9876543230",
"idempotent": true
}การตอบกลับ (409 Conflict)
เกิดขึ้นเมื่อเรียก failed สำหรับคำสั่งซื้อที่เป็น succeeded/refunded/canceled อยู่แล้ว
{
"error": "payment already in terminal state",
"existing_status": "succeeded"
}การตอบกลับเมื่อเกิดข้อผิดพลาด
บันทึกคอนเวอร์ชันของพาร์ทเนอร์ — รวมที่ไม่ใช่การชำระเงิน (S2S)
ระบุคอนเวอร์ชัน เช่น การสมัครสมาชิก ลีด และการซื้อ ให้กับ ผลงานของพาร์ทเนอร์โปรโมต (อัตราคอนเวอร์ชัน / ค่าคอมมิชชัน) เรียกแบบ Server-to-Server จากแบ็กเอนด์ของคุณ (ห้ามเรียกจากเบราว์เซอร์ — secret จะรั่วไหล) ส่งค่า ?vlref= ที่ต่อท้าย URL ปลายทางโดยอัตโนมัติเป็น referral_key เพื่อระบุแหล่งที่มาอย่างชัดเจน ส่วนแอปมือถือจะระบุแหล่งที่มาโดยอัตโนมัติผ่าน device_id อีเวนต์ที่กำหนดเองจาก track() ของ SDK จะแสดงเฉพาะในแท็บอีเวนต์และไม่มีผลต่ออัตราคอนเวอร์ชันของพาร์ทเนอร์
เฮดเดอร์ของคำขอ
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 (ไม่มีพาร์ทเนอร์) ค่าคอมมิชชันจะถูกบันทึกตามการตั้งค่าของพาร์ทเนอร์/โปรแกรม ณ เวลาที่เกิดคอนเวอร์ชัน สำหรับการยกเลิก/คืนเงิน ให้เรียก POST /v1/conversions/reverse พร้อม order_id
การตอบกลับเมื่อเกิดข้อผิดพลาด
ยกเลิกคอนเวอร์ชันของพาร์ทเนอร์ (คืนเงิน) — S2S
ยกเลิก (คืนเงิน) คอนเวอร์ชันที่บันทึกผ่าน POST /v1/conversions เรียกแบบ Server-to-Server จากแบ็กเอนด์ของคุณ คอนเวอร์ชันที่ถูกยกเลิกจะเปลี่ยนเป็น 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 — ยกเลิกไปแล้ว
การเรียกซ้ำสำหรับคอนเวอร์ชันที่ยกเลิกไปแล้วจะส่งคืนสถานะเดิมตามที่เป็นอยู่ (idempotent: true)
{
"ok": true,
"conversion_id": "412",
"status": "reversed",
"idempotent": true
}การตอบกลับเมื่อเกิดข้อผิดพลาด
นโยบายการระบุแหล่งที่มา
กฎที่ใช้ตัดสินว่าการชำระเงินสำเร็จ/ล้มเหลวจะถูกระบุให้กับคลิก/การติดตั้งใด ใช้โมเดลคลิกสุดท้าย (last_click) และการจับคู่จะทำแบบซิงโครนัส (eager) เมื่อมีการเรียก /v1/payments/succeeded หรือ /v1/payments/failed ผลการจับคู่จะถูกบันทึกทันทีในคอลัมน์ attributed_* ของตาราง payment_events
การตั้งค่าช่วงเวลา
ช่วงเวลาการระบุแหล่งที่มาเป็นค่านโยบายการดำเนินงานของทั้งบริการที่เก็บไว้ใน SystemConfig ค่าเริ่มต้นด้านล่างใช้กับทุกแอป หากต้องการเปลี่ยน โปรดติดต่อฝ่ายสนับสนุน
ขั้นตอนการจับคู่ (pseudocode)
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 repository สาธารณะ (ไม่ต้องยืนยันตัวตน) แล้วเพิ่ม dependency ใน 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")
}การเริ่มต้นใช้งาน
เริ่มต้น SDK ใน Application.onCreate()
// Application.kt
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
ViaLinkSDK.init(this, "YOUR_API_KEY")
}
}การจัดการดีปลิงก์
ลงทะเบียน callback ของดีปลิงก์และจัดการ Intent ที่ใช้เปิดแอปใน Activity ตั้งแต่ SDK 3.1 ขึ้นไป callback จะทำงานในการเปิดแอปตามปกติด้วย (เช่น แตะไอคอนแอป) โดย 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 เป็นตัวเลือก และ SDK จะเก็บ device_info ให้อัตโนมัติ paymentEventId ในการตอบกลับใช้ระบุวงจรการชำระเงินของ order_id เดียวกัน หลังได้รับ callback จาก 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 meta tag, ช่องทาง/แท็ก/วันหมดอายุ และอื่น ๆ — เป็น named argument ได้ 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 โดยตรงไม่ได้ ใช้ wrapper แบบ Callback/CompletableFuture ตั้งแต่ SDK 1.4.0 ขึ้นไป และส่งตัวเลือกทั้งหมดผ่าน CreateLinkOptions Builder ตั้งแต่ 1.5.0 ขึ้นไป
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
เพิ่ม intent filter ของ App Links ใน AndroidManifest.xml
<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>การติดตั้ง
เพิ่ม Swift Package ใน Xcode
Xcode > File > Add Package Dependencies
URL: https://github.com/aresjoydev/vialink-ios-sdkการเริ่มต้นใช้งาน
เริ่มต้น SDK ใน AppDelegate หรือใน init ของ SwiftUI App
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)
}
}
}
}การจัดการดีปลิงก์
ลงทะเบียน callback ของดีปลิงก์และจัดการ Universal Links ใน SceneDelegate ตั้งแต่ SDK 3.1 ขึ้นไป callback จะทำงานในการเปิดแอปตามปกติด้วย (เช่น แตะไอคอนแอป) โดย 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 แยกจัดการความล้มเหลวจากการตรวจสอบข้อมูลนำเข้ากับข้อผิดพลาดของเครือข่ายได้ หลังได้รับ callback จาก 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 meta tag, ช่องทาง/แท็ก/วันหมดอายุ และอื่น ๆ — เป็น named argument ได้
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 Link
ตั้งค่า Associated Domains ใน Xcode
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 ปัจจุบัน (แบบ synchronous) และค้นหาลิงก์สั้น (resolveLink) Web SDK ไม่มี onDeepLink getDeepLinkData() ถือว่า URL ที่มี path ตั้งแต่สองส่วนขึ้นไปเป็นดีปลิงก์ (path เป็น '/' เสมอ) และเซิร์ฟเวอร์ไม่ต่อพารามิเตอร์ของดีปลิงก์ไปยังปลายทางเว็บ จึงห้ามนำทางตามผลลัพธ์นี้ ให้ใส่ path ของหน้าแบบเต็มใน 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 เมื่อผู้ใช้ออกจากหน้า แล้วรวมผลในแท็บอีเวนต์ของแดชบอร์ด หากต้องการนับคอนเวอร์ชันเป็นผลงานของพาร์ทเนอร์โปรโมชัน (อัตราคอนเวอร์ชัน / ค่าคอมมิชชัน) ให้เรียก POST /v1/conversions แบบเซิร์ฟเวอร์ถึงเซิร์ฟเวอร์แทน track — ส่งค่า ?vlref= ที่ต่อท้าย URL ปลายทางอัตโนมัติเป็น 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() แสดงในแท็บอีเวนต์เท่านั้น และไม่มีผลต่อผลงานของพาร์ทเนอร์โปรโมชัน (อัตราคอนเวอร์ชัน / ค่าคอมมิชชัน) หากต้องการระบุให้พาร์ทเนอร์: เก็บค่า ?vlref= ที่ต่อท้าย URL ปลายทางอัตโนมัติเมื่อผู้ใช้เข้ามาผ่านลิงก์ของพาร์ทเนอร์ แล้วเรียก POST /v1/conversions แบบเซิร์ฟเวอร์ถึงเซิร์ฟเวอร์เมื่อคอนเวอร์ชันได้รับการยืนยัน (type: signup | purchase | lead | custom, order_id แบบ idempotent — ดู 'Record Partner Conversion' ในส่วน 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 ขึ้นไป หลังได้รับ callback จาก 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);
}การสร้างลิงก์
สร้างดีปลิงก์บนเว็บ ส่งตัวเลือกเพิ่มเติม — URL สำรอง, OG meta tag, ช่องทาง/แท็ก/วันหมดอายุ และอื่น ๆ — เป็นอาร์กิวเมนต์ตัวที่ 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การเริ่มต้นใช้งาน
เริ่มต้น SDK ที่ระดับบนสุดของ App.tsx
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>;
}การจัดการดีปลิงก์
ลงทะเบียน callback ของดีปลิงก์ ทำงานเฉพาะเมื่อแอปถูกเปิดผ่านลิงก์และคืนค่า void (ยกเลิกด้วย destroy()) navigate() ของ React Navigation รับชื่อ route จึงต้องแปลง data.path เป็น route
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) เรียก payment.initiated ของ native SDK ฝั่ง Android/iOS ผ่าน native bridge (SDK 2.1.0 ขึ้นไป) หลังได้รับ callback จาก 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การเริ่มต้นใช้งาน
วาง prefab ViaLinkSDK ไว้ในซีนแรกแล้วเริ่มต้นใช้งาน
using Tapferry;
public class GameManager : MonoBehaviour
{
void Start()
{
ViaLinkSDK.Instance.Initialize("YOUR_API_KEY");
}
}การจัดการดีปลิงก์
subscribe อีเวนต์เพื่อจัดการดีปลิงก์ ตั้งแต่ 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 ใช้รูปแบบ callback (onSuccess/onError) (SDK 1.1.0 ขึ้นไป) หลังได้รับ callback จาก 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 meta tag, ช่องทาง/แท็ก/วันหมดอายุ และอื่น ๆ — เป็น named argument ได้
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}");
}
);การติดตั้ง
เพิ่ม dependency ใน 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 รับดีปลิงก์ให้อัตโนมัติ คุณเพียงลงทะเบียน callback ข้อมูลที่ส่งให้ onDeepLink ไม่เป็น null และ callback ทำงานเฉพาะเมื่อเข้าผ่านดีปลิงก์ (ไม่ทำงานในการเปิดแอปตามปกติ)
// 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() เรียก native SDK ผ่านช่องทาง Pigeon หลังได้รับ callback จาก 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 meta tag, ช่องทาง/แท็ก/วันหมดอายุ และอื่น ๆ — เป็น named argument ได้
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>