@clianta/sdk 1.0.0 → 1.1.1

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 CHANGED
@@ -1,303 +1,450 @@
1
- # @clianta/sdk
2
-
3
- Professional CRM and tracking SDK for Clianta - Track visitors, manage contacts, opportunities, and analyze user behavior.
4
-
5
- ## Features
6
-
7
- ### Tracking & Analytics
8
- - **Page Views** - Automatic page view tracking with SPA support
9
- - **Form Tracking** - Auto-detect and track form interactions
10
- - **Scroll Depth** - Track scroll milestones (25%, 50%, 75%, 100%)
11
- - **Click Tracking** - Track button and CTA clicks
12
- - **User Engagement** - Detect active user engagement
13
- - **File Downloads** - Track file downloads
14
- - **Exit Intent** - Detect when users are about to leave
15
- - **Error Tracking** - Capture JavaScript errors (optional)
16
- - **Performance** - Web Vitals and page speed metrics (optional)
17
- - **Auto-Identify** - Automatically identify leads from form submissions
18
- - **Offline Support** - Queue events when offline, send when back
19
-
20
- ### CRM API Client
21
- - **Contacts Management** - Full CRUD operations for contacts
22
- - **Opportunities Management** - Create, update, and track sales opportunities
23
- - **Authenticated Requests** - Secure API access with token authentication
24
- - **Type-Safe** - Full TypeScript support for all CRM operations
25
-
26
- ### Developer Experience
27
- - **Debug Mode** - Verbose logging for troubleshooting
28
- - **TypeScript Support** - Full type definitions included
29
- - **Multiple Formats** - UMD, ESM, and CJS builds
30
- - **Tree-Shakeable** - Import only what you need
31
- - **Zero Dependencies** - Lightweight and fast
1
+ # Clianta SDK
2
+
3
+ Professional CRM and tracking SDK for lead generation. Works with any website or JavaScript framework.
32
4
 
33
5
  ## Installation
34
6
 
35
- ### NPM
7
+ ### NPM / Yarn (React, Next.js, Vue)
36
8
 
37
9
  ```bash
38
10
  npm install @clianta/sdk
11
+ # or
12
+ yarn add @clianta/sdk
39
13
  ```
40
14
 
41
- ### Script Tag (CDN)
15
+ ### Script Tag (HTML, WordPress, Webflow)
42
16
 
43
17
  ```html
44
- <script src="https://unpkg.com/@clianta/sdk@1.0.0/dist/clianta.umd.min.js"></script>
45
- <script>
46
- const tracker = Clianta.clianta('YOUR_WORKSPACE_ID');
47
- </script>
18
+ <script src="https://cdn.clianta.online/sdk/v1/clianta.min.js"></script>
48
19
  ```
49
20
 
21
+ ---
22
+
50
23
  ## Quick Start
51
24
 
52
- ### Tracking
25
+ ### Script Tag (Any Website)
53
26
 
54
- ```javascript
27
+ ```html
28
+ <!-- Add before </head> -->
29
+ <script src="https://cdn.clianta.online/sdk/v1/clianta.min.js"></script>
30
+ <script>
31
+ clianta('YOUR_WORKSPACE_ID', {
32
+ apiEndpoint: 'https://api.clianta.online'
33
+ });
34
+ </script>
35
+ ```
36
+
37
+ ### NPM Module
38
+
39
+ ```typescript
55
40
  import { clianta } from '@clianta/sdk';
56
41
 
57
- // Initialize tracker
58
42
  const tracker = clianta('YOUR_WORKSPACE_ID', {
43
+ apiEndpoint: 'https://api.clianta.online',
59
44
  debug: true,
60
- apiEndpoint: 'https://api.clianta.online'
61
45
  });
62
46
 
63
- // Track custom event
64
- tracker.track('custom', 'Button Clicked', {
65
- buttonId: 'signup-cta',
66
- location: 'hero-section',
67
- });
47
+ // Track events
48
+ tracker.track('button_click', 'Signup Button', { location: 'hero' });
68
49
 
