@meetelise/chat 1.20.73 → 1.20.75

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/src/MEChat.ts CHANGED
@@ -273,6 +273,7 @@ const overrideContactUsForm = async (
273
273
  "Missing the following form elements: " + missingElements.join(", ")
274
274
  );
275
275
  }
276
+ const originalButtonText = btn.textContent;
276
277
 
277
278
  // Replace the original form element with the cloned one
278
279
  const clonedButton = btn.cloneNode(true) as HTMLButtonElement;
@@ -282,6 +283,9 @@ const overrideContactUsForm = async (
282
283
  if (!isValid()) return;
283
284
  event.preventDefault();
284
285
 
286
+ clonedButton.textContent = "Processing request...";
287
+ clonedButton.disabled = true;
288
+
285
289
  const formValues: { [key: string]: string | undefined } = {};
286
290
  Object.entries(getFormElements()).forEach(
287
291
  ([key, val]) => (formValues[key] = val?.value)
@@ -325,21 +329,25 @@ const overrideContactUsForm = async (
325
329
  "org-slug": orgSlug,
326
330
  },
327
331
  body: jsonData,
328
- }).then((response) => {
329
- if (!response.ok) {
330
- throw new Error(`HTTP error ${response.status}`);
331
- }
332
+ })
333
+ .then((response) => {
334
+ if (!response.ok) {
335
+ throw new Error(`HTTP error ${response.status}`);
336
+ }
337
+
338
+ form.reset();
339
+ Object.values(getFormElements()).forEach((el) => {
340
+ if (!el) return;
341
+ el.disabled = true;
342
+ });
343
+ clonedButton.textContent = "Submitted";
344
+ clonedButton.disabled = true;
332
345
 
333
- form.reset();
334
- Object.values(getFormElements()).forEach((el) => {
335
- if (!el) return;
336
- el.disabled = true;
346
+ return response.json();
347
+ })
348
+ .catch(() => {
349
+ clonedButton.textContent = originalButtonText;
337
350
  });
338
- clonedButton.textContent = "Submitted";
339
- clonedButton.disabled = true;
340
-
341
- return response.json();
342
- });
343
351
  };
344
352
  };
345
353
 
@@ -30,6 +30,7 @@ import { InputStyles } from "../actions/InputStyles";
30
30
  import { classMap } from "lit/directives/class-map.js";
31
31
  import postLeadSources from "../../postLeadSources";
32
32
  import { FeatureFlagsShowDropdown } from "../../fetchFeatureFlag";
33
+ import { pushGtmEvent } from "../../gtm";
33
34
 
34
35
  const getHumanReadableLayout = (layout: string) => {
35
36
  if (layout == "studio") return "Studio";
@@ -373,6 +374,30 @@ export class TourScheduler extends LitElement {
373
374
  ? this.selectedLeadSource.value
374
375
  : this.currentLeadSource;
375
376
 
377
+ const leadSources = [
378
+ ...new Set(
379
+ parsedLeadSource
380
+ ? [parsedLeadSource, "property-website"]
381
+ : ["property-website"]
382
+ ),
383
+ ];
384
+ pushGtmEvent("scheduleTourSubmitted", {
385
+ email: this.email,
386
+ phone: `+1${this.phoneNumber.match(/\d/g)?.join("")}`,
387
+ firstName: this.firstNameInput.value,
388
+ lastName: this.lastNameInput.value,
389
+ tourType: tourTypeForSubmission[this.tourType],
390
+ tourTime: `${this.selectedTime.datetime}${this.selectedTime.offset}`,
391
+ layouts: this.layoutTypeSelect.value
392
+ ? [this.layoutTypeSelect.value]
393
+ : null,
394
+ unitNumbers:
395
+ this.unitTypeSelect && this.unitTypeSelect.value
396
+ ? [this.unitTypeSelect.value]
397
+ : null,
398
+ originatingSource:
399
+ leadSources.find((i) => i !== "property-website") || null,
400
+ });
376
401
  const data = {
377
402
  referrer: document.referrer,
378
403
  email_address: this.email,
@@ -15,6 +15,7 @@ import {
15
15
  import { InputStyles } from "./InputStyles";
16
16
  import axios from "axios";
17
17
  import { FeatureFlagsShowDropdown } from "../../fetchFeatureFlag";
18
+ import { pushGtmEvent } from "../../gtm";
18
19
 
19
20
  @customElement("email-us-window")
20
21
  export class EmailUsWindow extends LitElement {
@@ -488,7 +489,15 @@ const createEmail = async (
488
489
  // @ts-ignore
489
490
  query_params: Object.fromEntries(queryParams.entries()),
490
491
  };
491
-
492
+ pushGtmEvent("emailUsSubmitted", {
493
+ firstName,
494
+ lastName,
495
+ email,
496
+ phone: formattedPhoneNumber,
497
+ message,
498
+ originatingSource:
499
+ leadSources.find((i) => i !== "property-website") || null,
500
+ });
492
501
  await axios.post(
493
502
  "https://app.meetelise.com/platformApi/state/create/emailMe",
494
503
  requestBody,
@@ -10,6 +10,7 @@ import {
10
10
  } from "./formatPhoneNumber";
11
11
  import { InputStyles } from "./InputStyles";
12
12
  import axios from "axios";
13
+ import { pushGtmEvent } from "../../gtm";
13
14
 
14
15
  @customElement("text-us-window")
15
16
  export class TextUsWindow extends LitElement {
@@ -266,7 +267,11 @@ const createTextWithUs = async (
266
267
  // @ts-ignore
267
268
  query_params: Object.fromEntries(queryParams.entries()),
268
269
  };
269
-
270
+ pushGtmEvent("textUsSubmitted", {
271
+ phone: formattedPhoneNumber,
272
+ originatingSource:
273
+ leadSources.find((i) => i !== "property-website") || null,
274
+ });
270
275
  await axios.post(
271
276
  "https://app.meetelise.com/platformApi/state/create/textMe",
272
277
  requestBody,
package/src/gtm.ts ADDED
@@ -0,0 +1,17 @@
1
+ declare global {
2
+ interface Window {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ dataLayer: any[];
5
+ }
6
+ }
7
+
8
+ export const pushGtmEvent = (
9
+ eventName: string,
10
+ event: Record<string, unknown> = {}
11
+ ): void => {
12
+ window.dataLayer = window.dataLayer || [];
13
+ window.dataLayer.push({
14
+ event: eventName,
15
+ ...event,
16
+ });
17
+ };