@ordersune/crm-web-sdk 1.0.12 → 1.0.14
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 +155 -37
- package/dist/index.js +1 -5
- package/dist/types/index.d.ts +1 -10
- package/dist/web-sdk.d.ts +2 -5
- package/package.json +19 -5
- package/dist/types/index.js +0 -3
- package/dist/utils/index.js +0 -9
- package/dist/web-sdk.js +0 -663
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Order Sune CRM TypeScript SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A comprehensive TypeScript SDK for integrating the Order Sune CRM solution into your web applications. Enables seamless user tracking, event monitoring, purchase analytics, in-app messaging, and customer data management.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ npm install @ordersune/crm-web-sdk
|
|
|
10
10
|
yarn add @ordersune/crm-web-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Quick Start
|
|
14
14
|
|
|
15
15
|
### Initialize the SDK
|
|
16
16
|
|
|
@@ -20,32 +20,35 @@ import { WebSDK } from '@ordersune/crm-web-sdk';
|
|
|
20
20
|
const crm = new WebSDK({
|
|
21
21
|
apiKey: 'your-api-key',
|
|
22
22
|
endpoint: 'https://api.example.com',
|
|
23
|
-
debug: false
|
|
23
|
+
debug: false,
|
|
24
|
+
batchSize: 10,
|
|
25
|
+
batchInterval: 10000
|
|
24
26
|
});
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
## Core Features
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
### User Management
|
|
32
|
+
|
|
33
|
+
#### User Identification
|
|
34
|
+
Track both registered and guest users:
|
|
30
35
|
|
|
31
36
|
```typescript
|
|
32
37
|
// Identify a registered user
|
|
33
|
-
crm.identify('user123'
|
|
34
|
-
email: 'user@example.com',
|
|
35
|
-
name: 'John Doe',
|
|
36
|
-
subscription: 'premium'
|
|
37
|
-
});
|
|
38
|
+
crm.identify('user123');
|
|
38
39
|
|
|
39
40
|
// Get current user profile
|
|
40
41
|
const userProfile = crm.getUserProfile();
|
|
42
|
+
|
|
43
|
+
// Clear user data and generate new device ID
|
|
44
|
+
crm.clearUserData();
|
|
41
45
|
```
|
|
42
46
|
|
|
43
47
|
### Event Tracking
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
#### Basic Event Tracking
|
|
47
50
|
```typescript
|
|
48
|
-
//
|
|
51
|
+
// Simple event
|
|
49
52
|
crm.trackEvent('page_view');
|
|
50
53
|
|
|
51
54
|
// Event with properties
|
|
@@ -65,34 +68,113 @@ crm.trackEvent('custom_event',
|
|
|
65
68
|
);
|
|
66
69
|
```
|
|
67
70
|
|
|
71
|
+
#### Purchase Tracking
|
|
72
|
+
Track detailed purchase events:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
crm.logProductPurchase(
|
|
76
|
+
'order_123', // orderId
|
|
77
|
+
'item_456', // itemId
|
|
78
|
+
'Premium Widget', // itemName
|
|
79
|
+
29.99, // unitPrice
|
|
80
|
+
2, // quantity
|
|
81
|
+
'web', // source
|
|
82
|
+
'direct', // channel
|
|
83
|
+
'electronics' // itemCategory (optional)
|
|
84
|
+
);
|
|
85
|
+
```
|
|
86
|
+
|
|
68
87
|
### Custom Attributes
|
|
69
88
|
|
|
70
|
-
Track persistent user attributes:
|
|
89
|
+
Track persistent user attributes that are sent with every batch:
|
|
71
90
|
|
|
72
91
|
```typescript
|
|
73
92
|
crm.trackCustomAttribute('preference_theme', 'dark');
|
|
74
93
|
crm.trackCustomAttribute('notification_enabled', true);
|
|
94
|
+
crm.trackCustomAttribute('user_tier', 'premium');
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Push Notifications
|
|
98
|
+
|
|
99
|
+
#### Token Management
|
|
100
|
+
```typescript
|
|
101
|
+
// Set push notification token
|
|
102
|
+
crm.setToken('your-push-token');
|
|
103
|
+
|
|
104
|
+
// Log push notification clicks
|
|
105
|
+
crm.logClick('campaign_123');
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### In-App Messaging
|
|
109
|
+
|
|
110
|
+
Display rich in-app messages with customizable styling:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const messageData = JSON.stringify({
|
|
114
|
+
header: "Welcome!",
|
|
115
|
+
message: "Check out our new features",
|
|
116
|
+
modal: {
|
|
117
|
+
button1: {
|
|
118
|
+
type: "Continue",
|
|
119
|
+
backgroundColor: "#007AFF",
|
|
120
|
+
textColor: "#FFFFFF",
|
|
121
|
+
borderColor: "#007AFF",
|
|
122
|
+
webOnClickValue: "redirect_to_web_url",
|
|
123
|
+
webOnClickAction: "https://example.com"
|
|
124
|
+
},
|
|
125
|
+
button2: {
|
|
126
|
+
type: "Skip",
|
|
127
|
+
backgroundColor: "#F2F2F2",
|
|
128
|
+
textColor: "#000000",
|
|
129
|
+
borderColor: "#CCCCCC"
|
|
130
|
+
},
|
|
131
|
+
dismissMessageAutomatically: true,
|
|
132
|
+
dismissMessageInSeconds: "10",
|
|
133
|
+
headerColor: "#000000",
|
|
134
|
+
messageColor: "#666666",
|
|
135
|
+
closeColor: "#999999"
|
|
136
|
+
},
|
|
137
|
+
mediaConfig: {
|
|
138
|
+
inAppImage: "https://example.com/image.png"
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
crm.displayInAppMessage(messageData, 'campaign_456');
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Batch Processing
|
|
146
|
+
|
|
147
|
+
#### Manual Control
|
|
148
|
+
```typescript
|
|
149
|
+
// Force send all queued events immediately
|
|
150
|
+
await crm.forceSend();
|
|
151
|
+
|
|
152
|
+
// Clean up resources
|
|
153
|
+
crm.dispose();
|
|
75
154
|
```
|
|
76
155
|
|
|
77
|
-
##
|
|
156
|
+
## Configuration Options
|
|
78
157
|
|
|
79
158
|
### SDKConfig
|
|
80
159
|
|
|
81
160
|
```typescript
|
|
82
161
|
interface SDKConfig {
|
|
83
|
-
apiKey: string;
|
|
84
|
-
endpoint: string;
|
|
85
|
-
debug?: boolean;
|
|
162
|
+
apiKey: string; // Your API key (required)
|
|
163
|
+
endpoint: string; // API endpoint URL (required)
|
|
164
|
+
debug?: boolean; // Enable debug logging
|
|
165
|
+
batchSize?: number; // Events per batch (default: 10)
|
|
166
|
+
batchInterval?: number; // Batch interval in ms (default: 10000)
|
|
86
167
|
}
|
|
87
168
|
```
|
|
88
169
|
|
|
170
|
+
## Data Types
|
|
171
|
+
|
|
89
172
|
### UserProfile
|
|
90
173
|
|
|
91
174
|
```typescript
|
|
92
175
|
interface UserProfile {
|
|
93
|
-
id: string;
|
|
94
|
-
|
|
95
|
-
traits: Record<string, any>; // Custom user traits
|
|
176
|
+
id: string; // User identifier
|
|
177
|
+
guestUserId?: string; // Guest user identifier
|
|
96
178
|
}
|
|
97
179
|
```
|
|
98
180
|
|
|
@@ -100,32 +182,68 @@ interface UserProfile {
|
|
|
100
182
|
|
|
101
183
|
```typescript
|
|
102
184
|
interface EventOptions {
|
|
103
|
-
timestamp?: string;
|
|
104
|
-
requestId?: string;
|
|
185
|
+
timestamp?: string; // Custom event timestamp
|
|
186
|
+
requestId?: string; // Custom request identifier
|
|
105
187
|
}
|
|
106
188
|
```
|
|
107
189
|
|
|
108
|
-
|
|
190
|
+
### PurchasePayload
|
|
109
191
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
192
|
+
```typescript
|
|
193
|
+
interface PurchasePayload {
|
|
194
|
+
externalId: string; // Order ID
|
|
195
|
+
itemId: string; // Product/item ID
|
|
196
|
+
itemName: string; // Product name
|
|
197
|
+
unitPrice: number; // Price per unit
|
|
198
|
+
quantity: number; // Number of items
|
|
199
|
+
source: string; // Purchase source
|
|
200
|
+
channel: string; // Purchase channel
|
|
201
|
+
itemCategory?: string; // Product category
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Key Features
|
|
206
|
+
|
|
207
|
+
### Automatic Functionality
|
|
208
|
+
- **Session Management**: Automatic session tracking with device ID generation
|
|
209
|
+
- **Guest User Handling**: Seamless guest-to-registered user transition
|
|
210
|
+
- **Batch Processing**: Efficient event batching with configurable size and interval
|
|
211
|
+
- **Offline Support**: Event queuing when offline with automatic retry
|
|
212
|
+
- **Device Detection**: Automatic platform and device information collection
|
|
213
|
+
- **Timezone Detection**: Automatic timezone detection and tracking
|
|
214
|
+
|
|
215
|
+
### Performance Optimizations
|
|
216
|
+
- **Event Queuing**: Intelligent batching to reduce network requests
|
|
217
|
+
- **Session Storage**: Persistent storage for user data and custom attributes
|
|
218
|
+
- **Error Handling**: Robust error handling with automatic retry mechanisms
|
|
219
|
+
- **Memory Management**: Efficient cleanup and disposal methods
|
|
220
|
+
|
|
221
|
+
### Developer Experience
|
|
222
|
+
- **TypeScript Support**: Full type definitions included
|
|
223
|
+
- **Debug Mode**: Comprehensive logging for development
|
|
224
|
+
- **Flexible Configuration**: Customizable batch sizes and intervals
|
|
225
|
+
- **Modern API**: Promise-based async operations
|
|
116
226
|
|
|
117
227
|
## Requirements
|
|
118
228
|
|
|
119
|
-
- TypeScript 5.0+
|
|
120
|
-
- Modern
|
|
121
|
-
-
|
|
229
|
+
- **TypeScript**: 5.0+
|
|
230
|
+
- **Browser**: Modern browsers with sessionStorage support
|
|
231
|
+
- **Network**: Internet connection for event transmission
|
|
232
|
+
- **Dependencies**: UUID library (automatically installed)
|
|
233
|
+
|
|
234
|
+
## Browser Compatibility
|
|
235
|
+
|
|
236
|
+
- Chrome 60+
|
|
237
|
+
- Firefox 55+
|
|
238
|
+
- Safari 12+
|
|
239
|
+
- Edge 79+
|
|
122
240
|
|
|
123
241
|
## License
|
|
124
242
|
|
|
125
243
|
MIT License
|
|
126
244
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
---
|
|
245
|
+
## Support & Documentation
|
|
130
246
|
|
|
131
|
-
|
|
247
|
+
- [API Documentation](https://docs.ordersune.com/crm)
|
|
248
|
+
- [Support Portal](mailto:support@ordersune.com)
|
|
249
|
+
- [GitHub Issues](https://github.com/ordersune/crm-web-sdk/issues)
|