@ordersune/crm-web-sdk 1.0.13 → 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 +249 -249
- package/dist/index.js +1 -5
- package/package.json +38 -24
- package/dist/types/index.js +0 -3
- package/dist/utils/index.js +0 -9
- package/dist/web-sdk.js +0 -583
package/README.md
CHANGED
|
@@ -1,249 +1,249 @@
|
|
|
1
|
-
# Order Sune CRM TypeScript SDK
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @ordersune/crm-web-sdk
|
|
9
|
-
# or
|
|
10
|
-
yarn add @ordersune/crm-web-sdk
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
14
|
-
|
|
15
|
-
### Initialize the SDK
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { WebSDK } from '@ordersune/crm-web-sdk';
|
|
19
|
-
|
|
20
|
-
const crm = new WebSDK({
|
|
21
|
-
apiKey: 'your-api-key',
|
|
22
|
-
endpoint: 'https://api.example.com',
|
|
23
|
-
debug: false,
|
|
24
|
-
batchSize: 10,
|
|
25
|
-
batchInterval: 10000
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Core Features
|
|
30
|
-
|
|
31
|
-
### User Management
|
|
32
|
-
|
|
33
|
-
#### User Identification
|
|
34
|
-
Track both registered and guest users:
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
// Identify a registered user
|
|
38
|
-
crm.identify('user123');
|
|
39
|
-
|
|
40
|
-
// Get current user profile
|
|
41
|
-
const userProfile = crm.getUserProfile();
|
|
42
|
-
|
|
43
|
-
// Clear user data and generate new device ID
|
|
44
|
-
crm.clearUserData();
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Event Tracking
|
|
48
|
-
|
|
49
|
-
#### Basic Event Tracking
|
|
50
|
-
```typescript
|
|
51
|
-
// Simple event
|
|
52
|
-
crm.trackEvent('page_view');
|
|
53
|
-
|
|
54
|
-
// Event with properties
|
|
55
|
-
crm.trackEvent('purchase_completed', {
|
|
56
|
-
productId: 'prod_123',
|
|
57
|
-
amount: 99.99,
|
|
58
|
-
currency: 'USD'
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Event with custom options
|
|
62
|
-
crm.trackEvent('custom_event',
|
|
63
|
-
{ key: 'value' },
|
|
64
|
-
{
|
|
65
|
-
timestamp: '2024-12-28T10:00:00Z',
|
|
66
|
-
requestId: 'req_abc123'
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
```
|
|
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
|
-
|
|
87
|
-
### Custom Attributes
|
|
88
|
-
|
|
89
|
-
Track persistent user attributes that are sent with every batch:
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
crm.trackCustomAttribute('preference_theme', 'dark');
|
|
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();
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Configuration Options
|
|
157
|
-
|
|
158
|
-
### SDKConfig
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
interface SDKConfig {
|
|
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)
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
## Data Types
|
|
171
|
-
|
|
172
|
-
### UserProfile
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
interface UserProfile {
|
|
176
|
-
id: string; // User identifier
|
|
177
|
-
guestUserId?: string; // Guest user identifier
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### EventOptions
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
interface EventOptions {
|
|
185
|
-
timestamp?: string; // Custom event timestamp
|
|
186
|
-
requestId?: string; // Custom request identifier
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### PurchasePayload
|
|
191
|
-
|
|
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
|
|
226
|
-
|
|
227
|
-
## Requirements
|
|
228
|
-
|
|
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+
|
|
240
|
-
|
|
241
|
-
## License
|
|
242
|
-
|
|
243
|
-
MIT License
|
|
244
|
-
|
|
245
|
-
## Support & Documentation
|
|
246
|
-
|
|
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)
|
|
1
|
+
# Order Sune CRM TypeScript SDK
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ordersune/crm-web-sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @ordersune/crm-web-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### Initialize the SDK
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { WebSDK } from '@ordersune/crm-web-sdk';
|
|
19
|
+
|
|
20
|
+
const crm = new WebSDK({
|
|
21
|
+
apiKey: 'your-api-key',
|
|
22
|
+
endpoint: 'https://api.example.com',
|
|
23
|
+
debug: false,
|
|
24
|
+
batchSize: 10,
|
|
25
|
+
batchInterval: 10000
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Core Features
|
|
30
|
+
|
|
31
|
+
### User Management
|
|
32
|
+
|
|
33
|
+
#### User Identification
|
|
34
|
+
Track both registered and guest users:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Identify a registered user
|
|
38
|
+
crm.identify('user123');
|
|
39
|
+
|
|
40
|
+
// Get current user profile
|
|
41
|
+
const userProfile = crm.getUserProfile();
|
|
42
|
+
|
|
43
|
+
// Clear user data and generate new device ID
|
|
44
|
+
crm.clearUserData();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Event Tracking
|
|
48
|
+
|
|
49
|
+
#### Basic Event Tracking
|
|
50
|
+
```typescript
|
|
51
|
+
// Simple event
|
|
52
|
+
crm.trackEvent('page_view');
|
|
53
|
+
|
|
54
|
+
// Event with properties
|
|
55
|
+
crm.trackEvent('purchase_completed', {
|
|
56
|
+
productId: 'prod_123',
|
|
57
|
+
amount: 99.99,
|
|
58
|
+
currency: 'USD'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Event with custom options
|
|
62
|
+
crm.trackEvent('custom_event',
|
|
63
|
+
{ key: 'value' },
|
|
64
|
+
{
|
|
65
|
+
timestamp: '2024-12-28T10:00:00Z',
|
|
66
|
+
requestId: 'req_abc123'
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
```
|
|
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
|
+
|
|
87
|
+
### Custom Attributes
|
|
88
|
+
|
|
89
|
+
Track persistent user attributes that are sent with every batch:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
crm.trackCustomAttribute('preference_theme', 'dark');
|
|
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();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Configuration Options
|
|
157
|
+
|
|
158
|
+
### SDKConfig
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
interface SDKConfig {
|
|
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)
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Data Types
|
|
171
|
+
|
|
172
|
+
### UserProfile
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
interface UserProfile {
|
|
176
|
+
id: string; // User identifier
|
|
177
|
+
guestUserId?: string; // Guest user identifier
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### EventOptions
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
interface EventOptions {
|
|
185
|
+
timestamp?: string; // Custom event timestamp
|
|
186
|
+
requestId?: string; // Custom request identifier
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### PurchasePayload
|
|
191
|
+
|
|
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
|
|
226
|
+
|
|
227
|
+
## Requirements
|
|
228
|
+
|
|
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+
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
MIT License
|
|
244
|
+
|
|
245
|
+
## Support & Documentation
|
|
246
|
+
|
|
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)
|