cdp-lite-sdk 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/dist/cdp-lite-sdk.umd.js +1080 -656
- package/dist/cdp-lite-sdk.umd.js.map +1 -1
- package/dist/cdp-lite-sdk.umd.min.js +1 -1
- package/dist/cdp-lite-sdk.umd.min.js.map +1 -1
- package/dist/index.cjs.js +1072 -644
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1072 -643
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
- [Quick Start](#quick-start)
|
|
13
13
|
- [Configuration](#configuration)
|
|
14
14
|
- [Security Features](#security-features)
|
|
15
|
+
- [ID Management](#id-management)
|
|
16
|
+
- [User Tracking](#user-tracking)
|
|
15
17
|
- [Core Methods](#core-methods)
|
|
16
18
|
- [Advanced Usage](#advanced-usage)
|
|
17
19
|
- [React Integration](#react-integration)
|
|
@@ -222,6 +224,133 @@ const cdp = new CdpLiteSdk({
|
|
|
222
224
|
|
|
223
225
|
---
|
|
224
226
|
|
|
227
|
+
<h2 id="user-tracking">🆔 ID Management</h2>
|
|
228
|
+
|
|
229
|
+
CDP Lite SDK manages **5 types of IDs** for comprehensive user tracking:
|
|
230
|
+
|
|
231
|
+
### ID Types
|
|
232
|
+
|
|
233
|
+
| ID | Description | Persistence | Usage |
|
|
234
|
+
|----|-------------|-------------|-------|
|
|
235
|
+
| **user_id** | User identifier | Persistent | Set on login |
|
|
236
|
+
| **profile_id** | CDP profile ID | Persistent | From API response |
|
|
237
|
+
| **anonymous_id** | Anonymous visitor | Persistent | Auto-generated |
|
|
238
|
+
| **device_id** | Device identifier | Persistent | Cross-session tracking |
|
|
239
|
+
| **session_id** | Session identifier | Per session | Single visit |
|
|
240
|
+
|
|
241
|
+
### Profile ID Flow
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
// 1. User logs in
|
|
245
|
+
await cdp.identifyUser('user_123', {
|
|
246
|
+
email: 'user@example.com'
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// 2. SDK calls /v1/profiles/track
|
|
250
|
+
// Response: { profile_id: 137455779753893888 }
|
|
251
|
+
|
|
252
|
+
// 3. Profile ID stored automatically
|
|
253
|
+
console.log(cdp.getProfileId()); // 137455779753893888
|
|
254
|
+
|
|
255
|
+
// 4. All events include profile_id
|
|
256
|
+
cdp.track('purchase', { amount: 100 });
|
|
257
|
+
// Event includes: profile_id, device_id, session_id
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Get All IDs
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
const ids = cdp.getUserIdentities();
|
|
264
|
+
console.log(ids);
|
|
265
|
+
// {
|
|
266
|
+
// user_id: 'user_123',
|
|
267
|
+
// profile_id: 137455779753893888,
|
|
268
|
+
// anonymous_id: '550e8400-...',
|
|
269
|
+
// device_id: '7a6f8b2e-...',
|
|
270
|
+
// session_id: 'abc12345-...'
|
|
271
|
+
// }
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### ID Methods
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
// Get specific IDs
|
|
278
|
+
cdp.getUserId() // User ID
|
|
279
|
+
cdp.getProfileId() // Profile ID (from API)
|
|
280
|
+
cdp.getDeviceId() // Device ID (persistent)
|
|
281
|
+
cdp.getSessionId() // Session ID (per session)
|
|
282
|
+
cdp.anonymousId // Anonymous ID
|
|
283
|
+
|
|
284
|
+
// Get all identities
|
|
285
|
+
cdp.getUserIdentities() // All IDs in one object
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**📖 Complete Guide:** [IDS.md](IDS.md)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
<h2 id="user-tracking">👤 User Tracking</h2>
|
|
294
|
+
|
|
295
|
+
### MoEngage-like User API
|
|
296
|
+
|
|
297
|
+
CDP Lite SDK provides MoEngage-compatible methods for user tracking:
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
// Login/Identify user
|
|
301
|
+
await cdp.identifyUser('user_123', {
|
|
302
|
+
full_name: 'John Doe',
|
|
303
|
+
email: 'john@example.com',
|
|
304
|
+
phone: '+84901234567'
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// Update attributes with fluent API
|
|
308
|
+
cdp
|
|
309
|
+
.add_first_name('John')
|
|
310
|
+
.add_last_name('Doe')
|
|
311
|
+
.add_email('john@example.com')
|
|
312
|
+
.add_mobile('+84901234567')
|
|
313
|
+
.add_gender('Male')
|
|
314
|
+
.add_birthday(new Date(1990, 0, 1));
|
|
315
|
+
|
|
316
|
+
// Custom attributes
|
|
317
|
+
cdp.add_user_attribute('membership_level', 'Gold');
|
|
318
|
+
cdp.add_user_attributes({
|
|
319
|
+
loyalty_points: 1500,
|
|
320
|
+
vip_status: true
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// Get user info
|
|
324
|
+
const identities = cdp.getUserIdentities();
|
|
325
|
+
const email = cdp.getUserAttribute('email');
|
|
326
|
+
|
|
327
|
+
// Logout
|
|
328
|
+
await cdp.destroy_session();
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Built-in User Methods
|
|
332
|
+
|
|
333
|
+
| Method | Description |
|
|
334
|
+
|--------|-------------|
|
|
335
|
+
| `identifyUser(id, traits?)` | Login/identify user |
|
|
336
|
+
| `add_first_name(value)` | Add first name |
|
|
337
|
+
| `add_last_name(value)` | Add last name |
|
|
338
|
+
| `add_user_name(value)` | Add full name |
|
|
339
|
+
| `add_email(value)` | Add email |
|
|
340
|
+
| `add_mobile(value)` | Add phone |
|
|
341
|
+
| `add_gender(value)` | Add gender |
|
|
342
|
+
| `add_birthday(value)` | Add date of birth |
|
|
343
|
+
| `add_idcard(value)` | Add ID card |
|
|
344
|
+
| `add_address(value)` | Add address |
|
|
345
|
+
| `add_user_attribute(name, value)` | Add custom attribute |
|
|
346
|
+
| `getUserIdentities()` | Get user identities |
|
|
347
|
+
| `getUserAttribute(name)` | Get specific attribute |
|
|
348
|
+
| `destroy_session()` | Logout user |
|
|
349
|
+
|
|
350
|
+
**📖 Complete Guide:** [USER-TRACKING.md](USER-TRACKING.md)
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
225
354
|
<h2 id="core-methods">📚 Core Methods</h2>
|
|
226
355
|
|
|
227
356
|
### 1. Track Events
|
|
@@ -911,6 +1040,10 @@ MIT License - see LICENSE file for details
|
|
|
911
1040
|
---
|
|
912
1041
|
|
|
913
1042
|
## 🤝 Support
|
|
1043
|
+
- 📖 [Full Documentation](README.md)
|
|
1044
|
+
- 🆔 [ID Management Guide](IDS.md)
|
|
1045
|
+
- 👤 [User Tracking Guide](USER_TRACKING.md)
|
|
1046
|
+
- 🔒 [Security Guide](SECURITY.md)
|
|
914
1047
|
- 📧 Email: vinv@vega.com.vn
|
|
915
1048
|
---
|
|
916
1049
|
|