@garagem-ai/site-sdk 0.13.1 → 0.13.2
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.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +14 -7
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +14 -7
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/analytics.ts +23 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@garagem-ai/site-sdk",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Typed, runtime-agnostic SDK for building custom real estate sites against the Garagem platform. Drop into any Next.js (or other JS) project to fetch listings, sites and CMS data.",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/analytics.ts
CHANGED
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
* consent, the visitor cookie and the site id, and posts it to `/api/t`.
|
|
5
5
|
* Without that listener (server render, other hosts) nothing is sent.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
changedPathFilters,
|
|
9
|
-
displayPathLocation,
|
|
10
|
-
type LocationNameTables,
|
|
11
|
-
} from "./search-engine";
|
|
7
|
+
import { changedPathFilters, type LocationNameTables } from "./search-engine";
|
|
12
8
|
import type { AppliedSearchQuery, Listing, SearchPathFilters } from "./types";
|
|
13
9
|
|
|
14
10
|
export const SITE_ANALYTICS_EVENT = "garagem:site-event";
|
|
@@ -39,6 +35,19 @@ function minOf(value: number | number[] | undefined): number | undefined {
|
|
|
39
35
|
return value.length ? Math.min(...value) : undefined;
|
|
40
36
|
}
|
|
41
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The path parser reads any unknown segment as a location (`/imoveis/sp/sobre`
|
|
40
|
+
* → city `sobre`), so only a slug the site's location table knows is a place.
|
|
41
|
+
*/
|
|
42
|
+
function knownLocationName(
|
|
43
|
+
table: Record<string, string> | undefined,
|
|
44
|
+
slug: string | undefined
|
|
45
|
+
): string | undefined {
|
|
46
|
+
if (!slug || !table) return undefined;
|
|
47
|
+
const key = Object.hasOwn(table, slug) ? slug : slug.toLowerCase();
|
|
48
|
+
return (Object.hasOwn(table, key) && table[key]) || undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
/** Call once per listing page in the browser (an effect keyed on `listing.id`). */
|
|
43
52
|
export function trackListingView(
|
|
44
53
|
listing: Pick<
|
|
@@ -79,17 +88,19 @@ export function trackSearchResults(input: {
|
|
|
79
88
|
total: number;
|
|
80
89
|
page: number;
|
|
81
90
|
}): void {
|
|
82
|
-
const { pathFilters, applied, listingIds, page } = input;
|
|
83
|
-
const location = displayPathLocation(
|
|
84
|
-
pathFilters.location,
|
|
85
|
-
input.locationNames
|
|
86
|
-
);
|
|
91
|
+
const { pathFilters, applied, locationNames, listingIds, page } = input;
|
|
87
92
|
emitSiteEvent("property_search", {
|
|
88
93
|
query: applied.query || undefined,
|
|
89
94
|
business_type: catalogBusinessType(pathFilters.listingType),
|
|
90
95
|
property_type: pathFilters.propertyType,
|
|
91
|
-
location_city:
|
|
92
|
-
|
|
96
|
+
location_city: knownLocationName(
|
|
97
|
+
locationNames?.cities,
|
|
98
|
+
pathFilters.location?.city
|
|
99
|
+
),
|
|
100
|
+
location_neighborhood: knownLocationName(
|
|
101
|
+
locationNames?.neighborhoods,
|
|
102
|
+
pathFilters.location?.neighborhood
|
|
103
|
+
),
|
|
93
104
|
min_price: pathFilters.price?.min,
|
|
94
105
|
max_price: pathFilters.price?.max,
|
|
95
106
|
min_bedrooms: minOf(pathFilters.bedrooms),
|