@journium/react 0.1.0-alpha.3 → 0.1.0-alpha.5

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/dist/hooks.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { AutocaptureConfig } from '@journium/core';
2
2
  export declare const useTrackEvent: () => (event: string, properties?: Record<string, any>) => void;
3
+ export declare const useIdentify: () => (distinctId: string, attributes?: Record<string, any>) => void;
4
+ export declare const useReset: () => () => void;
3
5
  export declare const useTrackPageview: () => (properties?: Record<string, any>) => void;
4
6
  export declare const useAutoTrackPageview: (dependencies?: React.DependencyList, properties?: Record<string, any>) => void;
5
7
  export declare const useAutocapture: () => {
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,eAAO,MAAM,aAAa,gBAId,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOnD,CAAC;AAEF,eAAO,MAAM,gBAAgB,sBAIX,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOpC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,eAAc,KAAK,CAAC,cAAmB,EACvC,aAAa,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOjC,CAAC;AAEF,eAAO,MAAM,cAAc;;;CAgB1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAS,OAAc,EACvB,SAAS,OAAO,CAAC,iBAAiB,CAAC,SAcpC,CAAC"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,eAAO,MAAM,aAAa,gBAId,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOnD,CAAC;AAEF,eAAO,MAAM,WAAW,qBAIP,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOxD,CAAC;AAEF,eAAO,MAAM,QAAQ,kBAQpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sBAIX,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOpC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,eAAc,KAAK,CAAC,cAAmB,EACvC,aAAa,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAOjC,CAAC;AAEF,eAAO,MAAM,cAAc;;;CAgB1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAS,OAAc,EACvB,SAAS,OAAO,CAAC,iBAAiB,CAAC,SAcpC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@ declare const JourniumProvider: React$1.FC<JourniumProviderProps>;
15
15
  declare const useJournium: () => JourniumContextValue;
16
16
 
17
17
  declare const useTrackEvent: () => (event: string, properties?: Record<string, any>) => void;
18
+ declare const useIdentify: () => (distinctId: string, attributes?: Record<string, any>) => void;
19
+ declare const useReset: () => () => void;
18
20
  declare const useTrackPageview: () => (properties?: Record<string, any>) => void;
19
21
  declare const useAutoTrackPageview: (dependencies?: React.DependencyList, properties?: Record<string, any>) => void;
20
22
  declare const useAutocapture: () => {
@@ -23,4 +25,4 @@ declare const useAutocapture: () => {
23
25
  };
24
26
  declare const useAutoTrackClicks: (enabled?: boolean, config?: Partial<AutocaptureConfig>) => void;
25
27
 
26
- export { JourniumProvider, useAutoTrackClicks, useAutoTrackPageview, useAutocapture, useJournium, useTrackEvent, useTrackPageview };
28
+ export { JourniumProvider, useAutoTrackClicks, useAutoTrackPageview, useAutocapture, useIdentify, useJournium, useReset, useTrackEvent, useTrackPageview };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EACnB,MAAM,SAAS,CAAC;AACjB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EACnB,MAAM,SAAS,CAAC;AACjB,cAAc,aAAa,CAAC"}
package/dist/index.esm.js CHANGED
@@ -514,11 +514,16 @@ class BrowserIdentityManager {
514
514
  $device_id: parsedIdentity.$device_id,
515
515
  $session_id: generateUuidv7(),
516
516
  session_timestamp: now,
517
+ $user_state: parsedIdentity.$user_state || 'anonymous',
517
518
  };
518
519
  }
519
520
  else {
520
521
  // Session still valid
521
522
  this.identity = parsedIdentity;
523
+ // Ensure $user_state exists for backward compatibility
524
+ if (!this.identity.$user_state) {
525
+ this.identity.$user_state = 'anonymous';
526
+ }
522
527
  }
523
528
  }
524
529
  else {
@@ -529,6 +534,7 @@ class BrowserIdentityManager {
529
534
  $device_id: newId,
530
535
  $session_id: newId,
531
536
  session_timestamp: Date.now(),
537
+ $user_state: 'anonymous',
532
538
  };
533
539
  }
534
540
  // Save to localStorage
@@ -543,6 +549,7 @@ class BrowserIdentityManager {
543
549
  $device_id: newId,
544
550
  $session_id: newId,
545
551
  session_timestamp: Date.now(),
552
+ $user_state: 'anonymous',
546
553
  };
547
554
  }
548
555
  }
@@ -575,6 +582,30 @@ class BrowserIdentityManager {
575
582
  };
576
583
  this.saveIdentity();
577
584
  }
