@phygitallabs/tapquest-core 6.7.7 → 6.7.9
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/bun.lock +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/data-tracking/GtagConsentSync.tsx +54 -0
- package/src/modules/data-tracking/hooks/index.ts +6 -3
- package/src/modules/data-tracking/index.ts +1 -0
- package/src/providers/ServicesProvider.tsx +9 -6
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { usePhygitalConsent } from "@phygitallabs/phygital-consent";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
|
|
6
|
+
type GtagConsent = (
|
|
7
|
+
command: "consent",
|
|
8
|
+
action: "default" | "update",
|
|
9
|
+
params: Record<string, string>
|
|
10
|
+
) => void;
|
|
11
|
+
|
|
12
|
+
const GTAG_CONSENT_DENIED = {
|
|
13
|
+
analytics_storage: "denied",
|
|
14
|
+
ad_storage: "denied",
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
const GTAG_CONSENT_GRANTED_ANALYTICS = {
|
|
18
|
+
analytics_storage: "granted",
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Sets gtag consent default to denied on mount and updates to granted
|
|
23
|
+
* when user has accepted analytics (must be under PhygitalConsentProvider).
|
|
24
|
+
* Renders nothing.
|
|
25
|
+
*/
|
|
26
|
+
export function GtagConsentSync() {
|
|
27
|
+
const consent = usePhygitalConsent();
|
|
28
|
+
const isAnalyticsAllowed = (consent as { isAnalyticsAllowed?: boolean }).isAnalyticsAllowed ?? false;
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (typeof window === "undefined") return;
|
|
32
|
+
const w = window as Window & { dataLayer?: unknown[]; gtag?: GtagConsent };
|
|
33
|
+
w.dataLayer = w.dataLayer || [];
|
|
34
|
+
const gtag = w.gtag;
|
|
35
|
+
if (typeof gtag === "function") {
|
|
36
|
+
gtag("consent", "default", { ...GTAG_CONSENT_DENIED });
|
|
37
|
+
} else {
|
|
38
|
+
w.dataLayer.push(["consent", "default", { ...GTAG_CONSENT_DENIED }]);
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!isAnalyticsAllowed || typeof window === "undefined") return;
|
|
44
|
+
const w = window as Window & { gtag?: GtagConsent; dataLayer?: unknown[] };
|
|
45
|
+
const gtag = w.gtag;
|
|
46
|
+
if (typeof gtag === "function") {
|
|
47
|
+
gtag("consent", "update", { ...GTAG_CONSENT_GRANTED_ANALYTICS });
|
|
48
|
+
} else if (Array.isArray(w.dataLayer)) {
|
|
49
|
+
w.dataLayer.push(["consent", "update", { ...GTAG_CONSENT_GRANTED_ANALYTICS }]);
|
|
50
|
+
}
|
|
51
|
+
}, [isAnalyticsAllowed]);
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { usePhygitalConsent } from "@phygitallabs/phygital-consent";
|
|
1
2
|
import posthog from "posthog-js";
|
|
2
3
|
import { useSessionReplay } from "../../../modules/session-replay";
|
|
3
4
|
|
|
4
5
|
declare global {
|
|
5
6
|
interface Window {
|
|
6
|
-
dataLayer:
|
|
7
|
+
dataLayer: unknown[];
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -19,7 +20,7 @@ const pushEventToDataLayer = (event: string, data: Record<string, any>) => {
|
|
|
19
20
|
try {
|
|
20
21
|
window.dataLayer = window.dataLayer || [];
|
|
21
22
|
|
|
22
|
-
window.dataLayer.push({
|
|
23
|
+
(window.dataLayer as Record<string, unknown>[]).push({
|
|
23
24
|
event,
|
|
24
25
|
...data,
|
|
25
26
|
});
|
|
@@ -45,6 +46,8 @@ const pushEventToPosthog = (eventName: string, eventData: Record<string, any>) =
|
|
|
45
46
|
|
|
46
47
|
function useDataTracking() {
|
|
47
48
|
const { setUserId, setMetadata } = useSessionReplay();
|
|
49
|
+
const consent = usePhygitalConsent();
|
|
50
|
+
const isAnalyticsAllowed = (consent as { isAnalyticsAllowed?: boolean }).isAnalyticsAllowed ?? false;
|
|
48
51
|
|
|
49
52
|
const trackEvent = (eventName: string, eventData: Record<string, any>, useTools?: ("gtm" | "ga" | "posthog")[]) => {
|
|
50
53
|
console.log("trackEvent ", eventName, eventData);
|
|
@@ -54,7 +57,7 @@ function useDataTracking() {
|
|
|
54
57
|
if (useTools.includes("gtm") && typeof window !== "undefined") {
|
|
55
58
|
pushEventToDataLayer(eventName, eventData);
|
|
56
59
|
}
|
|
57
|
-
if (useTools.includes("ga") && typeof gtag == "function") {
|
|
60
|
+
if (useTools.includes("ga") && isAnalyticsAllowed && typeof gtag == "function") {
|
|
58
61
|
pushEventToGA(eventName, eventData);
|
|
59
62
|
}
|
|
60
63
|
if (useTools.includes("posthog") && typeof posthog == "function") {
|
|
@@ -5,6 +5,7 @@ import { RewardServiceProvider } from "@phygitallabs/reward";
|
|
|
5
5
|
import { AchievementServiceProvider } from "@phygitallabs/achievement";
|
|
6
6
|
import { GenerateCertificateServiceProvider } from "@phygitallabs/generate-certificate";
|
|
7
7
|
import { PhygitalConsentProvider } from "@phygitallabs/phygital-consent";
|
|
8
|
+
import { GtagConsentSync } from "../modules/data-tracking";
|
|
8
9
|
|
|
9
10
|
import serviceApiUrl from "../constants/service";
|
|
10
11
|
import { APIConfig, ServiceConfig } from "../types/service";
|
|
@@ -37,7 +38,7 @@ export const ServicesProvider: React.FC<ServicesProviderProps> = ({
|
|
|
37
38
|
const { signOut, refreshToken } = useAuth();
|
|
38
39
|
const { environment, version } = apiConfig;
|
|
39
40
|
const [commonServiceConfig, setCommonServiceConfig] = useState<ServiceConfig | null>(null);
|
|
40
|
-
|
|
41
|
+
|
|
41
42
|
const [deviceUid, setDeviceUid] = useState<string>("");
|
|
42
43
|
|
|
43
44
|
useEffect(() => {
|
|
@@ -142,14 +143,16 @@ export const ServicesProvider: React.FC<ServicesProviderProps> = ({
|
|
|
142
143
|
baseURL={`${serviceApiUrl[environment].API_GENERATE_CERTIFICATE_URL}/v1`}
|
|
143
144
|
>
|
|
144
145
|
<PhygitalConsentProvider
|
|
146
|
+
{...commonServiceConfig}
|
|
145
147
|
deviceId={deviceUid}
|
|
146
|
-
queryClient={commonServiceConfig.queryClient as any}
|
|
147
|
-
axiosConfig={commonServiceConfig.axiosConfig}
|
|
148
|
-
requestInterceptors={commonServiceConfig.requestInterceptors}
|
|
149
|
-
responseInterceptors={commonServiceConfig.responseInterceptors}
|
|
150
148
|
baseURL={`${serviceApiUrl[environment].API_CONSENT_URL}/v1`}
|
|
151
|
-
|
|
149
|
+
axiosConfig={{
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Type": "application/json",
|
|
152
|
+
}
|
|
153
|
+
}}
|
|
152
154
|
>
|
|
155
|
+
<GtagConsentSync />
|
|
153
156
|
{children}
|
|
154
157
|
</PhygitalConsentProvider>
|
|
155
158
|
</GenerateCertificateServiceProvider>
|