@grainql/analytics-web 2.8.0 → 3.0.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.
Files changed (61) hide show
  1. package/README.md +36 -3
  2. package/dist/cjs/consent.d.ts +38 -7
  3. package/dist/cjs/consent.d.ts.map +1 -1
  4. package/dist/cjs/consent.js +82 -23
  5. package/dist/cjs/consent.js.map +1 -1
  6. package/dist/cjs/id-manager.d.ts +66 -0
  7. package/dist/cjs/id-manager.d.ts.map +1 -0
  8. package/dist/cjs/id-manager.js +212 -0
  9. package/dist/cjs/id-manager.js.map +1 -0
  10. package/dist/cjs/index.d.ts +12 -8
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/page-tracking.d.ts +6 -0
  14. package/dist/cjs/page-tracking.d.ts.map +1 -1
  15. package/dist/cjs/page-tracking.js +23 -2
  16. package/dist/cjs/page-tracking.js.map +1 -1
  17. package/dist/cjs/react/hooks/useConsent.d.ts +18 -2
  18. package/dist/cjs/react/hooks/useConsent.d.ts.map +1 -1
  19. package/dist/cjs/react/hooks/useConsent.js +52 -1
  20. package/dist/cjs/react/hooks/useConsent.js.map +1 -1
  21. package/dist/consent.d.ts +38 -7
  22. package/dist/consent.d.ts.map +1 -1
  23. package/dist/consent.js +82 -23
  24. package/dist/esm/consent.d.ts +38 -7
  25. package/dist/esm/consent.d.ts.map +1 -1
  26. package/dist/esm/consent.js +82 -23
  27. package/dist/esm/consent.js.map +1 -1
  28. package/dist/esm/id-manager.d.ts +66 -0
  29. package/dist/esm/id-manager.d.ts.map +1 -0
  30. package/dist/esm/id-manager.js +208 -0
  31. package/dist/esm/id-manager.js.map +1 -0
  32. package/dist/esm/index.d.ts +12 -8
  33. package/dist/esm/index.d.ts.map +1 -1
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/page-tracking.d.ts +6 -0
  36. package/dist/esm/page-tracking.d.ts.map +1 -1
  37. package/dist/esm/page-tracking.js +23 -2
  38. package/dist/esm/page-tracking.js.map +1 -1
  39. package/dist/esm/react/hooks/useConsent.d.ts +18 -2
  40. package/dist/esm/react/hooks/useConsent.d.ts.map +1 -1
  41. package/dist/esm/react/hooks/useConsent.js +49 -1
  42. package/dist/esm/react/hooks/useConsent.js.map +1 -1
  43. package/dist/id-manager.d.ts +66 -0
  44. package/dist/id-manager.d.ts.map +1 -0
  45. package/dist/id-manager.js +212 -0
  46. package/dist/index.d.ts +12 -8
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.global.dev.js +310 -81
  49. package/dist/index.global.dev.js.map +4 -4
  50. package/dist/index.global.js +8 -8
  51. package/dist/index.global.js.map +4 -4
  52. package/dist/index.js +72 -44
  53. package/dist/index.mjs +73 -45
  54. package/dist/page-tracking.d.ts +6 -0
  55. package/dist/page-tracking.d.ts.map +1 -1
  56. package/dist/page-tracking.js +23 -2
  57. package/dist/react/hooks/useConsent.d.ts +18 -2
  58. package/dist/react/hooks/useConsent.d.ts.map +1 -1
  59. package/dist/react/hooks/useConsent.js +52 -1
  60. package/dist/react/hooks/useConsent.mjs +49 -1
  61. package/package.json +1 -1
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  /**
3
- * useConsent - Hook for managing user consent
3
+ * useConsent - Hook for managing user consent (v2.0)
4
+ * Updated for new consent modes: cookieless, gdpr-strict, gdpr-opt-out
4
5
  */
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  exports.useConsent = useConsent;
8
+ exports.useConsentMode = useConsentMode;
9
+ exports.useTrackingId = useTrackingId;
10
+ exports.useCanTrack = useCanTrack;
7
11
  const React = require("react");
8
12
  const useGrainAnalytics_1 = require("./useGrainAnalytics");
9
13
  function useConsent() {
@@ -48,3 +52,50 @@ function useConsent() {
48
52
  categories: consentState?.categories ?? [],
49
53
  };
50
54
  }
