@phygitallabs/tapquest-core 6.7.15 → 6.7.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phygitallabs/tapquest-core",
3
- "version": "6.7.15",
3
+ "version": "6.7.16",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/index.ts CHANGED
@@ -35,5 +35,7 @@ export * from "./modules/action-logs";
35
35
 
36
36
  export * from "./modules/consent";
37
37
 
38
+
39
+
38
40
  // Export types
39
41
  export * from "./types/common";
@@ -3,5 +3,5 @@ export {
3
3
  usePhygitalConsent,
4
4
  useLatestConsentByUserId,
5
5
  CookieConsentBanner,
6
- PolicyPopup
7
- } from "@phygitallabs/phygital-consent";
6
+ PolicyPopup,
7
+ } from "@phygitallabs/phygital-consent";
@@ -33,7 +33,8 @@ export function DataTrackingConsentSync() {
33
33
  };
34
34
  const isAnalyticsAllowed = consent.isAnalyticsAllowed ?? false;
35
35
  const isAdvertisingAllowed = consent.isAdvertisingAllowed ?? false;
36
- const { togglePostHog, toggleOpenReplay, toggleGoogleAdSense, pauseGoogleAdSense } = useDataTracking();
36
+ const { togglePostHog, toggleOpenReplay, toggleGoogleAdSense, pauseGoogleAdSense } =
37
+ useDataTracking();
37
38
 
38
39
  // Default: deny all consent (run once on mount)
