@meetelise/chat 1.22.52 → 1.22.53

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.
@@ -4,7 +4,7 @@ import { classMap } from "lit/directives/class-map.js";
4
4
  import { createRef, ref, Ref } from "lit/directives/ref.js";
5
5
  import { Launcher } from "./launcher/Launcher";
6
6
  import "./Scheduler/tour-scheduler";
7
- import Analytics, { LogType, sendLoggingEvent } from "../analytics";
7
+ import Analytics, { logSignal, LogType, sendLoggingEvent } from "../analytics";
8
8
  import fetchBuildingInfo, { Building } from "../fetchBuildingInfo";
9
9
  import {
10
10
  FeatureFlagsShowDropdown,
@@ -249,6 +249,18 @@ export class MEChat extends LitElement {
249
249
  if (!building) {
250
250
  // eslint-disable-next-line no-console
251
251
  console.warn("MeetElise Chat will NOT appear. Building does NOT exist.");
252
+ logSignal({
253
+ params: {
254
+ org_slug: this.orgSlug,
255
+ building_slug: this.buildingSlug,
256
+ is_pixel_on_site: true,
257
+ is_any_webchat_showing: false,
258
+ extra_data: {
259
+ webchat_no_show_reason: "building_does_not_exist",
260
+ },
261
+ },
262
+ isSampled: true,
263
+ });
252
264
  return false;
253
265
  }
254
266
  if (!building.launchedDateTime) {
@@ -256,11 +268,35 @@ export class MEChat extends LitElement {
256
268
  console.warn(
257
269
  "MeetElise Chat will NOT appear. Building is NOT launched (based on launched date time)."
258
270
  );
271
+ logSignal({
272
+ params: {
273
+ org_slug: this.orgSlug,
274
+ building_slug: this.buildingSlug,
275
+ is_pixel_on_site: true,
276
+ is_any_webchat_showing: false,
277
+ extra_data: {
278
+ webchat_no_show_reason: "building_not_launched",
279
+ },
280
+ },
281
+ isSampled: true,
282
+ });
259
283
  return false;
260
284
  }
261
285
  if (!building.active) {
262
286
  // eslint-disable-next-line no-console
263
287
  console.warn("MeetElise Chat will NOT appear. Building is NOT active.");
288
+ logSignal({
289
+ params: {
290
+ org_slug: this.orgSlug,
291
+ building_slug: this.buildingSlug,
292
+ is_pixel_on_site: true,
293
+ is_any_webchat_showing: false,
294
+ extra_data: {
295
+ webchat_no_show_reason: "building_not_active",
296
+ },
297
+ },
298
+ isSampled: true,
299
+ });
264
300
  return false;
265
301
  }
266
302
  if (!building.webchatScopeConfigured) {
@@ -268,6 +304,18 @@ export class MEChat extends LitElement {
268
304
  console.warn(
269
305
  "MeetElise Chat will NOT appear. Building is NOT webchat scope configured."
270
306
  );
307
+ logSignal({
308
+ params: {
309
+ org_slug: this.orgSlug,
310
+ building_slug: this.buildingSlug,
311
+ is_pixel_on_site: true,
312
+ is_any_webchat_showing: false,
313
+ extra_data: {
314
+ webchat_no_show_reason: "building_not_webchat_scope_configured",
315
+ },
316
+ },
317
+ isSampled: true,
318
+ });
271
319
  return false;
272
320
  }
273
321
 
@@ -280,6 +328,18 @@ export class MEChat extends LitElement {
280
328
  console.warn(
281
329
  "MeetElise Chat will NOT appear. Chat is in maintenance mode."
282
330
  );
331
+ logSignal({
332
+ params: {
333
+ org_slug: this.orgSlug,
334
+ building_slug: this.buildingSlug,
335
+ is_pixel_on_site: true,
336
+ is_any_webchat_showing: false,
337
+ extra_data: {
338
+ webchat_no_show_reason: "building_in_maintenance_mode",
339
+ },
340
+ },
341
+ isSampled: true,
342
+ });
283
343
  return false;
284
344
  }
285
345
  return true;
@@ -303,6 +363,16 @@ export class MEChat extends LitElement {
303
363
  );
304
364
  if (!shouldShowWebchat) {
305
365
  return;
366
+ } else {
367
+ logSignal({
368
+ params: {
369
+ org_slug: this.orgSlug,
370
+ building_slug: this.buildingSlug,
371
+ is_pixel_on_site: true,
372
+ is_any_webchat_showing: true,
373
+ },
374
+ isSampled: true,
375
+ });
306
376
  }
307
377
 
308
378
  this.building = building;
@@ -334,6 +404,7 @@ export class MEChat extends LitElement {
334
404
  if (buildingDetails && this.orgSlug) {
335
405
  overrideContactUsForm(
336
406
  this.orgSlug,
407
+ this.LeadSourceClient?.chatId ?? null,
337
408
  this.buildingSlug,
338
409
  this.LeadSourceClient?.leadSource ?? null
339
410
  );
@@ -478,11 +549,24 @@ export class MEChat extends LitElement {
478
549
  }
479
550
  }
480
551
  if (featureFlagInsertDNIWebsite && phoneNumberForSource?.number) {
481
- insertDNIIntoWebsite(
552
+ const totalReplacements = insertDNIIntoWebsite(
482
553
  phoneNumberForSource.number,
483
554
  this.orgSlug,
484
555
  this.buildingSlug
485
556
  );
557
+ if (totalReplacements > 0) {
558
+ logSignal({
559
+ params: {
560
+ org_slug: this.orgSlug,
561
+ building_slug: this.buildingSlug,
562
+ is_dni_insert_override_success: true,
563
+ extra_data: {
564
+ total_replacements: totalReplacements,
565
+ },
566
+ },
567
+ isSampled: true,
568
+ });
569
+ }
486
570
  }
487
571
 
488
572
  const devTestPhoneNumber = localStorage.getItem(
@@ -991,6 +1075,7 @@ const findElementById = (priorityIds: string[]): HTMLElement | null => {
991
1075
 
992
1076
  const overrideContactUsForm = async (
993
1077
  orgSlug: string,
1078
+ chatId: string | null,
994
1079
  buildingSlug?: string,
995
1080
  leadSource?: string | null
996
1081
  ): Promise<void> => {
@@ -1144,6 +1229,18 @@ const overrideContactUsForm = async (
1144
1229
  const clonedButton = btn.cloneNode(true) as HTMLButtonElement;
1145
1230
  btn.parentNode?.replaceChild(clonedButton, btn);
1146
1231
 
1232
+ if (clonedButton) {
1233
+ logSignal({
1234
+ params: {
1235
+ chat_id: chatId,
1236
+ org_slug: orgSlug,
1237
+ building_slug: buildingSlug,
1238
+ is_form_override_success: true,
1239
+ },
1240
+ isSampled: true,
1241
+ });
1242
+ }
1243
+
1147
1244
  clonedButton.onclick = async function (event) {
1148
1245
  validateFormElements();
1149
1246
 
package/src/analytics.ts CHANGED
@@ -178,3 +178,48 @@ export const sendLoggingEvent = async ({
178
178
  }
179
179
  );
180
180
  };
181
+
182
+ interface SignalLoggerProps {
183
+ org_slug: string;
184
+ building_slug: string;
185
+ chat_id?: string | null;
186
+ is_pixel_on_site?: boolean | null;
187
+ is_any_webchat_showing?: boolean | null;
188
+ is_form_override_success?: boolean | null;
189
+ is_dni_insert_override_success?: boolean | null;
190
+ extra_data?: Record<string, unknown> | null;
191
+ }
192
+
193
+ export const logSignal = async ({
194
+ params,
195
+ isSampled,
196
+ }: {
197
+ params: SignalLoggerProps;
198
+ isSampled?: boolean;
199
+ }): Promise<void> => {
200
+ try {
201
+ // fire 10% of the time
202
+ if (!!isSampled && Math.random() <= 0.1) {
203
+ return;
204
+ }
205
+ await axios.post(
206
+ `https://app.meetelise.com/platformApi/webchat/log/signal`,
207
+ {
208
+ ...params,
209
+ website_origin: window.location.origin,
210
+ website_search: window.location.search,
211
+ }
212
+ );
213
+ } catch (error) {
214
+ // eslint-disable-next-line no-console
215
+ console.warn(error);
216
+ sendLoggingEvent({
217
+ logType: LogType.error,
218
+ logTitle: "SIGNAL_LOGGER_ERROR",
219
+ logData: {
220
+ error,
221
+ },
222
+ buildingSlug: params.building_slug,
223
+ });
224
+ }
225
+ };
@@ -9,7 +9,7 @@ export const insertDNIIntoWebsite = (
9
9
  cleanPhoneNumber: string, // format of 1234567890
10
10
  orgSlug: string,
11
11
  buildingSlug?: string
12
- ): void => {
12
+ ): number => {
13
13
  const newHrefNumber = `tel:${cleanPhoneNumber}`;
14
14
  const newHrefSmsNumber = `sms:${cleanPhoneNumber}`;
15
15
  const newWhatsAppNumber = `whatsapp://send?phone=${cleanPhoneNumber}}`;
@@ -35,6 +35,8 @@ export const insertDNIIntoWebsite = (
35
35
  let shouldLogTextInsertionError = false;
36
36
  let shouldLogHrefInsertionError = false;
37
37
 
38
+ let totalReplacements = 0;
39
+
38
40
  for (let i = 0; i < allHTMLItems.length; i++) {
39
41
  if (allHTMLItems[i].nodeType !== Node.ELEMENT_NODE) {
40
42
  continue;
@@ -50,6 +52,9 @@ export const insertDNIIntoWebsite = (
50
52
  phoneNumberPattern,
51
53
  newPhoneNumber
52
54
  );
55
+ if (oldInnerHTML !== newInnerHTML) {
56
+ totalReplacements++;
57
+ }
53
58
  allHTMLItems[i].innerHTML = newInnerHTML;
54
59
 
55
60
  foundPhoneNumber = true;
@@ -59,7 +64,7 @@ export const insertDNIIntoWebsite = (
59
64
  }
60
65
  }
61
66
 
62
- // Handles the href phone number
67
+ // Handles the href phone number (so when you click the link, it will call the phone number)
63
68
  if (allHTMLItems[i].hasAttribute("href")) {
64
69
  const href = allHTMLItems[i].getAttribute("href");
65
70
  if (!href) {
@@ -136,4 +141,6 @@ export const insertDNIIntoWebsite = (
136
141
  orgSlug,
137
142
  });
138
143
  }
144
+
145
+ return totalReplacements;
139
146
  };