55
+ /**
56
+ * useConsentMode - Hook to get current consent mode
57
+ * v2.0: Returns 'cookieless' | 'gdpr-strict' | 'gdpr-opt-out'
58
+ */
59
+ function useConsentMode() {
60
+ const client = (0, useGrainAnalytics_1.useGrainAnalytics)();
61
+ const [mode, setMode] = React.useState(null);
62
+ React.useEffect(() => {
63
+ if (!client)
64
+ return;
65
+ // Access internal consent manager via client methods
66
+ // This is a simplified version - mode doesn't change at runtime
67
+ const config = client.config;
68
+ setMode(config?.consentMode ?? 'cookieless');
69
+ }, [client]);
70
+ return mode;
71
+ }
72
+ /**
73
+ * useTrackingId - Hook to get current tracking ID
74
+ * v2.0: Returns daily rotating ID or permanent ID based on consent
75
+ */
76
+ function useTrackingId() {
77
+ const client = (0, useGrainAnalytics_1.useGrainAnalytics)();
78
+ const [trackingId, setTrackingId] = React.useState(null);
79
+ const { consentState } = useConsent();
80
+ React.useEffect(() => {
81
+ if (!client)
82
+ return;
83
+ try {
84
+ const id = client.getEffectiveUserId();
85
+ setTrackingId(id);
86
+ }
87
+ catch (error) {
88
+ console.warn('Failed to get tracking ID:', error);
89
+ }
90
+ }, [client, consentState]); // Re-fetch when consent changes
91
+ return trackingId;
92
+ }
93
+ /**
94
+ * useCanTrack - Hook to check if tracking is allowed
95
+ * v2.0: Always returns true (even cookieless mode allows basic tracking)
96
+ */
97
+ function useCanTrack() {
98
+ const mode = useConsentMode();
99
+ // All modes allow some form of tracking in v2.0
100
+ return mode !== null;
101
+ }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * useConsent - Hook for managing user consent
2
+ * useConsent - Hook for managing user consent (v2.0)
3
+ * Updated for new consent modes: cookieless, gdpr-strict, gdpr-opt-out
3
4
  */
4
5
  import * as React from 'react';
5
6
  import { useGrainAnalytics } from './useGrainAnalytics';
@@ -45,3 +46,50 @@ export function useConsent() {
45
46
  categories: consentState?.categories ?? [],
46
47
  };
47
48
  }
49
+ /**
50
+ * useConsentMode - Hook to get current consent mode
51
+ * v2.0: Returns 'cookieless' | 'gdpr-strict' | 'gdpr-opt-out'
52
+ */
53
+ export function useConsentMode() {
54
+ const client = useGrainAnalytics();
55
+ const [mode, setMode] = React.useState(null);
56
+ React.useEffect(() => {
57
+ if (!client)
58
+ return;
59
+ // Access internal consent manager via client methods
60
+ // This is a simplified version - mode doesn't change at runtime
61
+ const config = client.config;
62
+ setMode(config?.consentMode ?? 'cookieless');
63
+ }, [client]);
64
+ return mode;
65
+ }
66
+ /**
67
+ * useTrackingId - Hook to get current tracking ID
68
+ * v2.0: Returns daily rotating ID or permanent ID based on consent
69
+ */
70
+ export function useTrackingId() {
71
+ const client = useGrainAnalytics();
72
+ const [trackingId, setTrackingId] = React.useState(null);
73
+ const { consentState } = useConsent();
74
+ React.useEffect(() => {
75
+ if (!client)
76
+ return;
77
+ try {
78
+ const id = client.getEffectiveUserId();
79
+ setTrackingId(id);
80
+ }
81
+ catch (error) {
82
+ console.warn('Failed to get tracking ID:', error);
83
+ }
84
+ }, [client, consentState]); // Re-fetch when consent changes
85
+ return trackingId;
86
+ }
87
+ /**
88
+ * useCanTrack - Hook to check if tracking is allowed
89
+ * v2.0: Always returns true (even cookieless mode allows basic tracking)
90
+ */
91
+ export function useCanTrack() {
92
+ const mode = useConsentMode();
93
+ // All modes allow some form of tracking in v2.0
94
+ return mode !== null;
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grainql/analytics-web",
3
- "version": "2.8.0",
3
+ "version": "3.0.0",
4
4
  "description": "Lightweight TypeScript SDK for sending analytics events and managing remote configurations via Grain's REST API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",