@clianta/sdk 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ All notable changes to the Clianta SDK will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.5.0] - 2026-02-28
9
+
10
+ ### Security
11
+ - **Cookie `Secure` flag** — Cookies now include `; Secure` on HTTPS connections, preventing visitor IDs from leaking over plaintext
12
+ - **Open redirect prevention** — `redirectUrl` in popup forms is validated before navigation; blocks `javascript:`, `data:`, and other dangerous protocols
13
+ - **API key browser warning** — Console warning when `apiKey` is used in client-side code (should be server-side only)
14
+ - **HTTPS endpoint warning** — Console warning when `apiEndpoint` uses HTTP in production
15
+ - **Email validation** — `identify()` validates email format before sending to server
16
+ - **Queue moved to sessionStorage** — Event queue no longer persists in localStorage by default (configurable via `persistMode`)
17
+ - **innerHTML → textContent** — Popup form submit button uses safe DOM API
18
+
19
+ ### Fixed
20
+ - **CRITICAL: Double `history.pushState` patching** — ScrollPlugin and PageViewPlugin were both monkey-patching the History API independently, causing double page view events on SPA navigation. ScrollPlugin now listens for a `clianta:navigation` custom event instead
21
+ - **CRITICAL: React `useEffect` re-initialization** — `CliantaProvider` was destroying and recreating the tracker on every render when config was defined inline (object ref changed). Now depends on `config.projectId` (stable string)
22
+ - **React context null on first render** — Switched from `useRef` to `useState` for tracker instance so context re-renders when ready
23
+ - **PopupForms cleanup** — Delay timers and click trigger listeners are now properly tracked and cleaned up on `destroy()`
24
+ - **`reset()` cleanup** — Now clears `contactId` and `pendingIdentify` alongside visitor/session IDs
25
+
26
+ ### Added
27
+ - **Visitor APIs** — `getVisitorProfile()`, `getVisitorActivity()`, `getVisitorTimeline()`, `getVisitorEngagement()` for fetching visitor data from the CRM
28
+ - **Event schema validation** — `registerEventSchema()` validates event properties in debug mode
29
+ - **`persistMode` config** — Choose `'session'` (default), `'local'` (cross-session), or `'none'` for queue persistence
30
+ - **`websiteDomain` property** — Automatically included on all tracked events
31
+ - **Angular integration** — `@clianta/sdk/angular` module
32
+ - **Svelte integration** — `@clianta/sdk/svelte` module
33
+
34
+ ### Changed
35
+ - `CliantaProvider` uses `useState` instead of `useRef` for tracker instance
36
+ - Queue persistence defaults to `sessionStorage` (was `localStorage`)
37
+
8
38
  ## [1.4.0] - 2026-02-27
9
39
 
10
40
  ### Fixed
package/README.md CHANGED
@@ -9,7 +9,8 @@ Professional CRM and tracking SDK for lead generation with **automated email tri
9
9
  - 🤖 **Event Triggers & Automation** - Automated emails, tasks, and webhooks (like Salesforce & HubSpot)
10
10
  - 📧 **Email Notifications** - Send automated emails based on CRM actions
11
11
  - 🔒 **GDPR Compliant** - Built-in consent management
12
- - **Framework Agnostic** - Works with React, Vue, Next.js, or vanilla JavaScript
12
+ - 🔍 **Read-Back APIs** - Fetch visitor profiles, activity, timeline, and engagement metrics
13
+ - ⚡ **Framework Support** - React, Vue, Angular, Svelte, Next.js, or vanilla JavaScript
13
14
 
14
15
  ## Installation
15
16
 
@@ -361,6 +362,60 @@ tracker.reset();
361
362
 
362
363
  ---
363
364
 
365
+ ## Read-Back APIs
366
+
367
+ ### Frontend (Own Visitor Data)
368
+
369
+ Fetch the current visitor's data directly from the SDK:
370
+
371
+ ```typescript
372
+ // Get visitor's CRM profile
373
+ const profile = await tracker.getVisitorProfile();
374
+ console.log(profile?.firstName, profile?.email, profile?.leadScore);
375
+
376
+ // Get recent activity (paginated)
377
+ const activity = await tracker.getVisitorActivity({ limit: 20 });
378
+ activity?.data.forEach(event => {
379
+ console.log(event.eventType, event.eventName, event.timestamp);
380
+ });
381
+
382
+ // Get visitor journey timeline
383
+ const timeline = await tracker.getVisitorTimeline();
384
+ console.log('Total sessions:', timeline?.totalSessions);
385
+ console.log('Time on site:', timeline?.totalTimeSpentSeconds, 'sec');
386
+
387
+ // Get engagement metrics
388
+ const engagement = await tracker.getVisitorEngagement();
389
+ console.log('Score:', engagement?.engagementScore);
390
+ ```
391
+
392
+ ### Server-Side (Full CRM Access via API Key)
393
+
394
+ ```typescript
395
+ import { CRMClient } from '@clianta/sdk';
396
+
397
+ const crm = new CRMClient('https://api.clianta.online', 'workspace-id');
398
+ crm.setApiKey('mm_live_xxxxx');
399
+
400
+ // Look up contact by email
401
+ const contact = await crm.getContactByEmail('user@example.com');
402
+
403
+ // Get contact's activity history
404
+ const activity = await crm.getContactActivity(contact.data._id, { limit: 50 });
405
+
406
+ // Get engagement metrics
407
+ const engagement = await crm.getContactEngagement(contact.data._id);
408
+
409
+ // Search contacts
410
+ const results = await crm.searchContacts('john', { status: 'lead' });
411
+
412
+ // Manage webhooks
413
+ const webhooks = await crm.listWebhooks();
414
+ await crm.createWebhook({ url: 'https://example.com/hook', events: ['contact.created'] });
415
+ ```
416
+
417
+ ---
418
+
364
419
  ## GDPR Compliance
365
420
 
366
421
  ### Wait for Consent