@garagem-ai/site-sdk 0.13.4 → 0.13.6

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/react.mjs CHANGED
@@ -4,6 +4,43 @@
4
4
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
5
  import { usePathname, useRouter } from "next/navigation";
6
6
 
7
+ // src/analytics-document.ts
8
+ var FILTER_SEGMENT_SOURCE = "(?:^|-)(?:quartos|banheiros|suites|suite|vagas)$|(?:^|-)(?:reais|m2)$|^mapa$";
9
+ var CLICK_ID_SOURCE = "^(?:fbclid|gclid|gbraid|wbraid|msclkid|ttclid|igshid|yclid|twclid|mc_eid|mc_cid|gad_source|_gl)$";
10
+ var DOCUMENT_QUERY_KEYS = ["q", "ordenar", "page", "pagina"];
11
+ var FILTER_SEGMENT = new RegExp(FILTER_SEGMENT_SOURCE, "i");
12
+ var CLICK_ID = new RegExp(CLICK_ID_SOURCE);
13
+ function isAnalyticsDocumentUrl(href) {
14
+ let url;
15
+ try {
16
+ url = new URL(href, "https://site.invalid");
17
+ } catch {
18
+ return true;
19
+ }
20
+ const pageRaw = param(url, "page") ?? param(url, "pagina");
21
+ if (pageRaw != null && pageRaw !== "") {
22
+ const page = Number(pageRaw);
23
+ if (!Number.isInteger(page) || page !== 1) return false;
24
+ }
25
+ const path = url.pathname.replace(/\/+$/, "").toLowerCase() || "/";
26
+ if (path !== "/imoveis" && !path.startsWith("/imoveis/")) return true;
27
+ for (const key of url.searchParams.keys()) {
28
+ if (ignoredQuery(key.toLowerCase())) continue;
29
+ return false;
30
+ }
31
+ const segments = path.split("/").filter(Boolean).slice(1);
32
+ return segments.every((segment) => !FILTER_SEGMENT.test(segment));
33
+ }
34
+ function param(url, name) {
35
+ for (const [key, value] of url.searchParams) {
36
+ if (key.toLowerCase() === name) return value;
37
+ }
38
+ return null;
39
+ }
40
+ function ignoredQuery(key) {
41
+ return DOCUMENT_QUERY_KEYS.includes(key) || key.startsWith("utm_") || CLICK_ID.test(key);
42
+ }
43
+
7
44
  // ../search-url/types.ts
8
45
  var SEARCH_BASE_ROUTE = "imoveis";
9
46
  var MAX_PAGE = 1e4;
@@ -71,6 +108,19 @@ var LISTING_TYPE_ALIASES = {
71
108
  rental: ["alugar"]
72
109
  };
73
110
 
111
+ // ../search-url/listing-identity.ts
112
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
113
+ var LISTING_CODE_RE = /^(?:[A-Za-z0-9]+|[A-Z0-9]+(?:-[A-Z0-9]+)+)$/;
114
+ var LETTER_CODE_RE = /^[A-Z]{5}$/;
115
+ function isShortListingIdentity(segment) {
116
+ if (UUID_RE.test(segment) || LETTER_CODE_RE.test(segment)) return true;
117
+ return /\d/.test(segment) && LISTING_CODE_RE.test(segment);
118
+ }
119
+ function isShortListingPath(pathname) {
120
+ const parts = (pathname.split(/[?#]/)[0] ?? "").split("/").filter(Boolean);
121
+ return parts.length === 2 && parts[0] === SEARCH_BASE_ROUTE && isShortListingIdentity(parts[1] ?? "");
122
+ }
123
+
74
124
  // ../search-url/path.ts
75
125
  function toArray(value) {
76
126
  if (value === void 0) return [];
@@ -167,6 +217,7 @@ function parseSearchPublicPath(pathname, dictionary = emptySearchUrlDictionary()
167
217
  if (segments.some((segment) => segment.toLowerCase().startsWith("id-"))) {
168
218
  return null;
169
219
  }
220
+ if (isShortListingPath(raw)) return null;
170
221
  const filters = {};
171
222
  const locationParts = [];
172
223
  const propertyTypes = [];
@@ -499,9 +550,9 @@ function pathnameOnly(pathname) {
499
550
  return String(pathname || "").split(/[?#]/)[0] || "/";
500
551
  }
501
552
  function isListingDetailPath(pathname) {
502
- const parts = pathnameOnly(pathname).split("/").filter(Boolean);
503
- const last = parts[parts.length - 1] || "";
504
- return last.toLowerCase().startsWith("id-");
553
+ const path = pathnameOnly(pathname);
554
+ const last = path.split("/").filter(Boolean).pop() || "";
555
+ return last.toLowerCase().startsWith("id-") || isShortListingPath(path);
505
556
  }
506
557
  function readPublicSearch(pathname, search, dictionary) {
507
558
  const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
@@ -669,8 +720,17 @@ function clearStagedPathFilters(current, keepFilterIds = []) {
669
720
 
670
721
  // src/analytics.ts
671
722
  var SITE_ANALYTICS_EVENT = "garagem:site-event";
723
+ function browserPageHref() {
724
+ if (typeof window === "undefined") return null;
725
+ const location = window.location;
726
+ return typeof location?.href === "string" ? location.href : null;
727
+ }
672
728
  function emitSiteEvent(event, properties) {
673
729
  if (typeof window === "undefined") return;
730
+ const href = browserPageHref();
731
+ if (href && event !== "lead_generated" && !isAnalyticsDocumentUrl(href)) {
732
+ return;
733
+ }
674
734
  window.dispatchEvent(
675
735
  new CustomEvent(SITE_ANALYTICS_EVENT, { detail: { event, properties } })
676
736
  );