39
40
  useEffect(() => {
@@ -190,7 +190,11 @@ function useDataTracking() {
190
190
  if (useTools.includes("ga") && isAnalyticsAllowed) {
191
191
  pushEventToGA(eventName, eventData);
192
192
  }
193
- if (useTools.includes("posthog") && isAnalyticsAllowed && typeof posthog?.capture === "function") {
193
+ if (
194
+ useTools.includes("posthog") &&
195
+ isAnalyticsAllowed &&
196
+ typeof posthog?.capture === "function"
197
+ ) {
194
198
  pushEventToPosthog(eventName, eventData);
195
199
  }
196
200
  };
@@ -2,188 +2,187 @@ import React, { createContext, useReducer } from "react";
2
2
  import { v4 as uuidV4 } from "uuid";
3
3
 
4
4
  import {
5
- SessionReplayProviderProps,
6
- TrackerState,
7
- TrackerAction,
8
- TrackerContextValue,
9
- OpenReplayConfig,
5
+ SessionReplayProviderProps,
6
+ TrackerState,
7
+ TrackerAction,
8
+ TrackerContextValue,
9
+ OpenReplayConfig,
10
10
  } from "../types";
11
11
 
12
- import {
13
- isBrowser
14
- } from "../utils";
12
+ import { isBrowser } from "../utils";
15
13
 
16
14
  export const TrackerContext = createContext<TrackerContextValue | null>(null);
17
15
 
18
16
  function defaultGetUserId(): string {
19
- return uuidV4();
17
+ return uuidV4();
20
18
  }
21
19
 
22
20
  async function newTracker(config: OpenReplayConfig) {
23
- try {
24
- // Dynamic import for SSR compatibility
25
- const OpenReplay = (await import("@openreplay/tracker")).default;
26
-
27
- // Get user ID function (custom or default UUID generator)
28
- const getUserId =
29
- config?.userIdEnabled && config?.getUserId
30
- ? config.getUserId
31
- : defaultGetUserId;
32
-
33
- // Build tracker configuration
34
- const trackerConfig: any = {
35
- projectKey:
36
- config?.projectKey || process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY,
37
- ingestPoint: config?.ingestPoint,
38
- // Capture options
39
- captureExceptions: config.captureExceptions ?? true,
40
- capturePerformance: config.capturePerformance ?? true,
41
- // Network tracking
42
- network: config.network || {
43
- capturePayload: true,
44
- sanitizer: (data: any) => data,
45
- },
46
- // Console tracking
47
- console: config.console || {
48
- levels: ["error", "warn", "log"],
49
- },
50
- // Privacy settings
51
- obscureTextEmails: config.obscureTextEmails ?? true,
52
- obscureTextNumbers: config.obscureTextNumbers ?? false,
53
- obscureInputEmails: config.obscureInputEmails ?? true,
54
- // Development mode
55
- __DISABLE_SECURE_MODE:
56
- config.__DISABLE_SECURE_MODE ??
57
- (typeof process !== "undefined" && process.env?.NODE_ENV === "development"),
58
- };
59
-
60
- // Initialize tracker
61
- const tracker = new OpenReplay(trackerConfig);
62
-
63
- // Set user ID if enabled
64
- if (config?.userIdEnabled) {
65
- const userId = getUserId();
66
- tracker.setUserID(userId);
67
- console.log("User ID set:", userId);
68
- }
21
+ try {
22
+ // Dynamic import for SSR compatibility
23
+ const OpenReplay = (await import("@openreplay/tracker")).default;
24
+
25
+ // Get user ID function (custom or default UUID generator)
26
+ const getUserId =
27
+ config?.userIdEnabled && config?.getUserId ? config.getUserId : defaultGetUserId;
28
+
29
+ // Build tracker configuration
30
+ const trackerConfig: any = {
31
+ projectKey: config?.projectKey || process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY,
32
+ ingestPoint: config?.ingestPoint,
33
+ // Capture options
34
+ captureExceptions: config.captureExceptions ?? true,
35
+ capturePerformance: config.capturePerformance ?? true,
36
+ // Network tracking
37
+ network: config.network || {
38
+ capturePayload: true,
39
+ sanitizer: (data: any) => data,
40
+ },
41
+ // Console tracking
42
+ console: config.console || {
43
+ levels: ["error", "warn", "log"],
44
+ },
45
+ // Privacy settings
46
+ obscureTextEmails: config.obscureTextEmails ?? true,
47
+ obscureTextNumbers: config.obscureTextNumbers ?? false,
48
+ obscureInputEmails: config.obscureInputEmails ?? true,
49
+ // Development mode
50
+ __DISABLE_SECURE_MODE:
51
+ config.__DISABLE_SECURE_MODE ??
52
+ (typeof process !== "undefined" && process.env?.NODE_ENV === "development"),
53
+ };
54
+
55
+ // Initialize tracker
56
+ const tracker = new OpenReplay(trackerConfig);
57
+
58
+ // Set user ID if enabled
59
+ if (config?.userIdEnabled) {
60
+ const userId = getUserId();
61
+ tracker.setUserID(userId);
62
+ console.log("User ID set:", userId);
63
+ }
69
64
 
70
- console.log("OpenReplay tracker initialized");
71
- console.log("Project Key:", trackerConfig.projectKey);
72
- console.log("Ingest Point:", trackerConfig.ingestPoint);
65
+ console.log("OpenReplay tracker initialized");
66
+ console.log("Project Key:", trackerConfig.projectKey);
67
+ console.log("Ingest Point:", trackerConfig.ingestPoint);
73
68
 
74
- return tracker;
75
- } catch (error: any) {
76
- console.error("Failed to create tracker:", error);
77
- throw error;
78
- }
69
+ return tracker;
70
+ } catch (error: any) {
71
+ console.error("Failed to create tracker:", error);
72
+ throw error;
73
+ }
79
74
  }
80
75
 
81
76
  function reducer(state: TrackerState, action: TrackerAction): TrackerState {
82
- const { debug = false } = state.config;
83
-
84
- switch (action.type) {
85
- case "init":
86
- // Only initialize if tracker doesn't exist and we're in browser
87
- if (!state.tracker && isBrowser()) {
88
- if (!state.config.projectKey && !process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY) {
89
- console.warn(
90
- debug,
91
- "Project key not found. Skipping session replay initialization."
92
- );
93
- return state;
94
- }
95
-
96
- // Return state with tracker promise
97
- // The tracker will be created asynchronously
98
- return {
99
- ...state,
100
- tracker: newTracker(state.config),
101
- };
102
- }
103
- return state;
104
-
105
- case "start":
106
- // Start tracking if tracker exists
107
- if (state.tracker) {
108
- Promise.resolve(state.tracker)
109
- .then((tracker) => {
110
- tracker.start();
111
- console.log(debug, "Session replay tracker started");
112
- })
113
- .catch((error) => {
114
- console.error("Failed to start tracker:", error);
115
- });
116
- } else {
117
- console.warn(debug, "Tracker not initialized. Call initTracker() first.");
118
- }
119
- return state;
120
-
121
- case "setUserId":
122
- // Set or update user ID
123
- if (state.tracker) {
124
- Promise.resolve(state.tracker)
125
- .then((tracker) => {
126
- tracker.setUserID(action.payload);
127
- console.log(debug, "User ID updated:", action.payload);
128
- })
129
- .catch((error) => {
130
- console.error("Failed to set user ID:", error);
131
- });
132
- } else {
133
- console.warn(debug, "Tracker not initialized. Call initTracker() first.");
134
- }
135
- return state;
136
-
137
- // Set metadata
138
- case "setMetadata":
139
- if (state.tracker) {
140
- Promise.resolve(state.tracker)
141
- .then((tracker) => {
142
- Object.entries(action.payload || {})?.forEach(([key, value]) => {
143
- tracker.setMetadata(key, value);
144
- });
145
-
146
- console.log(debug, "Metadata updated:", action.payload.metadata);
147
- })
148
- .catch((error) => {
149
- console.error("Failed to set metadata:", error);
150
- });
151
- } else {
152
- console.warn(debug, "Tracker not initialized. Call initTracker() first.");
153
- }
154
- return state;
155
-
156
- default:
157
- return state;
158
- }
77
+ const { debug = false } = state.config;
78
+
79
+ switch (action.type) {
80
+ case "init":
81
+ // Only initialize if tracker doesn't exist and we're in browser
82
+ if (!state.tracker && isBrowser()) {
83
+ if (!state.config.projectKey && !process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY) {
84
+ console.warn(debug, "Project key not found. Skipping session replay initialization.");
85
+ return state;
86
+ }
87
+
88
+ // Return state with tracker promise
89
+ // The tracker will be created asynchronously
90
+ return {
91
+ ...state,
92
+ tracker: newTracker(state.config),
93
+ };
94
+ }
95
+ return state;
96
+
97
+ case "start":
98
+ // Start tracking if tracker exists
99
+ if (state.tracker) {
100
+ Promise.resolve(state.tracker)
101
+ .then((tracker) => {
102
+ tracker.start();
103
+ console.log(debug, "Session replay tracker started");
104
+ })
105
+ .catch((error) => {
106
+ console.error("Failed to start tracker:", error);
107
+ });
108
+ } else {
109
+ console.warn(debug, "Tracker not initialized. Call initTracker() first.");
110
+ }
111
+ return state;
112
+
113
+ case "setUserId":
114
+ // Set or update user ID
115
+ if (state.tracker) {
116
+ Promise.resolve(state.tracker)
117
+ .then((tracker) => {
118
+ tracker.setUserID(action.payload);
119
+ console.log(debug, "User ID updated:", action.payload);
120
+ })
121
+ .catch((error) => {
122
+ console.error("Failed to set user ID:", error);
123
+ });
124
+ } else {
125
+ console.warn(debug, "Tracker not initialized. Call initTracker() first.");
126
+ }
127
+ return state;
128
+
129
+ // Set metadata
130
+ case "setMetadata":
131
+ if (state.tracker) {
132
+ Promise.resolve(state.tracker)
133
+ .then((tracker) => {
134
+ Object.entries(action.payload || {})?.forEach(([key, value]) => {
135
+ tracker.setMetadata(key, value);
136
+ });
137
+
138
+ console.log(debug, "Metadata updated:", action.payload.metadata);
139
+ })
140
+ .catch((error) => {
141
+ console.error("Failed to set metadata:", error);
142
+ });
143
+ } else {
144
+ console.warn(debug, "Tracker not initialized. Call initTracker() first.");
145
+ }
146
+ return state;
147
+
148
+ default:
149
+ return state;
150
+ }
159
151
  }
160
152
 
161
153
  export const SessionReplayProvider: React.FC<SessionReplayProviderProps> = ({
162
- children,
163
- config = {},
154
+ children,
155
+ config = {},
164
156
  }) => {
165
- const [, dispatch] = useReducer(reducer, {
166
- tracker: null,
167
- config,
168
- });
169
-
170
- const initTracker = () => dispatch({ type: "init" })
171
- const startTracking = () => dispatch({ type: "start" })
172
- const setUserId = (userId: string) => dispatch({ type: "setUserId", payload: userId })
173
- const setMetadata = (metadata: Record<string, any>) => dispatch({ type: "setMetadata", payload: metadata })
174
-
175
- // // init and start tracker
176
- // useEffect(() => {
177
- // initTracker();
178
- // startTracking();
179
- // }, []);
180
-
181
- return <TrackerContext.Provider value={{
157
+ const [, dispatch] = useReducer(reducer, {
158
+ tracker: null,
159
+ config,
160
+ });
161
+
162
+ const initTracker = () => dispatch({ type: "init" });
163
+ const startTracking = () => dispatch({ type: "start" });
164
+ const setUserId = (userId: string) => dispatch({ type: "setUserId", payload: userId });
165
+ const setMetadata = (metadata: Record<string, any>) =>
166
+ dispatch({ type: "setMetadata", payload: metadata });
167
+
168
+ // // init and start tracker
169
+ // useEffect(() => {
170
+ // initTracker();
171
+ // startTracking();
172
+ // }, []);
173
+
174
+ return (
175
+ <TrackerContext.Provider
176
+ value={{
182
177
  initTracker,
183
178
  startTracking,
184
179
  setUserId,
185
- setMetadata
186
- }}>{children}</TrackerContext.Provider>;
180
+ setMetadata,
181
+ }}
182
+ >
183
+ {children}
184
+ </TrackerContext.Provider>
185
+ );
187
186
  };
188
187
 
189
188
  export default SessionReplayProvider;
@@ -0,0 +1 @@
1
+ export { useUserCampaignAction } from "@phygitallabs/api-core";