@garagem-ai/site-sdk 0.13.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garagem-ai/site-sdk",
3
- "version": "0.13.0",
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: location?.city,
92
- location_neighborhood: location?.neighborhood,
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),
@@ -25,10 +25,12 @@ export const STUDIO_SDK_CONTRACT = {
25
25
  * does not export them. Property registration shipped in 0.10.0.
26
26
  * Weighted map buckets (`map.buckets`, clustered by the hook) shipped
27
27
  * in 0.11.0. Share links (`getShareLink`, `/p/[token]`) shipped in
28
- * 0.12.0. Search filter helpers (`visibleSearchFilters` /
29
- * `toolbarFilterIds`) shipped in 0.4.12 and remain on this pin.
28
+ * 0.12.0. Analytics catalog events (`trackListingView` plus the search
29
+ * and lead emitters) shipped in 0.13.0. Search filter helpers
30
+ * (`visibleSearchFilters` / `toolbarFilterIds`) shipped in 0.4.12 and
31
+ * remain on this pin.
30
32
  */
31
- minNpmVersion: "0.12.0",
33
+ minNpmVersion: "0.13.0",
32
34
  /** Historical: older tarballs inject card CSS when those components mount. */
33
35
  selfInjectSince: "0.4.2",
34
36
  chromeStrategy: "app-owned" as const,