@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/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/modules/consent/index.ts +2 -2
- package/src/modules/data-tracking/DataTrackingConsentSync.tsx +2 -1
- package/src/modules/data-tracking/hooks/index.ts +5 -1
- package/src/modules/session-replay/providers/SessionReplayProvider.tsx +160 -161
- package/src/modules/user-campaign/index.ts +1 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -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 } =
|
|
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 (
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
17
|
+
return uuidV4();
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
async function newTracker(config: OpenReplayConfig) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
console.log("OpenReplay tracker initialized");
|
|
66
|
+
console.log("Project Key:", trackerConfig.projectKey);
|
|
67
|
+
console.log("Ingest Point:", trackerConfig.ingestPoint);
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
163
|
-
|
|
154
|
+
children,
|
|
155
|
+
config = {},
|
|
164
156
|
}) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
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";
|