@fynd-design-engineering/fynd-one-v2 2.1.2 → 2.2.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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../bin/live-reload.js", "../../src/posthog/index.ts"],
4
+ "sourcesContent": ["// Only enable live reload when running on localhost\nif (\n window.location.hostname === \"localhost\" ||\n window.location.hostname === \"127.0.0.1\"\n) {\n new EventSource(`${SERVE_ORIGIN}/esbuild`).addEventListener(\"change\", () =>\n location.reload()\n );\n} else {\n console.log(\"Live reload disabled: not running on localhost\");\n}\n", "// Type definitions\ninterface TrackingProperties {\n source_page: string;\n fynd_product: string;\n interface: string;\n device_type: string;\n utm_source: string;\n utm_medium: string;\n utm_campaign: string;\n referrer: string;\n}\n\ninterface TrackingPropertiesWithForm extends TrackingProperties {\n form_name: string;\n}\n\n// PostHog interface\ninterface PostHog {\n capture: (eventName: string, properties: TrackingProperties | TrackingPropertiesWithForm) => void;\n}\n\n// Extend Window interface to include custom properties\ndeclare global {\n interface Window {\n getTrackingProperties: () => TrackingProperties;\n getTrackingPropertiesWithForm: (formName: string) => TrackingPropertiesWithForm;\n interactedForm: string;\n posthog: PostHog;\n }\n}\n\n// This export statement is needed to make this file a module\n// and allow the global declarations to work properly\nexport { };\n\n// Default tracking properties function\nconst getTrackingProperties = (): TrackingProperties => {\n const pathname: string = window.location.pathname;\n\n return {\n source_page: pathname === \"/\" ? pathname + \" Home\" : pathname,\n fynd_product: \"fynd.com website\",\n interface: \"Webflow\",\n device_type: /Mobile|Android|iPhone|iPad/.test(navigator.userAgent)\n ? \"Mobile\"\n : \"Web\",\n utm_source:\n new URLSearchParams(window.location.search).get(\"utm_source\") || \"\",\n utm_medium:\n new URLSearchParams(window.location.search).get(\"utm_medium\") || \"\",\n utm_campaign:\n new URLSearchParams(window.location.search).get(\"utm_campaign\") || \"\",\n referrer: document.referrer,\n };\n};\n\n// Function to get tracking properties with form name\nconst getTrackingPropertiesWithForm = (formName: string): TrackingPropertiesWithForm => {\n return {\n ...getTrackingProperties(),\n form_name: formName,\n };\n};\n\n// Assign functions to window object\nwindow.getTrackingProperties = getTrackingProperties;\nwindow.getTrackingPropertiesWithForm = getTrackingPropertiesWithForm;\nwindow.interactedForm = \"\";\n\n// Getting parent form name by passing field element\nfunction getParentFormName(fieldElement: Element): string | null {\n const parentForm = fieldElement.closest(\"form\") as HTMLFormElement | null;\n if (parentForm) {\n const formName = parentForm.getAttribute(\"data-name\");\n return formName || null;\n }\n return null;\n}\n\n// Initialize PostHog pageview\ndocument.addEventListener(\"DOMContentLoaded\", function (): void {\n if (window.posthog) {\n window.posthog.capture(\"$pageview\", window.getTrackingProperties());\n }\n});\n\n// Track page load event\nwindow.addEventListener(\"load\", function (): void {\n if (window.posthog) {\n window.posthog.capture(\"fynd_page_loaded\", window.getTrackingProperties());\n }\n});\n\n// button click tracking for sign up, sign in, and scroll to form and book a demo buttons\ndocument.addEventListener(\"DOMContentLoaded\", function (): void {\n const signUpButtons = document.querySelectorAll('[data-ph=\"sign-up\"]') as NodeListOf<Element>;\n const signInButtons = document.querySelectorAll('[data-ph=\"sign-in\"]') as NodeListOf<Element>;\n const scrollToFormButtons = document.querySelectorAll(\n '[href=\"#footer-form\"]'\n ) as NodeListOf<Element>;\n const bookADemoButtons = document.querySelectorAll('[data-ph=\"book-a-demo\"]') as NodeListOf<Element>;\n\n signUpButtons.forEach((button: Element) => {\n button.addEventListener(\"click\", function (): void {\n if (window.posthog) {\n window.posthog.capture(\"fynd_clicked_sign_up\", window.getTrackingProperties());\n }\n });\n });\n\n signInButtons.forEach((button: Element) => {\n button.addEventListener(\"click\", function (): void {\n if (window.posthog) {\n window.posthog.capture(\"fynd_clicked_sign_in\", window.getTrackingProperties());\n }\n });\n });\n\n scrollToFormButtons.forEach((button: Element) => {\n button.addEventListener(\"click\", function (): void {\n if (window.posthog) {\n window.posthog.capture(\"fynd_clicked_scroll_to_form\", window.getTrackingProperties());\n }\n });\n });\n\n bookADemoButtons.forEach((button: Element) => {\n button.addEventListener(\"click\", function (): void {\n if (window.posthog) {\n window.posthog.capture(\"fynd_clicked_book_a_demo\", window.getTrackingProperties());\n }\n });\n });\n});\n\n\n\n// Track form interactions\ndocument.addEventListener(\"DOMContentLoaded\", function (): void {\n // Select all form fields with data-posthog-trigger attribute\n const formFields = document.querySelectorAll(\"[data-posthog-trigger]\") as NodeListOf<Element>;\n console.log(\n \"%cposthog/custom-events.js:58 formFields\",\n \"color: #007acc;\",\n formFields\n );\n\n // Keep track of forms that have already been processed\n const processedForms = new Set<HTMLFormElement>();\n\n formFields.forEach((field: Element) => {\n field.addEventListener(\"change\", function (this: Element): string | null {\n // Find the parent form element\n const parentForm = this.closest(\"form\") as HTMLFormElement | null;\n\n if (parentForm) {\n // Check if this form has already been processed\n if (processedForms.has(parentForm)) {\n // console.log(\"Form already processed, skipping...\");\n return null;\n }\n\n // Mark this form as processed\n processedForms.add(parentForm);\n\n // Get the data-name attribute value from the parent form\n const formName = parentForm.getAttribute(\"data-name\");\n window.interactedForm = formName || \"\";\n\n if (formName && window.posthog) {\n console.log(\"form started\");\n window.posthog.capture(\n \"fynd_form_started\",\n window.getTrackingPropertiesWithForm(formName)\n );\n return formName;\n } else {\n console.warn(\"No data-name attribute found on parent form or PostHog not available\");\n return null;\n }\n } else {\n console.warn(\"No parent form found\");\n return null;\n }\n });\n });\n});"],
5
+ "mappings": ";;;AACA,MACE,OAAO,SAAS,aAAa,eAC7B,OAAO,SAAS,aAAa,aAC7B;AACA,QAAI,YAAY,GAAG,uBAAY,UAAU,EAAE;AAAA,MAAiB;AAAA,MAAU,MACpE,SAAS,OAAO;AAAA,IAClB;AAAA,EACF,OAAO;AACL,YAAQ,IAAI,gDAAgD;AAAA,EAC9D;;;AC0BA,MAAM,wBAAwB,MAA0B;AACpD,UAAM,WAAmB,OAAO,SAAS;AAEzC,WAAO;AAAA,MACH,aAAa,aAAa,MAAM,W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OAAO;AACH,oBAAQ,KAAK,sEAAsE;AACnF,mBAAO;AAAA,UACX;AAAA,QACJ,OAAO;AACH,kBAAQ,KAAK,sBAAsB;AACnC,iBAAO;AAAA,QACX;AAAA,MACJ,CAAC;AAAA,IACL,CAAC;AAAA,EACL,CAAC;",
6
+ "names": []
7
+ }
@@ -1 +1,16 @@
1
- "use strict";(()=>{console.log("script is running always");})();
1
+ "use strict";
2
+ (() => {
3
+ // bin/live-reload.js
4
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
5
+ new EventSource(`${"http://localhost:3000"}/esbuild`).addEventListener(
6
+ "change",
7
+ () => location.reload()
8
+ );
9
+ } else {
10
+ console.log("Live reload disabled: not running on localhost");
11
+ }
12
+
13
+ // src/test/sample.ts
14
+ console.log("script is running always");
15
+ })();
16
+ //# sourceMappingURL=sample.js.map
@@ -1 +1,97 @@
1
- "use strict";(()=>{function o(){try{let e=i();if(!e||e.userJourney.length===0)return;let t=e.userJourney[0],r=e.userJourney[e.userJourney.length-1];e.userJourney.length>1&&e.userJourney[e.userJourney.length-1].page==="/contact-us"&&(r=e.userJourney[e.userJourney.length-2]);let n={utm_source:t.utm.source,utm_medium:t.utm.medium,utm_campaign:t.utm.campaign,fp_custom_page_title:t.title,fp_custom_page_category:t.category.join(", "),fp_custom_page_type:t.type,fp_timestamp:t.time,fp_path:t.page,lp_custom_page_title:r.title,lp_custom_page_category:r.category.join(", "),lp_custom_page_type:r.type,lp_timestamp:r.time,lp_path:r.page,userjourney:JSON.stringify(e.userJourney),device:e.deviceCategory,browser:e.browser};Object.entries(n).forEach(([u,s])=>{a(u,s)})}catch(e){console.error("Error filling form with user journey data:",e)}}function i(){try{let e=sessionStorage.getItem("userJourney");return e?JSON.parse(e):null}catch(e){return console.error("Error getting user journey data:",e),null}}function a(e,t){try{let r=`[fynd-queryparam-name="${e}"]`,n=document.querySelector(r);if(n){n.value=t;let u=new Event("input",{bubbles:!0});n.dispatchEvent(u);let s=new Event("change",{bubbles:!0});n.dispatchEvent(s)}}catch(r){console.error(`Error filling field [${e}]:`,r)}}document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{o()},500)});document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{o()},500)}):setTimeout(()=>{o()},500);window.fillFormWithUserJourney=o;})();
1
+ "use strict";
2
+ (() => {
3
+ // bin/live-reload.js
4
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
5
+ new EventSource(`${"http://localhost:3000"}/esbuild`).addEventListener(
6
+ "change",
7
+ () => location.reload()
8
+ );
9
+ } else {
10
+ console.log("Live reload disabled: not running on localhost");
11
+ }
12
+
13
+ // src/tracking/fill-form-fields.ts
14
+ function fillFormWithUserJourney() {
15
+ try {
16
+ const journey = getUserJourneyData();
17
+ if (!journey || journey.userJourney.length === 0) {
18
+ return;
19
+ }
20
+ const firstPage = journey.userJourney[0];
21
+ let lastPage = journey.userJourney[journey.userJourney.length - 1];
22
+ if (journey.userJourney.length > 1 && journey.userJourney[journey.userJourney.length - 1].page === "/contact-us") {
23
+ lastPage = journey.userJourney[journey.userJourney.length - 2];
24
+ }
25
+ const fieldMappings = {
26
+ // UTM parameters
27
+ "utm_source": firstPage.utm.source,
28
+ "utm_medium": firstPage.utm.medium,
29
+ "utm_campaign": firstPage.utm.campaign,
30
+ // First Page (Landing Page) data
31
+ "fp_custom_page_title": firstPage.title,
32
+ "fp_custom_page_category": firstPage.category.join(", "),
33
+ "fp_custom_page_type": firstPage.type,
34
+ "fp_timestamp": firstPage.time,
35
+ "fp_path": firstPage.page,
36
+ // Last Page data
37
+ "lp_custom_page_title": lastPage.title,
38
+ "lp_custom_page_category": lastPage.category.join(", "),
39
+ "lp_custom_page_type": lastPage.type,
40
+ "lp_timestamp": lastPage.time,
41
+ "lp_path": lastPage.page,
42
+ // Journey metadata
43
+ "userjourney": JSON.stringify(journey.userJourney),
44
+ "device": journey.deviceCategory,
45
+ "browser": journey.browser
46
+ };
47
+ Object.entries(fieldMappings).forEach(([attributeValue, data]) => {
48
+ fillFormField(attributeValue, data);
49
+ });
50
+ } catch (error) {
51
+ console.error("Error filling form with user journey data:", error);
52
+ }
53
+ }
54
+ function getUserJourneyData() {
55
+ try {
56
+ const storedData = sessionStorage.getItem("userJourney");
57
+ return storedData ? JSON.parse(storedData) : null;
58
+ } catch (error) {
59
+ console.error("Error getting user journey data:", error);
60
+ return null;
61
+ }
62
+ }
63
+ function fillFormField(attributeValue, data) {
64
+ try {
65
+ const selector = `[fynd-queryparam-name="${attributeValue}"]`;
66
+ const element = document.querySelector(selector);
67
+ if (element) {
68
+ element.value = data;
69
+ const inputEvent = new Event("input", { bubbles: true });
70
+ element.dispatchEvent(inputEvent);
71
+ const changeEvent = new Event("change", { bubbles: true });
72
+ element.dispatchEvent(changeEvent);
73
+ } else {
74
+ }
75
+ } catch (error) {
76
+ console.error(`Error filling field [${attributeValue}]:`, error);
77
+ }
78
+ }
79
+ document.addEventListener("DOMContentLoaded", () => {
80
+ setTimeout(() => {
81
+ fillFormWithUserJourney();
82
+ }, 500);
83
+ });
84
+ if (document.readyState === "loading") {
85
+ document.addEventListener("DOMContentLoaded", () => {
86
+ setTimeout(() => {
87
+ fillFormWithUserJourney();
88
+ }, 500);
89
+ });
90
+ } else {
91
+ setTimeout(() => {
92
+ fillFormWithUserJourney();
93
+ }, 500);
94
+ }
95
+ window.fillFormWithUserJourney = fillFormWithUserJourney;
96
+ })();
97
+ //# sourceMappingURL=fill-form-fields.js.map
@@ -1 +1,21 @@
1
- "use strict";(()=>{document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{let t=document.querySelectorAll('[data-page-category="true"]');window.pageCategories=Array.from(t).map(e=>e.textContent?.trim()||"").filter(e=>e.length>0)},100)});})();
1
+ "use strict";
2
+ (() => {
3
+ // bin/live-reload.js
4
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
5
+ new EventSource(`${"http://localhost:3000"}/esbuild`).addEventListener(
6
+ "change",
7
+ () => location.reload()
8
+ );
9
+ } else {
10
+ console.log("Live reload disabled: not running on localhost");
11
+ }
12
+
13
+ // src/tracking/page-categories.ts
14
+ document.addEventListener("DOMContentLoaded", () => {
15
+ setTimeout(() => {
16
+ const categoryDivs = document.querySelectorAll('[data-page-category="true"]');
17
+ window.pageCategories = Array.from(categoryDivs).map((div) => div.textContent?.trim() || "").filter((text) => text.length > 0);
18
+ }, 100);
19
+ });
20
+ })();
21
+ //# sourceMappingURL=page-categories.js.map
@@ -1 +1,253 @@
1
- "use strict";(()=>{async function c(){let t="userJourney";function i(){let e=navigator.userAgent;return/tablet|ipad|playbook|silk/i.test(e)?"tablet":/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(e)?"mobile":"desktop"}function g(){let e=navigator.userAgent;return e.includes("Chrome")&&!e.includes("Edg")?"Chrome":e.includes("Firefox")?"Firefox":e.includes("Safari")&&!e.includes("Chrome")?"Safari":e.includes("Edg")?"Edge":e.includes("Opera")?"Opera":"Unknown"}function m(e){if(!e)return"Unknown";try{let s=new URL(e).hostname.replace(/^www\./,""),a=s.split(".");return a.length>=2?a[0]:s||"Unknown"}catch{return"Unknown"}}function p(e,r){let o=new URLSearchParams(window.location.search),s=o.has("utm_source")||o.has("utm_medium")||o.has("utm_campaign");return e||s?s?{source:o.get("utm_source")||"",medium:o.get("utm_medium")||"",campaign:o.get("utm_campaign")||""}:{source:m(document.referrer),medium:"organic",campaign:"unknown"}:r||{source:"Unknown",medium:"organic",campaign:"unknown"}}function d(){try{return typeof window.pageCategories<"u"&&Array.isArray(window.pageCategories)&&window.pageCategories.length>0?window.pageCategories:["Not applicable"]}catch(e){return console.warn("Error accessing pageCategories:",e),["Not applicable"]}}function f(){let e=new URLSearchParams(window.location.search);return e.has("utm_source")||e.has("utm_medium")||e.has("utm_campaign")}function h(e){let r=e.split("?")[0].toLowerCase(),o={exactMatches:{"/":"Home","/home":"Home","/blog":"Blog listing","/about-us":"About us","/contact-us":"Contact","/privacy-policy":"Privacy policy","/terms-of-service":"Terms of service","/careers":"Careers","/customer-stories":"Customer stories listing","/events":"Events listing","/infographics":"Infographics listing","/newsroom":"Newsroom","/releases":"Releases listing"},pathStartsWith:[{pattern:"/blog/",type:"Blog"},{pattern:"/customer-stories/",type:"Customer story"},{pattern:"/case-studies/",type:"Case study"},{pattern:"/solutions/",type:"Solution"},{pattern:"/events/",type:"Event"},{pattern:"/news/",type:"News"},{pattern:"/press-releases/",type:"Press release"},{pattern:"/releases/",type:"Release"}]};if(o.exactMatches[r])return o.exactMatches[r];for(let s of o.pathStartsWith)if(r.startsWith(s.pattern))return s.type;return"Other"}function w(e){if(!e.userJourney||e.userJourney.length===0)return!1;let r=new Date(e.userJourney[e.userJourney.length-1].time);return new Date().getTime()-r.getTime()<18e5}return new Promise(e=>{setTimeout(()=>{try{let r=null,o=sessionStorage.getItem(t);if(o){let u=JSON.parse(o);w(u)&&(r=u)}r||(r={userJourney:[],origin:window.location.hostname,deviceCategory:i(),browser:g()});let s=window.location.pathname,a=new Date().toISOString(),y=r.userJourney[r.userJourney.length-1];if(y&&y.page===s)y.time=a;else{let u=r.userJourney.length===0,J=u?void 0:r.userJourney[0].utm,U={touchPoint:r.userJourney.length+1,page:s,title:document.title||"Untitled",type:h(s),category:d(),time:a,utmVisibility:f()?"visible":"hidden",utm:p(u,J)};r.userJourney.push(U)}sessionStorage.setItem(t,JSON.stringify(r)),e(r)}catch(r){console.error("Error tracking user journey:",r),e(null)}},200)})}function l(){try{let t=sessionStorage.getItem("userJourney");return t?JSON.parse(t):null}catch(t){return console.error("Error getting user journey:",t),null}}function P(){sessionStorage.removeItem("userJourney")}function S(t){try{let n=l();if(!n||n.userJourney.length===0)return!1;let i=n.userJourney[n.userJourney.length-1];return i.category=t.length>0?t:["Not applicable"],sessionStorage.setItem("userJourney",JSON.stringify(n)),!0}catch(n){return console.error("Error updating page categories:",n),!1}}function b(t){try{let n=l();if(!n||n.userJourney.length===0)return!1;let i=n.userJourney[n.userJourney.length-1];return i.type=t,sessionStorage.setItem("userJourney",JSON.stringify(n)),!0}catch(n){return console.error("Error updating page type:",n),!1}}function T(){let t=l();if(!t||t.userJourney.length===0)return null;let n=t.userJourney[0],i=t.userJourney[t.userJourney.length-1],g=new Date(i.time).getTime()-new Date(n.time).getTime();return{totalPages:t.userJourney.length,sessionDuration:Math.floor(g/1e3),firstPage:n.page,lastPage:i.page}}document.addEventListener("DOMContentLoaded",()=>{c()});document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{c()}):c();window.trackUserJourney=c;window.getUserJourney=l;window.clearUserJourney=P;window.updatePageType=b;window.updatePageCategories=S;window.getJourneyStats=T;})();
1
+ "use strict";
2
+ (() => {
3
+ // bin/live-reload.js
4
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
5
+ new EventSource(`${"http://localhost:3000"}/esbuild`).addEventListener(
6
+ "change",
7
+ () => location.reload()
8
+ );
9
+ } else {
10
+ console.log("Live reload disabled: not running on localhost");
11
+ }
12
+
13
+ // src/tracking/user-journey.ts
14
+ async function trackUserJourney() {
15
+ const STORAGE_KEY = "userJourney";
16
+ const SESSION_TIMEOUT = 30 * 60 * 1e3;
17
+ function getDeviceCategory() {
18
+ const userAgent = navigator.userAgent;
19
+ if (/tablet|ipad|playbook|silk/i.test(userAgent)) return "tablet";
20
+ if (/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(userAgent)) return "mobile";
21
+ return "desktop";
22
+ }
23
+ function getBrowser() {
24
+ const userAgent = navigator.userAgent;
25
+ if (userAgent.includes("Chrome") && !userAgent.includes("Edg")) return "Chrome";
26
+ if (userAgent.includes("Firefox")) return "Firefox";
27
+ if (userAgent.includes("Safari") && !userAgent.includes("Chrome")) return "Safari";
28
+ if (userAgent.includes("Edg")) return "Edge";
29
+ if (userAgent.includes("Opera")) return "Opera";
30
+ return "Unknown";
31
+ }
32
+ function extractDomainFromReferrer(referrer) {
33
+ if (!referrer) return "Unknown";
34
+ try {
35
+ const url = new URL(referrer);
36
+ const hostname = url.hostname;
37
+ const domain = hostname.replace(/^www\./, "");
38
+ const domainParts = domain.split(".");
39
+ if (domainParts.length >= 2) {
40
+ return domainParts[0];
41
+ }
42
+ return domain || "Unknown";
43
+ } catch (error) {
44
+ return "Unknown";
45
+ }
46
+ }
47
+ function getUTMParameters(isFirstVisit, firstVisitUTM) {
48
+ const urlParams = new URLSearchParams(window.location.search);
49
+ const hasCurrentUTM = urlParams.has("utm_source") || urlParams.has("utm_medium") || urlParams.has("utm_campaign");
50
+ if (isFirstVisit || hasCurrentUTM) {
51
+ if (hasCurrentUTM) {
52
+ return {
53
+ source: urlParams.get("utm_source") || "",
54
+ medium: urlParams.get("utm_medium") || "",
55
+ campaign: urlParams.get("utm_campaign") || ""
56
+ };
57
+ } else {
58
+ const referrerDomain = extractDomainFromReferrer(document.referrer);
59
+ return {
60
+ source: referrerDomain,
61
+ medium: "organic",
62
+ campaign: "unknown"
63
+ };
64
+ }
65
+ } else {
66
+ return firstVisitUTM || {
67
+ source: "Unknown",
68
+ medium: "organic",
69
+ campaign: "unknown"
70
+ };
71
+ }
72
+ }
73
+ function getPageCategories() {
74
+ try {
75
+ if (typeof window.pageCategories !== "undefined" && Array.isArray(window.pageCategories) && window.pageCategories.length > 0) {
76
+ return window.pageCategories;
77
+ }
78
+ return ["Not applicable"];
79
+ } catch (error) {
80
+ console.warn("Error accessing pageCategories:", error);
81
+ return ["Not applicable"];
82
+ }
83
+ }
84
+ function hasVisibleUTM() {
85
+ const urlParams = new URLSearchParams(window.location.search);
86
+ return urlParams.has("utm_source") || urlParams.has("utm_medium") || urlParams.has("utm_campaign");
87
+ }
88
+ function getPageType(url) {
89
+ const path = url.split("?")[0].toLowerCase();
90
+ const typeConfig = {
91
+ // Exact path matches (highest priority)
92
+ exactMatches: {
93
+ "/": "Home",
94
+ "/home": "Home",
95
+ "/blog": "Blog listing",
96
+ "/about-us": "About us",
97
+ "/contact-us": "Contact",
98
+ "/privacy-policy": "Privacy policy",
99
+ "/terms-of-service": "Terms of service",
100
+ "/careers": "Careers",
101
+ "/customer-stories": "Customer stories listing",
102
+ "/events": "Events listing",
103
+ "/infographics": "Infographics listing",
104
+ "/newsroom": "Newsroom",
105
+ "/releases": "Releases listing"
106
+ },
107
+ // Path pattern matches
108
+ // These will match if the path starts with the pattern
109
+ pathStartsWith: [
110
+ { pattern: "/blog/", type: "Blog" },
111
+ { pattern: "/customer-stories/", type: "Customer story" },
112
+ { pattern: "/case-studies/", type: "Case study" },
113
+ { pattern: "/solutions/", type: "Solution" },
114
+ { pattern: "/events/", type: "Event" },
115
+ { pattern: "/news/", type: "News" },
116
+ { pattern: "/press-releases/", type: "Press release" },
117
+ { pattern: "/releases/", type: "Release" }
118
+ ]
119
+ };
120
+ if (typeConfig.exactMatches[path]) {
121
+ return typeConfig.exactMatches[path];
122
+ }
123
+ for (const item of typeConfig.pathStartsWith) {
124
+ if (path.startsWith(item.pattern)) {
125
+ return item.type;
126
+ }
127
+ }
128
+ return "Other";
129
+ }
130
+ function isValidSession(journey) {
131
+ if (!journey.userJourney || journey.userJourney.length === 0) return false;
132
+ const lastVisit = new Date(journey.userJourney[journey.userJourney.length - 1].time);
133
+ const now = /* @__PURE__ */ new Date();
134
+ return now.getTime() - lastVisit.getTime() < SESSION_TIMEOUT;
135
+ }
136
+ return new Promise((resolve) => {
137
+ setTimeout(() => {
138
+ try {
139
+ let journey = null;
140
+ const storedData = sessionStorage.getItem(STORAGE_KEY);
141
+ if (storedData) {
142
+ const parsedData = JSON.parse(storedData);
143
+ if (isValidSession(parsedData)) {
144
+ journey = parsedData;
145
+ }
146
+ }
147
+ if (!journey) {
148
+ journey = {
149
+ userJourney: [],
150
+ origin: window.location.hostname,
151
+ deviceCategory: getDeviceCategory(),
152
+ browser: getBrowser()
153
+ };
154
+ }
155
+ const currentUrl = window.location.pathname;
156
+ const currentTime = (/* @__PURE__ */ new Date()).toISOString();
157
+ const lastVisit = journey.userJourney[journey.userJourney.length - 1];
158
+ if (lastVisit && lastVisit.page === currentUrl) {
159
+ lastVisit.time = currentTime;
160
+ } else {
161
+ const isFirstVisit = journey.userJourney.length === 0;
162
+ const firstVisitUTM = isFirstVisit ? void 0 : journey.userJourney[0].utm;
163
+ const touchPoint = {
164
+ touchPoint: journey.userJourney.length + 1,
165
+ page: currentUrl,
166
+ title: document.title || "Untitled",
167
+ type: getPageType(currentUrl),
168
+ category: getPageCategories(),
169
+ time: currentTime,
170
+ utmVisibility: hasVisibleUTM() ? "visible" : "hidden",
171
+ utm: getUTMParameters(isFirstVisit, firstVisitUTM)
172
+ };
173
+ journey.userJourney.push(touchPoint);
174
+ }
175
+ sessionStorage.setItem(STORAGE_KEY, JSON.stringify(journey));
176
+ resolve(journey);
177
+ } catch (error) {
178
+ console.error("Error tracking user journey:", error);
179
+ resolve(null);
180
+ }
181
+ }, 200);
182
+ });
183
+ }
184
+ function getUserJourney() {
185
+ try {
186
+ const storedData = sessionStorage.getItem("userJourney");
187
+ return storedData ? JSON.parse(storedData) : null;
188
+ } catch (error) {
189
+ console.error("Error getting user journey:", error);
190
+ return null;
191
+ }
192
+ }
193
+ function clearUserJourney() {
194
+ sessionStorage.removeItem("userJourney");
195
+ }
196
+ function updatePageCategories(categories) {
197
+ try {
198
+ const journey = getUserJourney();
199
+ if (!journey || journey.userJourney.length === 0) return false;
200
+ const lastVisit = journey.userJourney[journey.userJourney.length - 1];
201
+ lastVisit.category = categories.length > 0 ? categories : ["Not applicable"];
202
+ sessionStorage.setItem("userJourney", JSON.stringify(journey));
203
+ return true;
204
+ } catch (error) {
205
+ console.error("Error updating page categories:", error);
206
+ return false;
207
+ }
208
+ }
209
+ function updatePageType(type) {
210
+ try {
211
+ const journey = getUserJourney();
212
+ if (!journey || journey.userJourney.length === 0) return false;
213
+ const lastVisit = journey.userJourney[journey.userJourney.length - 1];
214
+ lastVisit.type = type;
215
+ sessionStorage.setItem("userJourney", JSON.stringify(journey));
216
+ return true;
217
+ } catch (error) {
218
+ console.error("Error updating page type:", error);
219
+ return false;
220
+ }
221
+ }
222
+ function getJourneyStats() {
223
+ const journey = getUserJourney();
224
+ if (!journey || journey.userJourney.length === 0) return null;
225
+ const firstVisit = journey.userJourney[0];
226
+ const lastVisit = journey.userJourney[journey.userJourney.length - 1];
227
+ const sessionDuration = new Date(lastVisit.time).getTime() - new Date(firstVisit.time).getTime();
228
+ return {
229
+ totalPages: journey.userJourney.length,
230
+ sessionDuration: Math.floor(sessionDuration / 1e3),
231
+ // in seconds
232
+ firstPage: firstVisit.page,
233
+ lastPage: lastVisit.page
234
+ };
235
+ }
236
+ document.addEventListener("DOMContentLoaded", () => {
237
+ trackUserJourney();
238
+ });
239
+ if (document.readyState === "loading") {
240
+ document.addEventListener("DOMContentLoaded", () => {
241
+ trackUserJourney();
242
+ });
243
+ } else {
244
+ trackUserJourney();
245
+ }
246
+ window.trackUserJourney = trackUserJourney;
247
+ window.getUserJourney = getUserJourney;
248
+ window.clearUserJourney = clearUserJourney;
249
+ window.updatePageType = updatePageType;
250
+ window.updatePageCategories = updatePageCategories;
251
+ window.getJourneyStats = getJourneyStats;
252
+ })();
253
+ //# sourceMappingURL=user-journey.js.map
@@ -1 +1,195 @@
1
- "use strict";(()=>{(function(){"use strict";let e={utmKeys:["utm_source","utm_medium","utm_campaign","utm_term","utm_content","utm_id"],selectors:["a[href]",'button[onclick*="location"]','button[onclick*="window.open"]','button[onclick*="href"]',"[data-href]"]};function a(){let t=new URLSearchParams(window.location.search),s={};return e.utmKeys.forEach(r=>{if(t.has(r)){let n=t.get(r);n&&(s[r]=n)}}),s}function c(t,s){try{return t.startsWith("/")||t.startsWith("./")||t.startsWith("../")?!0:t.startsWith("http")?new URL(t).hostname===s:t.startsWith("//")?new URL("http:"+t).hostname===s:!t.includes("://")}catch(r){return console.warn("Error parsing URL:",t,r),!0}}function u(t,s){try{let r=new URL(t,window.location.origin);return Object.keys(s).forEach(n=>{r.searchParams.has(n)||r.searchParams.set(n,s[n])}),r.toString()}catch(r){return console.warn("Error processing URL:",t,r),t}}function f(t){return t.hasAttribute("data-utm-exception")&&t.getAttribute("data-utm-exception")==="true"}function g(t){let s=t.match(/["'](https?:\/\/[^"']+|\/[^"']*|[^"']*\.html?[^"']*)["']/);return s?s[1]:null}function m(t,s,r){if(!(t instanceof HTMLElement)||!t.onclick)return;let o=t.onclick.toString().replace(s,r),i=o.slice(o.indexOf("{")+1,o.lastIndexOf("}"));t.setAttribute("onclick",i)}function h(){let t=a();if(Object.keys(t).length===0)return;let s=window.location.hostname;document.querySelectorAll(e.selectors.join(", ")).forEach(n=>{if(f(n))return;let o=null;if(n instanceof HTMLAnchorElement&&n.href)o=n.href;else if(n instanceof HTMLElement&&n.dataset.href)o=n.dataset.href;else if(n instanceof HTMLElement&&n.onclick){let i=n.onclick.toString();o=g(i)}if(o&&c(o,s)){let i=u(o,t);n instanceof HTMLAnchorElement&&n.href?n.href=i:n instanceof HTMLElement&&n.dataset.href&&(n.dataset.href=i),n instanceof HTMLElement&&n.onclick&&o!==i&&m(n,o,i)}}),console.log("UTM parameters propagated to internal links:",t)}function d(){let t=a();if(Object.keys(t).length===0)return;new MutationObserver(function(r){r.forEach(function(n){n.addedNodes.forEach(function(o){if(o.nodeType===Node.ELEMENT_NODE){let i=o;i.matches&&i.matches(e.selectors.join(", "))&&l(i,t),"querySelectorAll"in i&&i.querySelectorAll(e.selectors.join(", ")).forEach(E=>l(E,t))}})})}).observe(document.body,{childList:!0,subtree:!0})}function l(t,s){if(f(t))return;let r=window.location.hostname,n=null;if(t instanceof HTMLAnchorElement&&t.href?n=t.href:t instanceof HTMLElement&&t.dataset.href&&(n=t.dataset.href),n&&c(n,r)){let o=u(n,s);t instanceof HTMLAnchorElement&&t.href?t.href=o:t instanceof HTMLElement&&t.dataset.href&&(t.dataset.href=o)}}function M(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){h(),d()}):(h(),d())}M()})();})();
1
+ "use strict";
2
+ (() => {
3
+ // bin/live-reload.js
4
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
5
+ new EventSource(`${"http://localhost:3000"}/esbuild`).addEventListener(
6
+ "change",
7
+ () => location.reload()
8
+ );
9
+ } else {
10
+ console.log("Live reload disabled: not running on localhost");
11
+ }
12
+
13
+ // src/tracking/utm-links.ts
14
+ (function() {
15
+ "use strict";
16
+ const config = {
17
+ utmKeys: [
18
+ "utm_source",
19
+ "utm_medium",
20
+ "utm_campaign",
21
+ "utm_term",
22
+ "utm_content",
23
+ "utm_id"
24
+ ],
25
+ selectors: [
26
+ "a[href]",
27
+ 'button[onclick*="location"]',
28
+ 'button[onclick*="window.open"]',
29
+ 'button[onclick*="href"]',
30
+ "[data-href]"
31
+ ]
32
+ };
33
+ function getCurrentUTMParams() {
34
+ const urlParams = new URLSearchParams(window.location.search);
35
+ const utmParams = {};
36
+ config.utmKeys.forEach((key) => {
37
+ if (urlParams.has(key)) {
38
+ const value = urlParams.get(key);
39
+ if (value) {
40
+ utmParams[key] = value;
41
+ }
42
+ }
43
+ });
44
+ return utmParams;
45
+ }
46
+ function isInternalLink(url, currentHost) {
47
+ try {
48
+ if (url.startsWith("/") || url.startsWith("./") || url.startsWith("../")) {
49
+ return true;
50
+ }
51
+ if (url.startsWith("http")) {
52
+ const linkHost = new URL(url).hostname;
53
+ return linkHost === currentHost;
54
+ }
55
+ if (url.startsWith("//")) {
56
+ const linkHost = new URL("http:" + url).hostname;
57
+ return linkHost === currentHost;
58
+ }
59
+ if (!url.includes("://")) {
60
+ return true;
61
+ }
62
+ return false;
63
+ } catch (e) {
64
+ console.warn("Error parsing URL:", url, e);
65
+ return true;
66
+ }
67
+ }
68
+ function addUTMToURL(url, utmParams) {
69
+ try {
70
+ const urlObj = new URL(url, window.location.origin);
71
+ Object.keys(utmParams).forEach((key) => {
72
+ if (!urlObj.searchParams.has(key)) {
73
+ urlObj.searchParams.set(key, utmParams[key]);
74
+ }
75
+ });
76
+ return urlObj.toString();
77
+ } catch (e) {
78
+ console.warn("Error processing URL:", url, e);
79
+ return url;
80
+ }
81
+ }
82
+ function hasUTMException(element) {
83
+ return element.hasAttribute("data-utm-exception") && element.getAttribute("data-utm-exception") === "true";
84
+ }
85
+ function extractURLFromOnclick(onclickStr) {
86
+ const urlMatch = onclickStr.match(
87
+ /["'](https?:\/\/[^"']+|\/[^"']*|[^"']*\.html?[^"']*)["']/
88
+ );
89
+ return urlMatch ? urlMatch[1] : null;
90
+ }
91
+ function updateOnclickAttribute(element, oldUrl, newUrl) {
92
+ if (!(element instanceof HTMLElement) || !element.onclick) return;
93
+ const onclickStr = element.onclick.toString();
94
+ const newOnclick = onclickStr.replace(oldUrl, newUrl);
95
+ const funcBody = newOnclick.slice(
96
+ newOnclick.indexOf("{") + 1,
97
+ newOnclick.lastIndexOf("}")
98
+ );
99
+ element.setAttribute("onclick", funcBody);
100
+ }
101
+ function propagateUTMParameters() {
102
+ const utmParams = getCurrentUTMParams();
103
+ if (Object.keys(utmParams).length === 0) {
104
+ return;
105
+ }
106
+ const currentHost = window.location.hostname;
107
+ const elements = document.querySelectorAll(config.selectors.join(", "));
108
+ elements.forEach((element) => {
109
+ if (hasUTMException(element)) {
110
+ return;
111
+ }
112
+ let url = null;
113
+ if (element instanceof HTMLAnchorElement && element.href) {
114
+ url = element.href;
115
+ } else if (element instanceof HTMLElement && element.dataset.href) {
116
+ url = element.dataset.href;
117
+ } else if (element instanceof HTMLElement && element.onclick) {
118
+ const onclickStr = element.onclick.toString();
119
+ url = extractURLFromOnclick(onclickStr);
120
+ }
121
+ if (url && isInternalLink(url, currentHost)) {
122
+ const updatedURL = addUTMToURL(url, utmParams);
123
+ if (element instanceof HTMLAnchorElement && element.href) {
124
+ element.href = updatedURL;
125
+ } else if (element instanceof HTMLElement && element.dataset.href) {
126
+ element.dataset.href = updatedURL;
127
+ }
128
+ if (element instanceof HTMLElement && element.onclick && url !== updatedURL) {
129
+ updateOnclickAttribute(element, url, updatedURL);
130
+ }
131
+ }
132
+ });
133
+ console.log(`UTM parameters propagated to internal links:`, utmParams);
134
+ }
135
+ function observeNewContent() {
136
+ const utmParams = getCurrentUTMParams();
137
+ if (Object.keys(utmParams).length === 0) {
138
+ return;
139
+ }
140
+ const observer = new MutationObserver(function(mutations) {
141
+ mutations.forEach(function(mutation) {
142
+ mutation.addedNodes.forEach(function(node) {
143
+ if (node.nodeType === Node.ELEMENT_NODE) {
144
+ const element = node;
145
+ if (element.matches && element.matches(config.selectors.join(", "))) {
146
+ processElement(element, utmParams);
147
+ }
148
+ if ("querySelectorAll" in element) {
149
+ const links = element.querySelectorAll(config.selectors.join(", "));
150
+ links.forEach((link) => processElement(link, utmParams));
151
+ }
152
+ }
153
+ });
154
+ });
155
+ });
156
+ observer.observe(document.body, {
157
+ childList: true,
158
+ subtree: true
159
+ });
160
+ }
161
+ function processElement(element, utmParams) {
162
+ if (hasUTMException(element)) {
163
+ return;
164
+ }
165
+ const currentHost = window.location.hostname;
166
+ let url = null;
167
+ if (element instanceof HTMLAnchorElement && element.href) {
168
+ url = element.href;
169
+ } else if (element instanceof HTMLElement && element.dataset.href) {
170
+ url = element.dataset.href;
171
+ }
172
+ if (url && isInternalLink(url, currentHost)) {
173
+ const updatedURL = addUTMToURL(url, utmParams);
174
+ if (element instanceof HTMLAnchorElement && element.href) {
175
+ element.href = updatedURL;
176
+ } else if (element instanceof HTMLElement && element.dataset.href) {
177
+ element.dataset.href = updatedURL;
178
+ }
179
+ }
180
+ }
181
+ function init() {
182
+ if (document.readyState === "loading") {
183
+ document.addEventListener("DOMContentLoaded", function() {
184
+ propagateUTMParameters();
185
+ observeNewContent();
186
+ });
187
+ } else {
188
+ propagateUTMParameters();
189
+ observeNewContent();
190
+ }
191
+ }
192
+ init();
193
+ })();
194
+ })();
195
+ //# sourceMappingURL=utm-links.js.map
@@ -1 +1,18 @@
1
- "use strict";(()=>{function e(o){console.log("Logged message:",o)}})();
1
+ "use strict";
2
+ (() => {
3
+ // bin/live-reload.js
4
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
5
+ new EventSource(`${"http://localhost:3000"}/esbuild`).addEventListener(
6
+ "change",
7
+ () => location.reload()
8
+ );
9
+ } else {
10
+ console.log("Live reload disabled: not running on localhost");
11
+ }
12
+
13
+ // src/utils/sample.ts
14
+ function logMessage(message) {
15
+ console.log("Logged message:", message);
16
+ }
17
+ })();
18
+ //# sourceMappingURL=sample.js.map