@journium/react 0.1.0-alpha.4 → 0.1.0-alpha.6

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
@@ -427,8 +427,8 @@ const isNode = () => {
427
427
  var _a;
428
428
  return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
429
429
  };
430
- const fetchRemoteConfig = async (apiHost, token, configEndpoint, fetchFn) => {
431
- const endpoint = configEndpoint || '/configs';
430
+ const fetchRemoteConfig = async (apiHost, token, fetchFn) => {
431
+ const endpoint = '/v1/configs';
432
432
  const url = `${apiHost}${endpoint}?ingestion_key=${encodeURIComponent(token)}`;
433
433
  try {
434
434
  let fetch = fetchFn;
@@ -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 {
@@ -688,7 +719,6 @@ class JourniumClient {
688
719
  const localOnlyConfig = {
689
720
  apiHost: this.config.apiHost,
690
721
  token: this.config.token,
691
- configEndpoint: this.config.configEndpoint,
692
722
  };
693
723
  if (cachedConfig) {
694
724
  // Use cached remote config
@@ -737,7 +767,7 @@ class JourniumClient {
737
767
  if (this.config.debug) {
738
768
  console.log('Journium: Fetching remote configuration in background...');
739
769
  }
740
- const remoteConfigResponse = await fetchRemoteConfig(this.config.apiHost, this.config.token, this.config.configEndpoint);
770
+ const remoteConfigResponse = await fetchRemoteConfig(this.config.apiHost, this.config.token);
741
771
  if (remoteConfigResponse && remoteConfigResponse.success) {
742
772
  // Save to cache for next session
743
773
  this.saveCachedConfig(remoteConfigResponse.config);
@@ -745,7 +775,6 @@ class JourniumClient {
745
775
  const localOnlyConfig = {
746
776
  apiHost: this.config.apiHost,
747
777
  token: this.config.token,
748
- configEndpoint: this.config.configEndpoint,
749
778
  };
750
779
  this.config = {
751
780
  ...localOnlyConfig,
@@ -779,7 +808,7 @@ class JourniumClient {
779
808
  if (!events.length)
780
809
  return;
781
810
  try {
782
- const response = await fetch(`${this.config.apiHost}/ingest_event`, {
811
+ const response = await fetch(`${this.config.apiHost}/v1/ingest_event`, {
783
812
  method: 'POST',
784
813
  headers: {
785
814
  'Content-Type': 'application/json',
@@ -803,6 +832,42 @@ class JourniumClient {
803
832
  throw error;
804
833
  }
805
834
  }
835
+ identify(distinctId, attributes = {}) {
836
+ var _a;
837
+ // Don't identify if SDK is not properly configured
838
+ if (!this.config || !this.config.token || !this.config.apiHost || !this.initialized) {
839
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
840
+ console.warn('Journium: identify() call rejected - SDK not ready');
841
+ }
842
+ return;
843
+ }
844
+ // Call identify on identity manager to get previous distinct ID
845
+ const { previousDistinctId } = this.identityManager.identify(distinctId, attributes);
846
+ // Track $identify event with previous distinct ID
847
+ const identifyProperties = {
848
+ ...attributes,
849
+ $anon_distinct_id: previousDistinctId,
850
+ };
851
+ this.track('$identify', identifyProperties);
852
+ if (this.config.debug) {
853
+ console.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
854
+ }
855
+ }
856
+ reset() {
857
+ var _a;
858
+ // Don't reset if SDK is not properly configured
859
+ if (!this.config || !this.config.token || !this.config.apiHost || !this.initialized) {
860
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
861
+ console.warn('Journium: reset() call rejected - SDK not ready');
862
+ }
863
+ return;
864
+ }
865
+ // Reset identity in identity manager
866
+ this.identityManager.reset();
867
+ if (this.config.debug) {
868
+ console.log('Journium: User identity reset');
869
+ }
870
+ }
806
871
  track(event, properties = {}) {
807
872
  var _a;
808
873
  // Don't track if SDK is not properly configured
@@ -819,6 +884,7 @@ class JourniumClient {
819
884
  $device_id: identity === null || identity === void 0 ? void 0 : identity.$device_id,
820
885
  distinct_id: identity === null || identity === void 0 ? void 0 : identity.distinct_id,
821
886
  $session_id: identity === null || identity === void 0 ? void 0 : identity.$session_id,
887
+ $is_identified: (identity === null || identity === void 0 ? void 0 : identity.$user_state) === 'identified',
822
888
  $current_url: typeof window !== 'undefined' ? window.location.href : '',
823
889
  $pathname: typeof window !== 'undefined' ? window.location.pathname : '',
824
890
  ...userAgentInfo,
@@ -1299,6 +1365,12 @@ class Journium {
1299
1365
  track(event, properties) {
1300
1366
  this.client.track(event, properties);
1301
1367
  }
1368
+ identify(distinctId, attributes) {
1369
+ this.client.identify(distinctId, attributes);
1370
+ }
1371
+ reset() {
1372
+ this.client.reset();
1373
+ }
1302
1374
  capturePageview(properties) {
1303
1375
  this.pageviewTracker.capturePageview(properties);
1304
1376
  }
@@ -1368,6 +1440,22 @@ const useTrackEvent = () => {
1368
1440
  }
1369
1441
  }, [journium]);
1370
1442
  };
1443
+ const useIdentify = () => {
1444
+ const { journium } = useJournium();
1445
+ return useCallback((distinctId, attributes) => {
1446
+ if (journium) {
1447
+ journium.identify(distinctId, attributes);
1448
+ }
1449
+ }, [journium]);
1450
+ };
1451
+ const useReset = () => {
1452
+ const { journium } = useJournium();
1453
+ return useCallback(() => {
1454
+ if (journium) {
1455
+ journium.reset();
1456
+ }
1457
+ }, [journium]);
1458
+ };
1371
1459
  const useTrackPageview = () => {
1372
1460
  const { journium } = useJournium();
1373
1461
  return useCallback((properties) => {
@@ -1410,5 +1498,5 @@ const useAutoTrackClicks = (enabled = true, config) => {
1410
1498
  }, [journium, enabled]);
1411
1499
  };
1412
1500
 
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 };
1501
+ 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
1502
  //# sourceMappingURL=index.esm.js.map