@meetelise/chat 1.22.75 → 1.22.76

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.
@@ -15,6 +15,7 @@ import {
15
15
  fetchFeatureFlagMaintenanceMode,
16
16
  fetchFeatureFlagReplaceScheduleTourCtaWebsite,
17
17
  fetchFeatureFlagShowMarketingSourceDropdown,
18
+ fetchFeatureFlagUseApplicationsLinkReplacement,
18
19
  fetchFeatureFlagUseOverrideContactUsForm,
19
20
  fetchFeatureFlagUsePhoneNumberBySource,
20
21
  } from "../fetchFeatureFlag";
@@ -66,6 +67,7 @@ import LeadSourceClient, {
66
67
  import noop from "lodash/noop";
67
68
  import { updateRentgrataToken } from "../rentgrata";
68
69
  import { WidgetType } from "../main/MEChat";
70
+ import { replaceSelectButtonsWithNewLink } from "../replaceSelectButtonsWithNewLink";
69
71
 
70
72
  @customElement("me-chat")
71
73
  export class MEChat extends LitElement {
@@ -433,6 +435,7 @@ export class MEChat extends LitElement {
433
435
  featureFlagUseDNI,
434
436
  featureFlagInsertDNIWebsite,
435
437
  featureFlagReplaceScheduleTourCtaWebsite,
438
+ featureFlagUseApplicationsLinkReplacement,
436
439
  ] = await Promise.all([
437
440
  fetchBuildingABTestType(this.buildingSlug),
438
441
  fetchLeadSources(this.orgSlug, this.buildingSlug),
@@ -440,6 +443,7 @@ export class MEChat extends LitElement {
440
443
  fetchFeatureFlagUsePhoneNumberBySource(this.buildingSlug),
441
444
  fetchFeatureFlagInsertDNIWebsite(this.buildingSlug),
442
445
  fetchFeatureFlagReplaceScheduleTourCtaWebsite(this.buildingSlug),
446
+ fetchFeatureFlagUseApplicationsLinkReplacement(this.buildingSlug),
443
447
  ]);
444
448
 
445
449
  if (this.buildingWebchatView) {
@@ -594,6 +598,27 @@ export class MEChat extends LitElement {
594
598
  }
595
599
  }
596
600
  getRawAvailabilities(buildingDetails.id); // we're not using this here, just want to cache the result
601
+
602
+ if (featureFlagUseApplicationsLinkReplacement && this.buildingSlug) {
603
+ const totalReplacements = replaceSelectButtonsWithNewLink(
604
+ `https://applications.eliseai.com/building/${this.buildingSlug}`,
605
+ this.orgSlug,
606
+ this.buildingSlug
607
+ );
608
+ if (totalReplacements > 0) {
609
+ logSignal({
610
+ params: {
611
+ org_slug: this.orgSlug,
612
+ building_slug: this.buildingSlug,
613
+ is_application_link_replacement_success: true,
614
+ extra_data: {
615
+ total_replacements: totalReplacements,
616
+ },
617
+ },
618
+ sampleRate: this.sampleRateToUse,
619
+ });
620
+ }
621
+ }
597
622
  };
598
623
 
599
624
  private initializeChatVariables = async (): Promise<void> => {
package/src/analytics.ts CHANGED
@@ -187,6 +187,7 @@ interface SignalLoggerProps {
187
187
  is_any_webchat_showing?: boolean | null;
188
188
  is_form_override_success?: boolean | null;
189
189
  is_dni_insert_override_success?: boolean | null;
190
+ is_application_link_replacement_success?: boolean | null;
190
191
  extra_data?: Record<string, unknown> | null;
191
192
  }
192
193
 
@@ -223,3 +223,28 @@ export async function fetchFeatureFlagReplaceScheduleTourCtaWebsite(
223
223
  return false;
224
224
  }
225
225
  }
226
+
227
+ export async function fetchFeatureFlagUseApplicationsLinkReplacement(
228
+ buildingSlug: string
229
+ ): Promise<boolean> {
230
+ if (!buildingSlug) {
231
+ return false;
232
+ }
233
+ try {
234
+ const featureFlagResponse = await axios.get(
235
+ featureFlagEndpointV1(buildingSlug),
236
+ {
237
+ params: {
238
+ building_slug: buildingSlug,
239
+ flag_type: "bool",
240
+ feature_flag: "webchat-use-applications-link-replacement",
241
+ default_str: null,
242
+ default_bool: false,
243
+ },
244
+ }
245
+ );
246
+ return featureFlagResponse.data;
247
+ } catch (_) {
248
+ return false;
249
+ }
250
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Script to find all application links/buttons on a page and replace them with a
3
+ * new elise application link.
4
+ */
5
+ import { LogType, sendLoggingEvent } from "./analytics";
6
+
7
+ /**
8
+ * Script to find all "Select" buttons with specific URL patterns and replace them with a
9
+ * new application link.
10
+ */
11
+ export const replaceSelectButtonsWithNewLink = (
12
+ newApplicationLink: string,
13
+ orgSlug: string,
14
+ buildingSlug?: string
15
+ ): number => {
16
+ const urlPatterns = [
17
+ /thehavenatgreenhill\.securecafe\.com\/onlineleasing\/the-haven-at-greenhill\/oleapplication\.aspx(\?.*)?$/,
18
+ /securecafe\.com\/onlineleasing.*\/oleapplication\.aspx(\?.*)?$/,
19
+ /\/onlineleasing.*\/oleapplication\.aspx(\?.*)?$/,
20
+ ];
21
+
22
+ const allElements = document.body.getElementsByTagName("a");
23
+ let totalReplacements = 0;
24
+
25
+ for (let i = 0; i < allElements.length; i++) {
26
+ const element = allElements[i] as HTMLAnchorElement;
27
+ if (element.nodeType !== Node.ELEMENT_NODE) continue;
28
+
29
+ const matchesUrlPattern = urlPatterns.some((pattern) =>
30
+ pattern.test(element.href)
31
+ );
32
+ const isSelectButtonWithUrl = matchesUrlPattern;
33
+
34
+ if (isSelectButtonWithUrl) {
35
+ const oldHref = element.getAttribute("href");
36
+ element.setAttribute("href", newApplicationLink);
37
+ totalReplacements++;
38
+
39
+ sendLoggingEvent({
40
+ logTitle: "SELECT_BUTTON_LINK_REPLACEMENT",
41
+ logData: {
42
+ type: "link-replacement",
43
+ oldHref,
44
+ newHref: newApplicationLink,
45
+ website: window.location.href,
46
+ },
47
+ logType: LogType.info,
48
+ buildingSlug,
49
+ orgSlug,
50
+ });
51
+ }
52
+ }
53
+
54
+ if (totalReplacements === 0) {
55
+ sendLoggingEvent({
56
+ logTitle: "SELECT_BUTTON_LINK_REPLACEMENT",
57
+ logData: {
58
+ type: "no-select-buttons-found",
59
+ website: window.location.href,
60
+ },
61
+ logType: LogType.warn,
62
+ buildingSlug,
63
+ orgSlug,
64
+ });
65
+ }
66
+
67
+ return totalReplacements;
68
+ };