69
- // Identify a visitor
70
- tracker.identify('john@example.com', {
71
- firstName: 'John',
72
- lastName: 'Doe',
73
- company: 'Acme Inc',
74
- });
50
+ // Identify users
51
+ tracker.identify('user@example.com', { firstName: 'John' });
52
+ ```
75
53
 
76
- // Manual page view (automatic by default)
77
- tracker.page('Pricing Page', {
78
- plan: 'enterprise',
79
- });
54
+ ---
55
+
56
+ ## Framework Guides
57
+
58
+ ### Next.js (App Router)
59
+
60
+ Create a provider component:
61
+
62
+ ```tsx
63
+ // components/CliantaProvider.tsx
64
+ 'use client';
65
+
66
+ import { useEffect } from 'react';
67
+ import { clianta } from '@clianta/sdk';
68
+
69
+ export function CliantaProvider({ children }: { children: React.ReactNode }) {
70
+ useEffect(() => {
71
+ const tracker = clianta(process.env.NEXT_PUBLIC_WORKSPACE_ID!, {
72
+ apiEndpoint: process.env.NEXT_PUBLIC_API_ENDPOINT,
73
+ debug: process.env.NODE_ENV === 'development',
74
+ });
75
+
76
+ return () => { tracker.flush(); };
77
+ }, []);
78
+
79
+ return <>{children}</>;
80
+ }
80
81
  ```
81
82
 
82
- ### CRM API
83
+ Use in your layout:
83
84
 
84
- ```javascript
85
- import { CRMClient } from '@clianta/sdk';
85
+ ```tsx
86
+ // app/layout.tsx
87
+ import { CliantaProvider } from '@/components/CliantaProvider';
88
+
89
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
90
+ return (
91
+ <html lang="en">
92
+ <body>
93
+ <CliantaProvider>{children}</CliantaProvider>
94
+ </body>
95
+ </html>
96
+ );
97
+ }
98
+ ```
86
99
 
87
- // Initialize CRM client
88
- const crm = new CRMClient(
89
- 'https://api.clianta.online',
90
- 'YOUR_WORKSPACE_ID',
91
- 'YOUR_AUTH_TOKEN'
92
- );
100
+ Environment variables (`.env.local`):
93
101
 
94
- // Get all contacts
95
- const contacts = await crm.getContacts({
96
- page: 1,
97
- limit: 50,
98
- status: 'lead'
99
- });
102
+ ```bash
103
+ NEXT_PUBLIC_WORKSPACE_ID=your-workspace-id
104
+ NEXT_PUBLIC_API_ENDPOINT=https://api.clianta.online
105
+ ```
100
106
 
101
- // Create a new contact
102
- const newContact = await crm.createContact({
103
- email: 'jane@example.com',
104
- firstName: 'Jane',
105
- lastName: 'Smith',
106
- company: 'Tech Corp'
107
- });
107
+ ---
108
108
 
109
- // Create an opportunity
110
- const opportunity = await crm.createOpportunity({
111
- contactId: newContact.data._id,
112
- pipelineId: 'pipeline-id',
113
- stageId: 'stage-id',
114
- title: 'Enterprise Deal',
115
- value: 50000,
116
- currency: 'USD'
117
- });
109
+ ### React (Vite / CRA)
118
110
 
119
- // Update opportunity stage
120
- await crm.moveOpportunity(opportunity.data._id, 'new-stage-id');
111
+ ```tsx
112
+ // App.tsx
113
+ import { useEffect } from 'react';
114
+ import { clianta } from '@clianta/sdk';
115
+
116
+ function App() {
117
+ useEffect(() => {
118
+ const tracker = clianta(import.meta.env.VITE_WORKSPACE_ID, {
119
+ apiEndpoint: import.meta.env.VITE_API_ENDPOINT,
120
+ });
121
+
122
+ return () => { tracker.flush(); };
123
+ }, []);
124
+
125
+ return <div>Your App</div>;
126
+ }
121
127
  ```
122
128
 
