Skip to content

Commit 54219d5

Browse files
committed
feat: TikTok Business SDK
1 parent 754d7fb commit 54219d5

2 files changed

Lines changed: 252 additions & 0 deletions

File tree

content/plugins/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ A collection of high-quality NativeScript plugins from nStudio. Native performan
3333
- [Aptabase](/plugins/aptabase) - Privacy-first analytics
3434
- [Dynatrace](/plugins/dynatrace) - Application performance monitoring
3535
- [Appcues](/plugins/appcues) - In-app experiences and onboarding
36+
- [TikTok](/plugins/tiktok) - TikTok Business SDK App Events tracking
3637

3738
## Deep Linking & Attribution
3839

content/plugins/tiktok.md

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# TikTok
2+
3+
TikTok Business SDK (App Events) integration for NativeScript apps.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @nstudio/nativescript-tiktok
9+
```
10+
11+
## Prerequisites
12+
13+
Before initializing the SDK, make sure you have:
14+
15+
- A TikTok Business account
16+
- Access Token
17+
- App ID
18+
- TikTok App ID (single ID or multiple IDs)
19+
20+
Official TikTok docs:
21+
22+
- [TikTok Business SDK / App Events](https://business-api.tiktok.com/portal/docs?id=1739584951798785)
23+
24+
## Usage
25+
26+
### Initialize SDK
27+
28+
Initialize once when your app launches:
29+
30+
```typescript
31+
import { Application } from '@nativescript/core';
32+
import { BusinessSdk, Config, LogLevel } from '@nstudio/nativescript-tiktok';
33+
34+
Application.on(Application.launchEvent, async () => {
35+
const config = new Config(
36+
'<TIKTOK_ACCESS_TOKEN>',
37+
'<TIKTOK_APP_ID>',
38+
'<TIKTOK_SDK_APP_ID>'
39+
)
40+
.setLogLevel(LogLevel.Warning)
41+
.setFlushTimeInterval(15);
42+
43+
config.debugMode = false;
44+
config.autoTracking = true;
45+
46+
await BusinessSdk.initialize(config);
47+
});
48+
```
49+
50+
If auto tracking is disabled, start tracking manually:
51+
52+
```typescript
53+
BusinessSdk.startTrack();
54+
```
55+
56+
### Identify User
57+
58+
```typescript
59+
BusinessSdk.identify(
60+
'external-user-id',
61+
'username',
62+
'user@example.com',
63+
'+11234567890'
64+
);
65+
```
66+
67+
Clear current user identity:
68+
69+
```typescript
70+
BusinessSdk.logout();
71+
```
72+
73+
### Track Events
74+
75+
Basic event:
76+
77+
```typescript
78+
BusinessSdk.trackEvent({
79+
eventName: 'registration',
80+
eventId: 'evt-001',
81+
event: {
82+
type: 'registration',
83+
method: 'email',
84+
},
85+
});
86+
```
87+
88+
Typed standard event:
89+
90+
```typescript
91+
import { StandardEvent } from '@nstudio/nativescript-tiktok';
92+
93+
BusinessSdk.trackEvent({
94+
eventName: StandardEvent.Purchase,
95+
eventId: 'order-1001',
96+
event: {
97+
type: StandardEvent.Purchase,
98+
content_type: 'product',
99+
content_id: 'sku_42',
100+
description: 'Premium Plan',
101+
currency: 'USD',
102+
value: '9.99',
103+
},
104+
});
105+
```
106+
107+
Flush queued events manually:
108+
109+
```typescript
110+
BusinessSdk.flush();
111+
```
112+
113+
Fetch deferred deep link:
114+
115+
```typescript
116+
const deepLink = await BusinessSdk.fetchDeferredDeepLinkData();
117+
console.log('Deferred deep link:', deepLink);
118+
```
119+
120+
## API Reference
121+
122+
### Enums
123+
124+
#### `LogLevel`
125+
126+
```typescript
127+
enum LogLevel {
128+
None = 0,
129+
Info = 1,
130+
Warning = 2,
131+
Debug = 3,
132+
}
133+
```
134+
135+
#### `StandardEvent`
136+
137+
Supported standard event names include:
138+
139+
- `achieveLevel`
140+
- `addPaymentInfo`
141+
- `addToCart`
142+
- `addToWishlist`
143+
- `adRevenue`
144+
- `checkout`
145+
- `completeTutorial`
146+
- `createGroup`
147+
- `createRole`
148+
- `generateLead`
149+
- `impressionLevelAdRevenue`
150+
- `inAppADClick`
151+
- `inAppADImpr`
152+
- `installApp`
153+
- `joinGroup`
154+
- `launchAPP`
155+
- `login`
156+
- `purchase`
157+
- `rate`
158+
- `registration`
159+
- `search`
160+
- `spendCredits`
161+
- `startTrial`
162+
- `subscribe`
163+
- `unlockAchievement`
164+
- `viewContent`
165+
166+
### `Config`
167+
168+
#### `new Config(accessToken, appId, tiktokAppId)`
169+
170+
Create SDK configuration.
171+
172+
| Param | Type | Description |
173+
| --- | --- | --- |
174+
| `accessToken` | string | TikTok access token |
175+
| `appId` | string | TikTok app ID |
176+
| `tiktokAppId` | string \| string[] | TikTok SDK app ID or IDs |
177+
178+
#### Properties
179+
180+
| Property | Type | Description |
181+
| --- | --- | --- |
182+
| `paymentTracking` | boolean | Enable/disable payment tracking |
183+
| `debugMode` | boolean | Enable/disable debug mode |
184+
| `autoTracking` | boolean | Enable/disable automatic tracking |
185+
| `launchTracking` | boolean | Enable/disable launch tracking |
186+
| `retentionTracking` | boolean | Enable/disable retention tracking |
187+
| `installTracking` | boolean | Enable/disable install tracking |
188+
189+
#### Methods
190+
191+
| Method | Signature | Description |
192+
| --- | --- | --- |
193+
| `setFlushTimeInterval` | `(seconds: number) => this` | Set flush interval |
194+
| `disableAutoEnhancedDataPostbackEvent` | `() => this` | Disable auto enhanced data postback event |
195+
| `setIsLowPerformanceDevice` | `(isLowPerformanceDevice: boolean) => this` | Set low-performance device mode |
196+
| `setLogLevel` | `(level: LogLevel) => this` | Set SDK log level |
197+
198+
### `BusinessSdk`
199+
200+
#### `BusinessSdk.initialize(config)`
201+
202+
Initialize SDK with provided `Config`. Returns `Promise<BusinessSdk>`.
203+
204+
#### `BusinessSdk.startTrack()`
205+
206+
Start tracking manually when auto tracking is disabled.
207+
208+
#### `BusinessSdk.identify(externalId, externalUserName, email, phoneNumber)`
209+
210+
Associate user identity to subsequent events.
211+
212+
#### `BusinessSdk.logout()`
213+
214+
Clear user identity from SDK state.
215+
216+
#### `BusinessSdk.flush()`
217+
218+
Immediately flush queued events.
219+
220+
#### `BusinessSdk.fetchDeferredDeepLinkData()`
221+
222+
Fetch deferred deep link data. Returns `Promise<string>`.
223+
224+
#### `BusinessSdk.trackEvent(options)`
225+
226+
Track custom or standard events.
227+
228+
```typescript
229+
BusinessSdk.trackEvent({
230+
eventName: string;
231+
eventId?: string;
232+
event?: Events;
233+
});
234+
```
235+
236+
### Event Payload Types
237+
238+
The plugin exports typed event interfaces through `Events`, including:
239+
240+
- Generic event (`IEvent`)
241+
- Content events (`AddToCartEvent`, `AddToWishlistEvent`, `CheckoutEvent`, `PurchaseEvent`, `ViewContentEvent`)
242+
- Impression-level ad revenue events for:
243+
- `applovin_max_sdk`
244+
- `ironsource_sdk`
245+
- `admob_sdk`
246+
247+
For full typings, see [index.d.ts](https://github.com/nstudio/nativescript-plugins/blob/main/packages/nativescript-tiktok/index.d.ts).
248+
249+
## License
250+
251+
Apache License Version 2.0

0 commit comments

Comments
 (0)