@meetelise/chat 1.20.147 → 1.20.149

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.
@@ -35,7 +35,10 @@ import fetchLeadSources from "../fetchLeadSources";
35
35
  import { formatPhoneNumber } from "./actions/formatPhoneNumber";
36
36
  import MyPubnub from "../MyPubnub";
37
37
  import { insertDNIIntoWebsite } from "../insertDNIIntoWebsite";
38
- import { insertLeadSourceIntoSchedulerLinks } from "../insertLeadSourceIntoSchedulerLinks";
38
+ import {
39
+ insertLeadSourceIntoSchedulerLinks,
40
+ replaceSSTLinkWithTourWidgetTrigger,
41
+ } from "../insertLeadSourceIntoSchedulerLinks";
39
42
 
40
43
  import "./actions/minimize-expand-button";
41
44
  import "./launcher/mobile-launcher";
@@ -217,10 +220,6 @@ export class MEChat extends LitElement {
217
220
  this.currentLeadSource = currentLeadSource;
218
221
  this.featureFlagShowDropdown = featureFlagShowDropdown;
219
222
 
220
- if (this.currentLeadSource) {
221
- insertLeadSourceIntoSchedulerLinks(this.currentLeadSource);
222
- }
223
-
224
223
  const buildingPhoneNumber = await getBuildingPhoneNumber(this.buildingSlug);
225
224
 
226
225
  this.enabledChatWidgets = {
@@ -247,6 +246,14 @@ export class MEChat extends LitElement {
247
246
  : this.building?.chatWidgets?.includes("SST") ?? true,
248
247
  };
249
248
 
249
+ if (this.enabledChatWidgets.sst) {
250
+ replaceSSTLinkWithTourWidgetTrigger(this.handleTourClicked);
251
+ } else {
252
+ if (this.currentLeadSource) {
253
+ insertLeadSourceIntoSchedulerLinks(this.currentLeadSource);
254
+ }
255
+ }
256
+
250
257
  if (webchatSettings && webchatSettings.config) {
251
258
  this.brandColor = webchatSettings.config.primaryColor ?? null;
252
259
  this.webchatConfigHasAutoOpenChat = webchatSettings.config.autoOpenChat;
@@ -1,3 +1,5 @@
1
+ // DEPRECATED: This file is no longer used. It was used to insert the lead source into the scheduler links.
2
+ // We now prevent the redirect and force tour SST widget to open instead in replaceSSTLinkWithTourWidgetTrigger.ts.
1
3
  export const insertLeadSourceIntoSchedulerLinks = (
2
4
  leadSource: string
3
5
  ): void => {
@@ -15,3 +17,18 @@ export const insertLeadSourceIntoSchedulerLinks = (
15
17
  }
16
18
  });
17
19
  };
20
+
21
+ export const replaceSSTLinkWithTourWidgetTrigger = (
22
+ handleTourClicked: (e: MouseEvent) => void
23
+ ): void => {
24
+ const sstRedirectElements = document.querySelectorAll("a");
25
+ sstRedirectElements.forEach(function (element) {
26
+ const href = element.getAttribute("href");
27
+ if (href && href.startsWith("https://app.meetelise.com/")) {
28
+ element.addEventListener("click", (event) => {
29
+ event.preventDefault(); // Prevents the default href redirect
30
+ handleTourClicked(event as MouseEvent);
31
+ });
32
+ }
33
+ });
34
+ };
@@ -36,6 +36,15 @@ export default async function postLeadSources({
36
36
  }
37
37
 
38
38
  export function getUrlQueryParameters(): { [queryKey: string]: string } | null {
39
+ if (isQueryMalformed()) {
40
+ return getMalformedQueryParameters();
41
+ }
42
+ return getStandardUrlQueryParameters();
43
+ }
44
+
45
+ function getStandardUrlQueryParameters(): {
46
+ [queryKey: string]: string;
47
+ } | null {
39
48
  const queryParams = new URLSearchParams(window.location.search);
40
49
 
41
50
  const hasUtmContent = queryParams.has("utm_content");
@@ -50,3 +59,23 @@ export function getUrlQueryParameters(): { [queryKey: string]: string } | null {
50
59
 
51
60
  return Object.fromEntries(queryParams);
52
61
  }
62
+
63
+ // Some clients are sending malformed query parameters, so we need to handle those
64
+ // i.e. .../?switch_cls[id]=94593/?utm_source=MillCreekPlaces&utm_medium=Community+Portfolio+Page
65
+ function getMalformedQueryParameters(): { [queryKey: string]: string } | null {
66
+ const url = window.location.search;
67
+ const allParams: { [queryKey: string]: string } = {};
68
+ const malformedParts = url.split("?").slice(1).join("&");
69
+ const pairs = malformedParts.split("&");
70
+ pairs.forEach((pair) => {
71
+ const [key, value] = pair.split("=");
72
+ if (key && value) {
73
+ allParams[decodeURIComponent(key)] = decodeURIComponent(value);
74
+ }
75
+ });
76
+
77
+ return allParams;
78
+ }
79
+
80
+ const isQueryMalformed = (): boolean =>
81
+ (window.location.search.match(/\?/g) || []).length > 1;