@clianta/sdk 1.6.1 → 1.6.2
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 +69 -319
- package/dist/angular.cjs.js +32 -7
- package/dist/angular.cjs.js.map +1 -1
- package/dist/angular.d.ts +2 -3
- package/dist/angular.esm.js +32 -7
- package/dist/angular.esm.js.map +1 -1
- package/dist/clianta.cjs.js +32 -4
- package/dist/clianta.cjs.js.map +1 -1
- package/dist/clianta.esm.js +32 -4
- package/dist/clianta.esm.js.map +1 -1
- package/dist/clianta.umd.js +32 -4
- package/dist/clianta.umd.js.map +1 -1
- package/dist/clianta.umd.min.js +2 -2
- package/dist/clianta.umd.min.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/react.cjs.js +51 -55
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.d.ts +17 -39
- package/dist/react.esm.js +51 -55
- package/dist/react.esm.js.map +1 -1
- package/dist/svelte.cjs.js +32 -5
- package/dist/svelte.cjs.js.map +1 -1
- package/dist/svelte.d.ts +2 -1
- package/dist/svelte.esm.js +32 -5
- package/dist/svelte.esm.js.map +1 -1
- package/dist/vue.cjs.js +32 -6
- package/dist/vue.cjs.js.map +1 -1
- package/dist/vue.d.ts +2 -2
- package/dist/vue.esm.js +32 -6
- package/dist/vue.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -167,6 +167,8 @@ interface TrackerCore {
|
|
|
167
167
|
logActivity(data: PublicActivityData): Promise<PublicCrmResult>;
|
|
168
168
|
/** Create an opportunity (e.g., from "Request Demo" forms) */
|
|
169
169
|
createOpportunity(data: PublicOpportunityData): Promise<PublicCrmResult>;
|
|
170
|
+
/** Destroy the tracker instance, flush pending events, and clean up plugins */
|
|
171
|
+
destroy(): Promise<void>;
|
|
170
172
|
}
|
|
171
173
|
interface PublicContactData {
|
|
172
174
|
email: string;
|
|
@@ -226,66 +228,42 @@ interface PublicCrmResult {
|
|
|
226
228
|
}
|
|
227
229
|
|
|
228
230
|
interface CliantaProviderProps {
|
|
229
|
-
/**
|
|
230
|
-
|
|
231
|
+
/** Project/workspace ID — the ONLY required prop */
|
|
232
|
+
projectId: string;
|
|
233
|
+
/** Enable debug logging (default: false) */
|
|
234
|
+
debug?: boolean;
|
|
235
|
+
/** Full config for advanced usage (optional — most users don't need this) */
|
|
236
|
+
config?: Omit<CliantaConfig, 'projectId'>;
|
|
231
237
|
/** React children */
|
|
232
238
|
children: ReactNode;
|
|
233
|
-
/**
|
|
239
|
+
/** Error handler (optional) */
|
|
234
240
|
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
235
241
|
}
|
|
236
242
|
/**
|
|
237
|
-
* CliantaProvider -
|
|
243
|
+
* CliantaProvider — Plug-and-play tracking for React/Next.js
|
|
238
244
|
*
|
|
239
|
-
*
|
|
245
|
+
* Just wrap your app. Everything auto-tracks. Done.
|
|
240
246
|
*
|
|
241
247
|
* @example
|
|
242
|
-
* //
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* const config: CliantaConfig = {
|
|
246
|
-
* projectId: 'your-project-id',
|
|
247
|
-
* apiEndpoint: process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT || 'http://localhost:5000',
|
|
248
|
-
* debug: process.env.NODE_ENV === 'development',
|
|
249
|
-
* };
|
|
250
|
-
*
|
|
251
|
-
* export default config;
|
|
252
|
-
*
|
|
253
|
-
* // In app/layout.tsx or main.tsx:
|
|
254
|
-
* import { CliantaProvider } from '@clianta/sdk/react';
|
|
255
|
-
* import cliantaConfig from '../clianta.config';
|
|
256
|
-
*
|
|
257
|
-
* <CliantaProvider config={cliantaConfig}>
|
|
248
|
+
* // app/layout.tsx — that's it, one line:
|
|
249
|
+
* <CliantaProvider projectId={process.env.NEXT_PUBLIC_CLIANTA_ID!}>
|
|
258
250
|
* {children}
|
|
259
251
|
* </CliantaProvider>
|
|
260
252
|
*/
|
|
261
|
-
declare function CliantaProvider({ config, children, onError }: CliantaProviderProps): react_jsx_runtime.JSX.Element;
|
|
253
|
+
declare function CliantaProvider({ projectId, debug, config, children, onError }: CliantaProviderProps): react_jsx_runtime.JSX.Element;
|
|
262
254
|
/**
|
|
263
|
-
* useClianta
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* const tracker = useClianta();
|
|
267
|
-
* tracker?.track('button_click', 'CTA Button');
|
|
255
|
+
* useClianta — Access the tracker instance
|
|
268
256
|
*/
|
|
269
257
|
declare function useClianta(): TrackerCore | null;
|
|
270
258
|
/**
|
|
271
|
-
* useCliantaReady
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* const { isReady, tracker } = useCliantaReady();
|
|
275
|
-
* if (isReady) {
|
|
276
|
-
* tracker.track('purchase', 'Order', { value: 99 });
|
|
277
|
-
* }
|
|
259
|
+
* useCliantaReady — Check if SDK is initialized
|
|
278
260
|
*/
|
|
279
261
|
declare function useCliantaReady(): {
|
|
280
262
|
isReady: boolean;
|
|
281
263
|
tracker: TrackerCore | null;
|
|
282
264
|
};
|
|
283
265
|
/**
|
|
284
|
-
* useCliantaTrack
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* const track = useCliantaTrack();
|
|
288
|
-
* track('purchase', 'Order Completed', { orderId: '123' });
|
|
266
|
+
* useCliantaTrack — Quick tracking hook
|
|
289
267
|
*/
|
|
290
268
|
declare function useCliantaTrack(): (eventType: string, eventName: string, properties?: Record<string, unknown>) => void;
|
|
291
269
|
|
package/dist/react.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Clianta SDK v1.6.
|
|
2
|
+
* Clianta SDK v1.6.2
|
|
3
3
|
* (c) 2026 Clianta
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -11,7 +11,7 @@ import { createContext, useState, useRef, useEffect, useContext, Component } fro
|
|
|
11
11
|
* @see SDK_VERSION in core/config.ts
|
|
12
12
|
*/
|
|
13
13
|
/** SDK Version */
|
|
14
|
-
const SDK_VERSION = '1.6.
|
|
14
|
+
const SDK_VERSION = '1.6.2';
|
|
15
15
|
/** Default API endpoint — reads from env or falls back to localhost */
|
|
16
16
|
const getDefaultApiEndpoint = () => {
|
|
17
17
|
// Build-time env var (works with Next.js, Vite, CRA, etc.)
|
|
@@ -29,7 +29,7 @@ const getDefaultApiEndpoint = () => {
|
|
|
29
29
|
}
|
|
30
30
|
return 'http://localhost:5000';
|
|
31
31
|
};
|
|
32
|
-
/** Core plugins enabled by default */
|
|
32
|
+
/** Core plugins enabled by default — all auto-track with zero config */
|
|
33
33
|
const DEFAULT_PLUGINS = [
|
|
34
34
|
'pageView',
|
|
35
35
|
'forms',
|
|
@@ -38,6 +38,8 @@ const DEFAULT_PLUGINS = [
|
|
|
38
38
|
'engagement',
|
|
39
39
|
'downloads',
|
|
40
40
|
'exitIntent',
|
|
41
|
+
'errors',
|
|
42
|
+
'performance',
|
|
41
43
|
];
|
|
42
44
|
/** Default configuration values */
|
|
43
45
|
const DEFAULT_CONFIG = {
|
|
@@ -3213,7 +3215,7 @@ function clianta(workspaceId, config) {
|
|
|
3213
3215
|
globalInstance = new Tracker(workspaceId, config);
|
|
3214
3216
|
return globalInstance;
|
|
3215
3217
|
}
|
|
3216
|
-
// Attach to window for <script> tag usage
|
|
3218
|
+
// Attach to window for <script> tag usage + AUTO-INIT
|
|
3217
3219
|
if (typeof window !== 'undefined') {
|
|
3218
3220
|
window.clianta = clianta;
|
|
3219
3221
|
window.Clianta = {
|
|
@@ -3221,21 +3223,47 @@ if (typeof window !== 'undefined') {
|
|
|
3221
3223
|
Tracker,
|
|
3222
3224
|
ConsentManager,
|
|
3223
3225
|
};
|
|
3226
|
+
// ============================================
|
|
3227
|
+
// AUTO-INIT FROM SCRIPT TAG
|
|
3228
|
+
// ============================================
|
|
3229
|
+
// Enables true plug-and-play:
|
|
3230
|
+
// <script src="clianta.min.js" data-project-id="YOUR_ID"></script>
|
|
3231
|
+
// That's it — everything auto-tracks.
|
|
3232
|
+
const autoInit = () => {
|
|
3233
|
+
const scripts = document.querySelectorAll('script[data-project-id]');
|
|
3234
|
+
const script = scripts[scripts.length - 1]; // last matching script
|
|
3235
|
+
if (!script)
|
|
3236
|
+
return;
|
|
3237
|
+
const projectId = script.getAttribute('data-project-id');
|
|
3238
|
+
if (!projectId)
|
|
3239
|
+
return;
|
|
3240
|
+
const debug = script.hasAttribute('data-debug');
|
|
3241
|
+
const instance = clianta(projectId, { debug });
|
|
3242
|
+
// Expose the auto-initialized instance globally
|
|
3243
|
+
window.__clianta = instance;
|
|
3244
|
+
};
|
|
3245
|
+
// Run after DOM is ready
|
|
3246
|
+
if (document.readyState === 'loading') {
|
|
3247
|
+
document.addEventListener('DOMContentLoaded', autoInit);
|
|
3248
|
+
}
|
|
3249
|
+
else {
|
|
3250
|
+
autoInit();
|
|
3251
|
+
}
|
|
3224
3252
|
}
|
|
3225
3253
|
|
|
3226
3254
|
/**
|
|
3227
3255
|
* Clianta SDK - React Integration
|
|
3228
3256
|
*
|
|
3229
|
-
*
|
|
3230
|
-
*
|
|
3257
|
+
* TRUE PLUG-AND-PLAY: Just wrap your app with <CliantaProvider projectId="xxx" />
|
|
3258
|
+
* and everything auto-tracks — page views, forms, clicks, scroll, engagement,
|
|
3259
|
+
* downloads, exit intent, errors, performance. Zero manual code needed.
|
|
3231
3260
|
*/
|
|
3232
3261
|
const CliantaContext = createContext({
|
|
3233
3262
|
tracker: null,
|
|
3234
3263
|
isReady: false,
|
|
3235
3264
|
});
|
|
3236
3265
|
/**
|
|
3237
|
-
* Internal ErrorBoundary
|
|
3238
|
-
* Catches render-time errors in the provider tree.
|
|
3266
|
+
* Internal ErrorBoundary — SDK crashes never break the host app.
|
|
3239
3267
|
*/
|
|
3240
3268
|
class CliantaErrorBoundary extends Component {
|
|
3241
3269
|
constructor(props) {
|
|
@@ -3251,56 +3279,39 @@ class CliantaErrorBoundary extends Component {
|
|
|
3251
3279
|
}
|
|
3252
3280
|
render() {
|
|
3253
3281
|
if (this.state.hasError) {
|
|
3254
|
-
// Render children anyway — SDK failure shouldn't break the host UI
|
|
3255
3282
|
return this.props.fallback ?? this.props.children;
|
|
3256
3283
|
}
|
|
3257
3284
|
return this.props.children;
|
|
3258
3285
|
}
|
|
3259
3286
|
}
|
|
3260
3287
|
/**
|
|
3261
|
-
* CliantaProvider -
|
|
3288
|
+
* CliantaProvider — Plug-and-play tracking for React/Next.js
|
|
3262
3289
|
*
|
|
3263
|
-
*
|
|
3290
|
+
* Just wrap your app. Everything auto-tracks. Done.
|
|
3264
3291
|
*
|
|
3265
3292
|
* @example
|
|
3266
|
-
* //
|
|
3267
|
-
*
|
|
3268
|
-
*
|
|
3269
|
-
* const config: CliantaConfig = {
|
|
3270
|
-
* projectId: 'your-project-id',
|
|
3271
|
-
* apiEndpoint: process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT || 'http://localhost:5000',
|
|
3272
|
-
* debug: process.env.NODE_ENV === 'development',
|
|
3273
|
-
* };
|
|
3274
|
-
*
|
|
3275
|
-
* export default config;
|
|
3276
|
-
*
|
|
3277
|
-
* // In app/layout.tsx or main.tsx:
|
|
3278
|
-
* import { CliantaProvider } from '@clianta/sdk/react';
|
|
3279
|
-
* import cliantaConfig from '../clianta.config';
|
|
3280
|
-
*
|
|
3281
|
-
* <CliantaProvider config={cliantaConfig}>
|
|
3293
|
+
* // app/layout.tsx — that's it, one line:
|
|
3294
|
+
* <CliantaProvider projectId={process.env.NEXT_PUBLIC_CLIANTA_ID!}>
|
|
3282
3295
|
* {children}
|
|
3283
3296
|
* </CliantaProvider>
|
|
3284
3297
|
*/
|
|
3285
|
-
function CliantaProvider({ config, children, onError }) {
|
|
3298
|
+
function CliantaProvider({ projectId, debug, config, children, onError }) {
|
|
3286
3299
|
const [tracker, setTracker] = useState(null);
|
|
3287
3300
|
const [isReady, setIsReady] = useState(false);
|
|
3288
|
-
|
|
3289
|
-
const projectIdRef = useRef(config.projectId);
|
|
3301
|
+
const projectIdRef = useRef(projectId);
|
|
3290
3302
|
useEffect(() => {
|
|
3291
|
-
// Initialize tracker with config
|
|
3292
|
-
const projectId = config.projectId;
|
|
3293
3303
|
if (!projectId) {
|
|
3294
|
-
console.error('[Clianta] Missing projectId
|
|
3304
|
+
console.error('[Clianta] Missing projectId prop on CliantaProvider');
|
|
3295
3305
|
return;
|
|
3296
3306
|
}
|
|
3297
|
-
// Only re-initialize if projectId actually changed
|
|
3298
3307
|
if (projectIdRef.current !== projectId) {
|
|
3299
3308
|
projectIdRef.current = projectId;
|
|
3300
3309
|
}
|
|
3301
3310
|
try {
|
|
3302
|
-
|
|
3303
|
-
|
|
3311
|
+
const options = {
|
|
3312
|
+
debug: debug ?? false,
|
|
3313
|
+
...config, // advanced config overrides
|
|
3314
|
+
};
|
|
3304
3315
|
const instance = clianta(projectId, options);
|
|
3305
3316
|
setTracker(instance);
|
|
3306
3317
|
setIsReady(true);
|
|
@@ -3309,48 +3320,33 @@ function CliantaProvider({ config, children, onError }) {
|
|
|
3309
3320
|
console.error('[Clianta] Failed to initialize SDK:', error);
|
|
3310
3321
|
onError?.(error, { componentStack: '' });
|
|
3311
3322
|
}
|
|
3312
|
-
// Cleanup: flush pending events on unmount
|
|
3313
3323
|
return () => {
|
|
3314
3324
|
tracker?.flush();
|
|
3315
3325
|
setIsReady(false);
|
|
3316
3326
|
};
|
|
3317
3327
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3318
|
-
}, [
|
|
3328
|
+
}, [projectId]);
|
|
3319
3329
|
return (jsx(CliantaErrorBoundary, { onError: onError, children: jsx(CliantaContext.Provider, { value: { tracker, isReady }, children: children }) }));
|
|
3320
3330
|
}
|
|
3321
3331
|
// ============================================
|
|
3322
3332
|
// HOOKS
|
|
3323
3333
|
// ============================================
|
|
3324
3334
|
/**
|
|
3325
|
-
* useClianta
|
|
3326
|
-
*
|
|
3327
|
-
* @example
|
|
3328
|
-
* const tracker = useClianta();
|
|
3329
|
-
* tracker?.track('button_click', 'CTA Button');
|
|
3335
|
+
* useClianta — Access the tracker instance
|
|
3330
3336
|
*/
|
|
3331
3337
|
function useClianta() {
|
|
3332
3338
|
const { tracker } = useContext(CliantaContext);
|
|
3333
3339
|
return tracker;
|
|
3334
3340
|
}
|
|
3335
3341
|
/**
|
|
3336
|
-
* useCliantaReady
|
|
3337
|
-
*
|
|
3338
|
-
* @example
|
|
3339
|
-
* const { isReady, tracker } = useCliantaReady();
|
|
3340
|
-
* if (isReady) {
|
|
3341
|
-
* tracker.track('purchase', 'Order', { value: 99 });
|
|
3342
|
-
* }
|
|
3342
|
+
* useCliantaReady — Check if SDK is initialized
|
|
3343
3343
|
*/
|
|
3344
3344
|
function useCliantaReady() {
|
|
3345
3345
|
const { tracker, isReady } = useContext(CliantaContext);
|
|
3346
3346
|
return { isReady, tracker };
|
|
3347
3347
|
}
|
|
3348
3348
|
/**
|
|
3349
|
-
* useCliantaTrack
|
|
3350
|
-
*
|
|
3351
|
-
* @example
|
|
3352
|
-
* const track = useCliantaTrack();
|
|
3353
|
-
* track('purchase', 'Order Completed', { orderId: '123' });
|
|
3349
|
+
* useCliantaTrack — Quick tracking hook
|
|
3354
3350
|
*/
|
|
3355
3351
|
function useCliantaTrack() {
|
|
3356
3352
|
const tracker = useClianta();
|