129
+ Track events in components:
130
+
131
+ ```tsx
132
+ import { clianta } from '@clianta/sdk';
133
+
134
+ function SignupButton() {
135
+ const handleClick = () => {
136
+ const tracker = clianta(import.meta.env.VITE_WORKSPACE_ID);
137
+ tracker.track('button_click', 'Signup CTA', { location: 'navbar' });
138
+ };
139
+
140
+ return <button onClick={handleClick}>Sign Up</button>;
141
+ }
142
+ ```
143
+
144
+ ---
145
+
146
+ ### Vue.js
147
+
148
+ ```typescript
149
+ // plugins/clianta.ts
150
+ import { clianta } from '@clianta/sdk';
151
+
152
+ export default {
153
+ install(app: any) {
154
+ const tracker = clianta(import.meta.env.VITE_WORKSPACE_ID, {
155
+ apiEndpoint: import.meta.env.VITE_API_ENDPOINT,
156
+ });
157
+
158
+ app.config.globalProperties.$clianta = tracker;
159
+ app.provide('clianta', tracker);
160
+ }
161
+ };
162
+ ```
163
+
164
+ ```vue
165
+ <script setup>
166
+ import { inject } from 'vue';
167
+ const tracker = inject('clianta');
168
+
169
+ const trackClick = () => {
170
+ tracker.track('button_click', 'CTA Clicked');
171
+ };
172
+ </script>
173
+ ```
174
+
175
+ ---
176
+
177
+ ### Plain HTML / WordPress / Webflow
178
+
179
+ ```html
180
+ <!DOCTYPE html>
181
+ <html>
182
+ <head>
183
+ <title>My Website</title>
184
+
185
+ <!-- Clianta SDK -->
186
+ <script src="https://cdn.clianta.online/sdk/v1/clianta.min.js"></script>
187
+ <script>
188
+ var tracker = clianta('YOUR_WORKSPACE_ID', {
189
+ apiEndpoint: 'https://api.clianta.online'
190
+ });
191
+ </script>
192
+ </head>
193
+ <body>
194
+ <button onclick="tracker.track('button_click', 'CTA Clicked')">
195
+ Click Me
196
+ </button>
197
+ </body>
198
+ </html>
199
+ ```
200
+
201
+ **WordPress**: Add to `Appearance > Theme Editor > header.php` before `</head>`
202
+
203
+ **Webflow**: Add to `Project Settings > Custom Code > Head Code`
204
+
205
+ **Shopify**: Add to `Online Store > Themes > Edit Code > theme.liquid`
206
+
207
+ ---
208
+
123
209
  ## Configuration
124
210
 
125
211
  ```typescript
126
- const tracker = clianta('YOUR_WORKSPACE_ID', {
127
- // Backend API URL (auto-detected by default)
212
+ const tracker = clianta('WORKSPACE_ID', {
213
+ // API endpoint (required for self-hosted)
128
214
  apiEndpoint: 'https://api.clianta.online',
129
-
130
- // Enable debug logging
215
+
216
+ // Debug mode (console logging)
131
217
  debug: false,
132
-
133
- // Auto-track page views
218
+
219
+ // Auto track page views
134
220
  autoPageView: true,
135
-
136
- // Plugins to enable (default: all core plugins)
221
+
222
+ // Plugins to enable
137
223
  plugins: [
138
- 'pageView',
139
- 'forms',
140
- 'scroll',
141
- 'clicks',
142
- 'engagement',
143
- 'downloads',
144
- 'exitIntent',
145
- // Optional:
146
- // 'errors',
147
- // 'performance',
224
+ 'pageView', // Page views with SPA support
225
+ 'forms', // Auto-detect forms
226
+ 'scroll', // Scroll depth tracking
227
+ 'clicks', // Button/CTA clicks
228
+ 'engagement', // User engagement
229
+ 'downloads', // File downloads
230
+ 'exitIntent', // Exit intent detection
231
+ 'errors', // JavaScript errors (optional)
232
+ 'performance', // Web Vitals (optional)
148
233
  ],
149
-
150
- // Session timeout (default: 30 minutes)
234
+
235
+ // Session timeout (30 min default)
151
236
  sessionTimeout: 30 * 60 * 1000,
152
-
153
- // Batch size before sending (default: 10)
237
+
238
+ // Events per batch
154
239
  batchSize: 10,
155
-
156
- // Flush interval in ms (default: 5000)
240
+
241
+ // Flush interval (ms)
157
242
  flushInterval: 5000,
243
+
244
+ // GDPR Consent Configuration
245
+ consent: {
246
+ waitForConsent: true, // Buffer events until consent
247
+ anonymousMode: true, // Use anonymous ID until consent
248
+ },
249
+
250
+ // Cookie-less mode (GDPR friendly)
251
+ cookielessMode: false,
158
252
  });
159
253
  ```
160
254
 
255
+ ---
256
+
161
257
  ## API Reference
162
258
 
163
- ### Tracker Methods
259
+ ### `tracker.track(eventType, eventName, properties?)`
164
260
 
165
- #### `tracker.track(eventType, eventName, properties?)`
166
- Track a custom event.
261
+ Track custom events:
167
262
 