585
+ identify(distinctId, attributes = {}) {
586
+ if (!this.identity)
587
+ return { previousDistinctId: null };
588
+ const previousDistinctId = this.identity.distinct_id;
589
+ // Update the distinct ID and mark user as identified
590
+ this.identity = {
591
+ ...this.identity,
592
+ distinct_id: distinctId,
593
+ $user_state: 'identified',
594
+ };
595
+ this.saveIdentity();
596
+ return { previousDistinctId };
597
+ }
598
+ reset() {
599
+ if (!this.identity)
600
+ return;
601
+ // Generate new distinct ID but keep device ID
602
+ this.identity = {
603
+ ...this.identity,
604
+ distinct_id: generateUuidv7(),
605
+ $user_state: 'anonymous',
606
+ };
607
+ this.saveIdentity();
608
+ }
578
609
  getUserAgentInfo() {
579
610
  if (!this.isBrowser()) {
580
611
  return {
@@ -803,6 +834,42 @@ class JourniumClient {
803
834
  throw error;
804
835
  }
805
836
  }
837
+ identify(distinctId, attributes = {}) {
838
+ var _a;
839
+ // Don't identify if SDK is not properly configured
840
+ if (!this.config || !this.config.token || !this.config.apiHost || !this.initialized) {
841
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
842
+ console.warn('Journium: identify() call rejected - SDK not ready');
843
+ }
844
+ return;
845
+ }
846
+ // Call identify on identity manager to get previous distinct ID
847
+ const { previousDistinctId } = this.identityManager.identify(distinctId, attributes);
848
+ // Track $identify event with previous distinct ID
849
+ const identifyProperties = {
850
+ ...attributes,
851
+ $anon_distinct_id: previousDistinctId,
852
+ };
853
+ this.track('$identify', identifyProperties);
854
+ if (this.config.debug) {
855
+ console.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
856
+ }
857
+ }
858
+ reset() {
859
+ var _a;
860
+ // Don't reset if SDK is not properly configured
861
+ if (!this.config || !this.config.token || !this.config.apiHost || !this.initialized) {
862
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
863
+ console.warn('Journium: reset() call rejected - SDK not ready');
864
+ }
865
+ return;
866
+ }
867
+ // Reset identity in identity manager
868
+ this.identityManager.reset();
869
+ if (this.config.debug) {
870
+ console.log('Journium: User identity reset');
871
+ }
872
+ }
806
873
  track(event, properties = {}) {
807
874
  var _a;
808
875
  // Don't track if SDK is not properly configured
@@ -819,6 +886,7 @@ class JourniumClient {
819
886
  $device_id: identity === null || identity === void 0 ? void 0 : identity.$device_id,
820
887
  distinct_id: identity === null || identity === void 0 ? void 0 : identity.distinct_id,
821
888
  $session_id: identity === null || identity === void 0 ? void 0 : identity.$session_id,
889
+ $is_identified: (identity === null || identity === void 0 ? void 0 : identity.$user_state) === 'identified',
822
890
  $current_url: typeof window !== 'undefined' ? window.location.href : '',
823
891
  $pathname: typeof window !== 'undefined' ? window.location.pathname : '',
824
892
  ...userAgentInfo,
@@ -1299,6 +1367,12 @@ class Journium {
1299
1367
  track(event, properties) {
1300
1368
  this.client.track(event, properties);
1301
1369
  }
1370
+ identify(distinctId, attributes) {
1371
+ this.client.identify(distinctId, attributes);
1372
+ }
1373
+ reset() {
1374
+ this.client.reset();
1375
+ }
1302
1376
  capturePageview(properties) {
1303
1377
  this.pageviewTracker.capturePageview(properties);
1304
1378
  }
@@ -1368,6 +1442,22 @@ const useTrackEvent = () => {
1368
1442
  }
1369
1443
  }, [journium]);
1370
1444
  };
1445
+ const useIdentify = () => {
1446
+ const { journium } = useJournium();
1447
+ return useCallback((distinctId, attributes) => {
1448
+ if (journium) {
1449
+ journium.identify(distinctId, attributes);
1450
+ }
1451
+ }, [journium]);
1452
+ };
1453
+ const useReset = () => {
1454
+ const { journium } = useJournium();
1455
+ return useCallback(() => {
1456
+ if (journium) {
1457
+ journium.reset();
1458
+ }
1459
+ }, [journium]);
1460
+ };
1371
1461
  const useTrackPageview = () => {
1372
1462
  const { journium } = useJournium();
1373
1463
  return useCallback((properties) => {
@@ -1410,5 +1500,5 @@ const useAutoTrackClicks = (enabled = true, config) => {
1410
1500
  }, [journium, enabled]);
1411
1501
  };
1412
1502
 
1413
- export { AutocaptureTracker, BrowserIdentityManager, Journium, JourniumClient, JourniumProvider, PageviewTracker, fetchRemoteConfig, generateId, generateUuidv7, getCurrentTimestamp, getCurrentUrl, getPageTitle, getReferrer, init, isBrowser, isNode, mergeConfigs, useAutoTrackClicks, useAutoTrackPageview, useAutocapture, useJournium, useTrackEvent, useTrackPageview };
1503
+ export { AutocaptureTracker, BrowserIdentityManager, Journium, JourniumClient, JourniumProvider, PageviewTracker, fetchRemoteConfig, generateId, generateUuidv7, getCurrentTimestamp, getCurrentUrl, getPageTitle, getReferrer, init, isBrowser, isNode, mergeConfigs, useAutoTrackClicks, useAutoTrackPageview, useAutocapture, useIdentify, useJournium, useReset, useTrackEvent, useTrackPageview };
1414
1504
  //# sourceMappingURL=index.esm.js.map