@garagem-ai/site-sdk 0.13.5 → 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/index.mjs CHANGED
@@ -479,6 +479,75 @@ async function getShareLink(options) {
479
479
  );
480
480
  }
481
481
 
482
+ // src/analytics-document.ts
483
+ var FILTER_SEGMENT_SOURCE = "(?:^|-)(?:quartos|banheiros|suites|suite|vagas)$|(?:^|-)(?:reais|m2)$|^mapa$";
484
+ var CLICK_ID_SOURCE = "^(?:fbclid|gclid|gbraid|wbraid|msclkid|ttclid|igshid|yclid|twclid|mc_eid|mc_cid|gad_source|_gl)$";
485
+ var DOCUMENT_QUERY_KEYS = ["q", "ordenar", "page", "pagina"];
486
+ var FILTER_SEGMENT = new RegExp(FILTER_SEGMENT_SOURCE, "i");
487
+ var CLICK_ID = new RegExp(CLICK_ID_SOURCE);
488
+ function isAnalyticsDocumentUrl(href) {
489
+ let url;
490
+ try {
491
+ url = new URL(href, "https://site.invalid");
492
+ } catch {
493
+ return true;
494
+ }
495
+ const pageRaw = param(url, "page") ?? param(url, "pagina");
496
+ if (pageRaw != null && pageRaw !== "") {
497
+ const page = Number(pageRaw);
498
+ if (!Number.isInteger(page) || page !== 1) return false;
499
+ }
500
+ const path = url.pathname.replace(/\/+$/, "").toLowerCase() || "/";
501
+ if (path !== "/imoveis" && !path.startsWith("/imoveis/")) return true;
502
+ for (const key of url.searchParams.keys()) {
503
+ if (ignoredQuery(key.toLowerCase())) continue;
504
+ return false;
505
+ }
506
+ const segments = path.split("/").filter(Boolean).slice(1);
507
+ return segments.every((segment) => !FILTER_SEGMENT.test(segment));
508
+ }
509
+ function param(url, name) {
510
+ for (const [key, value] of url.searchParams) {
511
+ if (key.toLowerCase() === name) return value;
512
+ }
513
+ return null;
514
+ }
515
+ function ignoredQuery(key) {
516
+ return DOCUMENT_QUERY_KEYS.includes(key) || key.startsWith("utm_") || CLICK_ID.test(key);
517
+ }
518
+ function analyticsDocumentGuardSource() {
519
+ return `const FILTER_SEGMENT = /${FILTER_SEGMENT_SOURCE}/i;
520
+ const CLICK_ID = /${CLICK_ID_SOURCE}/;
521
+ const DOCUMENT_QUERY = ["q", "ordenar", "page", "pagina"];
522
+
523
+ function documentUrl(href) {
524
+ let url;
525
+ try {
526
+ url = new URL(href, "https://site.invalid");
527
+ } catch {
528
+ return true;
529
+ }
530
+ let pageRaw = null;
531
+ for (const [key, value] of url.searchParams) {
532
+ const name = key.toLowerCase();
533
+ if (pageRaw == null && (name === "page" || name === "pagina")) pageRaw = value;
534
+ }
535
+ if (pageRaw != null && pageRaw !== "") {
536
+ const page = Number(pageRaw);
537
+ if (!Number.isInteger(page) || page !== 1) return false;
538
+ }
539
+ const path = url.pathname.replace(/\\/+$/, "").toLowerCase() || "/";
540
+ if (path !== "/imoveis" && !path.startsWith("/imoveis/")) return true;
541
+ for (const key of url.searchParams.keys()) {
542
+ const name = key.toLowerCase();
543
+ if (DOCUMENT_QUERY.includes(name) || name.startsWith("utm_") || CLICK_ID.test(name)) continue;
544
+ return false;
545
+ }
546
+ const segments = path.split("/").filter(Boolean).slice(1);
547
+ return segments.every((segment) => !FILTER_SEGMENT.test(segment));
548
+ }`;
549
+ }
550
+
482
551
  // ../search-url/types.ts
483
552
  var SEARCH_BASE_ROUTE = "imoveis";
484
553
  var MAX_PAGE = 1e4;
@@ -1355,8 +1424,17 @@ function searchChromeModel(schema, pathFilters, locationNames) {
1355
1424
 
1356
1425
  // src/analytics.ts
1357
1426
  var SITE_ANALYTICS_EVENT = "garagem:site-event";
1427
+ function browserPageHref() {
1428
+ if (typeof window === "undefined") return null;
1429
+ const location = window.location;
1430
+ return typeof location?.href === "string" ? location.href : null;
1431
+ }
1358
1432
  function emitSiteEvent(event, properties) {
1359
1433
  if (typeof window === "undefined") return;
1434
+ const href = browserPageHref();
1435
+ if (href && event !== "lead_generated" && !isAnalyticsDocumentUrl(href)) {
1436
+ return;
1437
+ }
1360
1438
  window.dispatchEvent(
1361
1439
  new CustomEvent(SITE_ANALYTICS_EVENT, { detail: { event, properties } })
1362
1440
  );
@@ -3288,7 +3366,10 @@ var STUDIO_SDK_CONTRACT = {
3288
3366
  "rangeDraftFromPath",
3289
3367
  // `unknownSearchLocation` is in git. Prompts inline the same check with
3290
3368
  // `parseSearchPublicPath` + `locationsPath` until this name is on the pin.
3291
- "unknownSearchLocation"
3369
+ "unknownSearchLocation",
3370
+ // In git. The installed client inlines the check. Naming it in a prompt
3371
+ // makes v0 import it from the pinned tarball, which does not export it.
3372
+ "isAnalyticsDocumentUrl"
3292
3373
  ],
3293
3374
  /**
3294
3375
  * maps.fndn.ai helpers (static map, street view, boundaries, travel
@@ -5027,6 +5108,7 @@ export {
5027
5108
  STUDIO_SITE_LAYOUT,
5028
5109
  TOOLBAR_PRIMARY_FILTER_IDS,
5029
5110
  VISIT_TIME_ZONE,
5111
+ analyticsDocumentGuardSource,
5030
5112
  applyMatchedPhotoCover,
5031
5113
  applyPathFilter,
5032
5114
  boundaryCitySlug,
@@ -5080,6 +5162,7 @@ export {
5080
5162
  hrefForAppliedChange,
5081
5163
  hrefForPathFilters,
5082
5164
  hrefWithExplicitPage,
5165
+ isAnalyticsDocumentUrl,
5083
5166
  isAnalyticsOnPin,
5084
5167
  isListingDetailPath,
5085
5168
  isMapBounds,