@networkpro/web 1.11.0 → 1.12.3

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.
@@ -1,70 +0,0 @@
1
- /* ==========================================================================
2
- src/lib/utils/trackingCookies.js
3
-
4
- Copyright © 2025 Network Pro Strategies (Network Pro™)
5
- SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
6
- This file is part of Network Pro.
7
- ========================================================================== */
8
-
9
- /**
10
- * @file trackingCookies.js
11
- * @description Handles setting, clearing, and toggling tracking preference cookies.
12
- * @module src/lib/utils/
13
- * @author SunDevil311
14
- * @updated 2025-06-04
15
- */
16
-
17
- // 6 months (in seconds). Will be centralized later.
18
- const DEFAULT_COOKIE_MAX_AGE = 60 * 60 * 24 * 180;
19
-
20
- /**
21
- * Builds a standard cookie string for use in all tracking cookies.
22
- * @param {number} maxAge
23
- * @returns {string}
24
- */
25
- function buildCookieSettings(maxAge) {
26
- return `path=/; max-age=${maxAge}; expires=${new Date(Date.now() + maxAge * 1000).toUTCString()}; SameSite=Lax; Secure`;
27
- }
28
-
29
- /**
30
- * Sets tracking preference cookies based on type.
31
- * @param {"enable" | "disable"} type
32
- * @param {number} [maxAge=DEFAULT_COOKIE_MAX_AGE]
33
- */
34
- export function setTrackingPreference(type, maxAge = DEFAULT_COOKIE_MAX_AGE) {
35
- if (typeof document === "undefined") return; // SSR guard
36
-
37
- const cookieSettings = buildCookieSettings(maxAge);
38
- const now = Date.now();
39
-
40
- if (type === "enable") {
41
- document.cookie = `enable_tracking=true; ${cookieSettings}`;
42
- document.cookie = `tracking_consent_timestamp=${now}; ${cookieSettings}`;
43
- clearCookie("disable_tracking");
44
- } else if (type === "disable") {
45
- document.cookie = `disable_tracking=true; ${cookieSettings}`;
46
- document.cookie = `tracking_consent_timestamp=${now}; ${cookieSettings}`;
47
- clearCookie("enable_tracking");
48
- }
49
- }
50
-
51
- /**
52
- * Clears all tracking-related cookies.
53
- */
54
- export function clearTrackingPreferences() {
55
- if (typeof document === "undefined") return; // SSR guard
56
-
57
- clearCookie("enable_tracking");
58
- clearCookie("disable_tracking");
59
- clearCookie("tracking_consent_timestamp");
60
- }
61
-
62
- /**
63
- * Clears an individual cookie.
64
- * @param {string} name
65
- */
66
- function clearCookie(name) {
67
- if (typeof document === "undefined") return; // SSR guard
68
-
69
- document.cookie = `${name}=; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax; Secure`;
70
- }
@@ -1,61 +0,0 @@
1
- /* ==========================================================================
2
- src/lib/utils/trackingStatus.js
3
-
4
- Copyright © 2025 Network Pro Strategies (Network Pro™)
5
- SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
6
- This file is part of Network Pro.
7
- ========================================================================== */
8
-
9
- /**
10
- * @file trackingStatus.js
11
- * @description Get tracking preferences based on cookies and browser privacy signals.
12
- * @module src/lib/utils
13
- * @author SunDevil311
14
- * @updated 2025-05-28
15
- */
16
-
17
- import { browser } from "$app/environment";
18
-
19
- /**
20
- * Gets the current tracking preferences based on browser cookies and signals.
21
- *
22
- * @returns {{
23
- * optedOut: boolean,
24
- * optedIn: boolean,
25
- * dnt: boolean,
26
- * gpc: boolean,
27
- * status: string
28
- * }}
29
- */
30
- export function getTrackingPreferences() {
31
- // Prevent errors during SSR (no document or navigator)
32
- if (!browser) {
33
- return {
34
- optedOut: false,
35
- optedIn: false,
36
- dnt: false,
37
- gpc: false,
38
- status: "⏳ Checking tracking preferences...",
39
- };
40
- }
41
-
42
- const cookies = document.cookie;
43
- const optedOut = cookies.includes("disable_tracking=true");
44
- const optedIn = cookies.includes("enable_tracking=true");
45
-
46
- const dnt = navigator.doNotTrack === "1";
47
- // @ts-expect-error: 'globalPrivacyControl' is non-standard
48
- const gpc = navigator.globalPrivacyControl === true;
49
-
50
- let status = "⚙️ Using default settings (tracking enabled)";
51
-
52
- if (optedOut) {
53
- status = "🔒 Tracking disabled (manual opt-out)";
54
- } else if (optedIn) {
55
- status = "✅ Tracking enabled (manual opt-in)";
56
- } else if (dnt || gpc) {
57
- status = "🛑 Tracking disabled (via browser signal)";
58
- }
59
-
60
- return { optedOut, optedIn, dnt, gpc, status };
61
- }