168
- #### `tracker.identify(email, traits?)`
169
- Identify a visitor and link to a contact.
263
+ ```typescript
264
+ tracker.track('button_click', 'Add to Cart', {
265
+ productId: '123',
266
+ price: 29.99,
267
+ });
268
+ ```
170
269
 
171
- #### `tracker.page(name?, properties?)`
172
- Track a page view (automatic by default).
270
+ ### `tracker.identify(email, traits?)`
173
271
 
174
- #### `tracker.debug(enabled)`
175
- Enable or disable debug mode.
272
+ Identify a visitor:
176
273
 
177
- #### `tracker.getVisitorId()`
178
- Get the current visitor ID.
274
+ ```typescript
275
+ tracker.identify('john@example.com', {
276
+ firstName: 'John',
277
+ lastName: 'Doe',
278
+ company: 'Acme Inc',
279
+ phone: '+1234567890',
280
+ });
281
+ ```
179
282
 
180
- #### `tracker.getSessionId()`
181
- Get the current session ID.
283
+ ### `tracker.page(name?, properties?)`
182
284
 
183
- #### `tracker.flush()`
184
- Force send all queued events.
285
+ Track page views manually:
185
286
 
186
- #### `tracker.reset()`
187
- Reset visitor data (call on logout).
287
+ ```typescript
288
+ tracker.page('Pricing Page', { plan: 'enterprise' });
289
+ ```
188
290
 
189
- ### CRM Client Methods
291
+ ### `tracker.consent(state)`
190
292
 
191
- #### Contacts
192
- - `getContacts(params?)` - Get all contacts with pagination
193
- - `getContact(contactId)` - Get a single contact
194
- - `createContact(contact)` - Create a new contact
195
- - `updateContact(contactId, updates)` - Update a contact
196
- - `deleteContact(contactId)` - Delete a contact
293
+ Update consent state (GDPR):
197
294
 
198
- #### Opportunities
199
- - `getOpportunities(params?)` - Get all opportunities with pagination
200
- - `getOpportunity(opportunityId)` - Get a single opportunity
201
- - `createOpportunity(opportunity)` - Create a new opportunity
202
- - `updateOpportunity(opportunityId, updates)` - Update an opportunity
203
- - `deleteOpportunity(opportunityId)` - Delete an opportunity
204
- - `moveOpportunity(opportunityId, stageId)` - Move opportunity to a different stage
295
+ ```typescript
296
+ tracker.consent({
297
+ analytics: true,
298
+ marketing: false,
299
+ personalization: true,
300
+ });
301
+ ```
205
302
 
206
- ## Framework Integration
303
+ ### `tracker.getConsentState()`
207
304
 
208
- ### React
305
+ Get current consent:
209
306
 
210
- ```tsx
211
- import { useEffect } from 'react';
212
- import { clianta } from '@clianta/sdk';
307
+ ```typescript
308
+ const state = tracker.getConsentState();
309
+ // { analytics: true, marketing: false, personalization: false }
310
+ ```
213
311
 
214
- function App() {
215
- useEffect(() => {
216
- const tracker = clianta('YOUR_WORKSPACE_ID', {
217
- debug: process.env.NODE_ENV === 'development'
218
- });
312
+ ### `tracker.deleteData()`
219
313
 
220
- return () => {
221
- tracker.flush();
222
- };
223
- }, []);
314
+ Delete all stored data (GDPR right-to-erasure):
224
315
 
225
- return <div>Your App</div>;
226
- }
316
+ ```typescript
317
+ tracker.deleteData();
227
318
  ```
228
319
 
229
- ### Next.js
320
+ ### `tracker.debug(enabled)`
230
321
 
231
- ```tsx
232
- // app/layout.tsx or pages/_app.tsx
233
- import { clianta } from '@clianta/sdk';
322
+ Toggle debug mode:
234
323
 
235
- if (typeof window !== 'undefined') {
236
- clianta('YOUR_WORKSPACE_ID');
237
- }
324
+ ```typescript
325
+ tracker.debug(true); // Enable console logging
238
326
  ```
239
327
 
240
- ### Vue.js
328
+ ### `tracker.getVisitorId()` / `tracker.getSessionId()`
241
329
 
