@garagem-ai/site-sdk 0.13.5 → 0.14.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.
- package/dist/index.d.mts +31 -12
- package/dist/index.d.ts +31 -12
- package/dist/index.js +132 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +66 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +66 -2
- package/dist/react.mjs.map +1 -1
- package/dist/{types-photo-search-CVPyF9zC.d.mts → types-photo-search-CokmqLjn.d.mts} +13 -0
- package/dist/{types-photo-search-CVPyF9zC.d.ts → types-photo-search-CokmqLjn.d.ts} +13 -0
- package/package.json +1 -1
- package/src/analytics-document.ts +90 -0
- package/src/analytics.ts +13 -0
- package/src/index.ts +6 -0
- package/src/listing-card-model.ts +28 -3
- package/src/studio-contract.ts +34 -2
- package/src/types.ts +8 -0
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;
|
|
@@ -683,8 +720,17 @@ function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
|
683
720
|
|
|
684
721
|
// src/analytics.ts
|
|
685
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
|
+
}
|
|
686
728
|
function emitSiteEvent(event, properties) {
|
|
687
729
|
if (typeof window === "undefined") return;
|
|
730
|
+
const href = browserPageHref();
|
|
731
|
+
if (href && event !== "lead_generated" && !isAnalyticsDocumentUrl(href)) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
688
734
|
window.dispatchEvent(
|
|
689
735
|
new CustomEvent(SITE_ANALYTICS_EVENT, { detail: { event, properties } })
|
|
690
736
|
);
|
|
@@ -1398,9 +1444,21 @@ import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useSta
|
|
|
1398
1444
|
function listingLocationLabel(location) {
|
|
1399
1445
|
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
1400
1446
|
}
|
|
1447
|
+
function cardPriceLabel(isPrivate, collapsed, price, formattedPrice) {
|
|
1448
|
+
if (isPrivate) return "Sob consulta";
|
|
1449
|
+
if (collapsed && price != null) return `A partir de ${formattedPrice}`;
|
|
1450
|
+
return formattedPrice;
|
|
1451
|
+
}
|
|
1401
1452
|
function toListingCardModel(listing) {
|
|
1402
1453
|
const isPrivate = listing.priceVisibility === "private";
|
|
1403
1454
|
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
1455
|
+
const unitCount = listing.development?.unitCount;
|
|
1456
|
+
const collapsed = typeof unitCount === "number" && unitCount > 1;
|
|
1457
|
+
const formattedPrice = formatListingPrice(
|
|
1458
|
+
listing.price,
|
|
1459
|
+
"pt-BR",
|
|
1460
|
+
listing.currency ?? "BRL"
|
|
1461
|
+
);
|
|
1404
1462
|
return {
|
|
1405
1463
|
href: listingPublicPath(listing),
|
|
1406
1464
|
title: listing.title,
|
|
@@ -1408,7 +1466,12 @@ function toListingCardModel(listing) {
|
|
|
1408
1466
|
businessLabel: listingBusinessLabel(listing.businessType),
|
|
1409
1467
|
priceVisibility: listing.priceVisibility,
|
|
1410
1468
|
price: listing.price,
|
|
1411
|
-
priceLabel:
|
|
1469
|
+
priceLabel: cardPriceLabel(
|
|
1470
|
+
isPrivate,
|
|
1471
|
+
collapsed,
|
|
1472
|
+
listing.price,
|
|
1473
|
+
formattedPrice
|
|
1474
|
+
),
|
|
1412
1475
|
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
1413
1476
|
locationLabel: listingLocationLabel(listing.location || {}),
|
|
1414
1477
|
propertyType: listing.property?.type ?? null,
|
|
@@ -1417,7 +1480,8 @@ function toListingCardModel(listing) {
|
|
|
1417
1480
|
bedrooms: listing.property?.bedrooms ?? null,
|
|
1418
1481
|
bathrooms: listing.property?.bathrooms ?? null,
|
|
1419
1482
|
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
1420
|
-
areaM2: area ?? null
|
|
1483
|
+
areaM2: area ?? null,
|
|
1484
|
+
unitCount: collapsed && typeof unitCount === "number" ? unitCount : null
|
|
1421
1485
|
};
|
|
1422
1486
|
}
|
|
1423
1487
|
|