@salesforcedevs/dx-components 1.32.0-alpha.1 → 1.32.0-alpha.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": "@salesforcedevs/dx-components",
3
- "version": "1.32.0-alpha.1",
3
+ "version": "1.32.0-alpha.2",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "luxon": "3.4.4",
45
45
  "msw": "^2.12.4"
46
46
  },
47
- "gitHead": "9f48b66de9a139bcf6cfac4052772726f00f6d8e"
47
+ "gitHead": "f42dc4194e762fe78415b45c729e966c0a680f8d"
48
48
  }
@@ -81,6 +81,9 @@
81
81
  class="dx-result-title"
82
82
  target={result.openInNewTab}
83
83
  rel={result.rel}
84
+ data-index={result.resultIndex}
85
+ data-title={result.title}
86
+ onclick={onSearchResultClick}
84
87
  >
85
88
  {result.title}
86
89
  </a>
@@ -15,6 +15,7 @@ interface SearchResultDisplay {
15
15
  href: string;
16
16
  matchedText: string;
17
17
  uniqueId: string;
18
+ resultIndex: number;
18
19
  openInNewTab: string | undefined;
19
20
  rel: string | undefined;
20
21
  }
@@ -129,11 +130,28 @@ export default class SearchResults extends LightningElement {
129
130
  href,
130
131
  matchedText: item.matchedText ?? "",
131
132
  uniqueId: href || `result-${index}`,
133
+ resultIndex: index + 1,
132
134
  openInNewTab: isExternal ? "_blank" : undefined,
133
135
  rel: isExternal ? "noopener noreferrer" : undefined
134
136
  };
135
137
  }
136
138
 
139
+ private onSearchResultClick(e: MouseEvent) {
140
+ const anchor = e.currentTarget as HTMLAnchorElement;
141
+ const index = Number(anchor.dataset.index ?? "0");
142
+ const title = anchor.dataset.title ?? "";
143
+ const href = anchor.href ?? "";
144
+ trackGTM(anchor, "custEv_scopedSearchlinkClick", {
145
+ click_text: title,
146
+ click_url: href,
147
+ element_title: title,
148
+ element_type: "link",
149
+ content_category: "documentation",
150
+ search_term: this.query,
151
+ search_result_position: index
152
+ });
153
+ }
154
+
137
155
  private trackSearchResultsOnce(term: string, resultCount: number) {
138
156
  if (this.didTrackThisSearch) {
139
157
  return;
@@ -1,5 +1,6 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import debounce from "debounce";
3
+ import { track as trackGTM } from "dxUtils/analytics";
3
4
  import {
4
5
  type Data360SearchCacheItem,
5
6
  type Data360SearchResultItem,
@@ -85,6 +86,7 @@ export default class SidebarSearch extends LightningElement {
85
86
  private value: string = "";
86
87
  private didRender = false;
87
88
  private data360SearchInitialized: boolean = false;
89
+ private didTrackThisSearch: boolean = false;
88
90
 
89
91
  private get isDropdownOpen() {
90
92
  return (
@@ -173,11 +175,13 @@ export default class SidebarSearch extends LightningElement {
173
175
 
174
176
  private async fetchDataCloudSearch(): Promise<void> {
175
177
  try {
176
- const rawResults = await fetchSearch(this.value.trim());
178
+ const query = this.value.trim();
179
+ const rawResults = await fetchSearch(query);
177
180
  const results: SidebarSearchResult[] = rawResults.map(
178
181
  this.normalizeDataCloudResult
179
182
  );
180
183
  this.dispatchChange(results);
184
+ this.trackSearchResultsOnce(query, results.length);
181
185
  const cacheItems: Data360SearchCacheItem[] = results.map((r) => ({
182
186
  title: r.title,
183
187
  titleHighlights: r.titleHighlights,
@@ -198,6 +202,19 @@ export default class SidebarSearch extends LightningElement {
198
202
  }
199
203
  }
200
204
 
205
+ private trackSearchResultsOnce(term: string, resultCount: number): void {
206
+ if (this.didTrackThisSearch || !term) {
207
+ return;
208
+ }
209
+ this.didTrackThisSearch = true;
210
+ trackGTM(this.template.host, "custEv_scopedSearch", {
211
+ search_term: term,
212
+ search_category: "",
213
+ search_type: "site search",
214
+ search_result_count: resultCount
215
+ });
216
+ }
217
+
201
218
  private dispatchChange(results: SidebarSearchResult[]) {
202
219
  this.dispatchEvent(
203
220
  new CustomEvent("change", {
@@ -279,6 +296,7 @@ export default class SidebarSearch extends LightningElement {
279
296
 
280
297
  private handleValueChange(isSyncingSearchValue = false) {
281
298
  if (this.value) {
299
+ this.didTrackThisSearch = false;
282
300
  this.dispatchOnLoading(true);
283
301
  this.submitSearch(isSyncingSearchValue);
284
302
  } else {
@@ -1,5 +1,6 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import cx from "classnames";
3
+ import { track } from "dxUtils/analytics";
3
4
  import { HighlightedSections } from "typings/custom";
4
5
 
5
6
  const toChunks = (value: string, highlights: HighlightedSections) => {
@@ -72,6 +73,13 @@ export default class SidebarSearchResult extends LightningElement {
72
73
 
73
74
  private onClick(e: PointerEvent) {
74
75
  e.preventDefault();
76
+ track(e.currentTarget!, "custEv_linkClick", {
77
+ click_text: this.header,
78
+ click_url: this.href,
79
+ element_title: this.header,
80
+ element_type: "link",
81
+ content_category: "documentation"
82
+ });
75
83
  this.select();
76
84
  window.location.href = this.href;
77
85
  }