242
- ```vue
243
- <script setup>
244
- import { onMounted, onUnmounted } from 'vue';
245
- import { clianta } from '@clianta/sdk';
330
+ Get current IDs:
331
+
332
+ ```typescript
333
+ const visitorId = tracker.getVisitorId();
334
+ const sessionId = tracker.getSessionId();
335
+ ```
246
336
 
247
- let tracker;
337
+ ### `tracker.flush()`
248
338
 
249
- onMounted(() => {
250
- tracker = clianta('YOUR_WORKSPACE_ID');
251
- });
339
+ Force send queued events:
340
+
341
+ ```typescript
342
+ await tracker.flush();
343
+ ```
344
+
345
+ ### `tracker.reset()`
346
+
347
+ Reset visitor (for logout):
252
348
 
253
- onUnmounted(() => {
254
- tracker?.flush();
349
+ ```typescript
350
+ tracker.reset();
351
+ ```
352
+
353
+ ---
354
+
355
+ ## GDPR Compliance
356
+
357
+ ### Wait for Consent
358
+
359
+ Buffer all events until user grants consent:
360
+
361
+ ```typescript
362
+ const tracker = clianta('WORKSPACE_ID', {
363
+ consent: {
364
+ waitForConsent: true,
365
+ },
255
366
  });
256
- </script>
367
+
368
+ // Events are buffered...
369
+ tracker.track('page_view', 'Home');
370
+
371
+ // User accepts cookies
372
+ tracker.consent({ analytics: true });
373
+ // Buffered events are now sent
257
374
  ```
258
375
 
259
- ## TypeScript Support
376
+ ### Anonymous Mode
260
377
 
261
- The SDK is written in TypeScript and includes full type definitions:
378
+ Track without persistent visitor ID until consent:
262
379
 
263
380
  ```typescript
264
- import type {
265
- TrackerCore,
266
- Contact,
267
- Opportunity,
268
- ApiResponse
269
- } from '@clianta/sdk';
381
+ const tracker = clianta('WORKSPACE_ID', {
382
+ consent: {
383
+ anonymousMode: true,
384
+ },
385
+ });
270
386
 
271
- const tracker: TrackerCore = clianta('workspace-id');
387
+ // Uses temporary anon_xxx ID
388
+ tracker.track('page_view', 'Home');
272
389
 
273
- const response: ApiResponse<Contact> = await crm.getContact('contact-id');
390
+ // User accepts - upgrades to persistent ID
391
+ tracker.consent({ analytics: true });
274
392
  ```
275
393
 
276
- ## Development
394
+ ### Cookie-less Mode
277
395
 
278
- ```bash
279
- # Install dependencies
280
- npm install
396
+ No persistent storage (session only):
281
397
 
282
- # Build
283
- npm run build
398
+ ```typescript
399
+ const tracker = clianta('WORKSPACE_ID', {
400
+ cookielessMode: true,
401
+ });
402
+ // Visitor ID stored in sessionStorage only
403
+ ```
284
404
 
285
- # Watch mode
286
- npm run build:watch
405
+ ### Data Deletion
287
406
 
288
- # Run tests
289
- npm test
407
+ Allow users to delete their data:
290
408
 
291
- # Type check
292
- npm run typecheck
409
+ ```typescript
410
+ function handleDeleteDataRequest() {
411
+ tracker.deleteData();
412
+ showConfirmation('Your data has been deleted');
413
+ }
293
414
  ```
294
415
 
295
- ## License
416
+ ---
417
+
418
+ ## TypeScript
419
+
420
+ Full TypeScript support included:
421
+
422
+ ```typescript
423
+ import {
424
+ clianta,
425
+ type TrackerCore,
426
+ type MorrisBConfig,
427
+ type ConsentState,
428
+ type TrackingEvent,
429
+ } from '@clianta/sdk';
430
+ ```
431
+
432
+ ---
433
+
434
+ ## Self-Hosted
435
+
436
+ For self-hosted deployments, configure the API endpoint:
437
+
438
+ ```typescript
439
+ const tracker = clianta('WORKSPACE_ID', {
440
+ apiEndpoint: 'https://your-backend.com',
441
+ });
442
+ ```
296
443
 
297
- MIT © Clianta
444
+ ---
298
445
 
299
446
  ## Support
300
447
 
301
448
  - Documentation: https://docs.clianta.online
302
- - Issues: https://github.com/xeet991fx/cliantaSDK/issues
303
- - Website: https://clianta.online
449
+ - Issues: https://github.com/clianta/sdk/issues
450
+ - Email: support@clianta.online