@aranova/tracking-react 1.5.0 → 1.7.0

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/dist/index.mjs CHANGED
@@ -1733,7 +1733,7 @@ function outcomeOf(body) {
1733
1733
  if (body.status === "pending") return { status: "pending", id: body.id, mode };
1734
1734
  return { status: "failed", id: body.id, fallbackUrl: body.fallback_url, mode };
1735
1735
  }
1736
- function formSubmitPayload(input, formId, labels) {
1736
+ function formSubmitPayload(input, formSubmit, labels) {
1737
1737
  const vehicle = input.vehicle ? `${input.vehicle.year} ${input.vehicle.make} ${input.vehicle.model}` : "";
1738
1738
  const field = (name, type, label, value) => ({
1739
1739
  name,
@@ -1741,32 +1741,31 @@ function formSubmitPayload(input, formId, labels) {
1741
1741
  label,
1742
1742
  value
1743
1743
  });
1744
+ const fields = [
1745
+ field("first_name", "text", "First name", input.firstName),
1746
+ field("last_name", "text", "Last name", input.lastName),
1747
+ // E.164 on the wire: it keys the customer and enhanced-conversion matching.
1748
+ field("phone", "tel", "Phone", toE164(input.phone) ?? input.phone),
1749
+ field("email", "email", "Email", input.email ?? ""),
1750
+ field(
1751
+ "service",
1752
+ "select",
1753
+ "Service",
1754
+ input.services.map((key) => labels.get(key) ?? key).join(", ")
1755
+ ),
1756
+ field("vehicle", "text", "Vehicle", vehicle),
1757
+ field(
1758
+ "start",
1759
+ "text",
1760
+ "Requested time",
1761
+ `${input.startDate} ${String(input.startHour).padStart(2, "0")}:00`
1762
+ ),
1763
+ field("note", "textarea", "Notes", input.notes ?? "")
1764
+ ];
1765
+ const reported = new Set(fields.map((item) => item.name));
1766
+ const extra = (formSubmit.extraFields ?? []).filter((item) => !reported.has(item.name));
1744
1767
  return {
1745
- form: {
1746
- id: formId,
1747
- action: "/tracking/bookings",
1748
- fields: [
1749
- field("first_name", "text", "First name", input.firstName),
1750
- field("last_name", "text", "Last name", input.lastName),
1751
- // E.164 on the wire: it keys the customer and enhanced-conversion matching.
1752
- field("phone", "tel", "Phone", toE164(input.phone) ?? input.phone),
1753
- field("email", "email", "Email", input.email ?? ""),
1754
- field(
1755
- "service",
1756
- "select",
1757
- "Service",
1758
- input.services.map((key) => labels.get(key) ?? key).join(", ")
1759
- ),
1760
- field("vehicle", "text", "Vehicle", vehicle),
1761
- field(
1762
- "start",
1763
- "text",
1764
- "Requested time",
1765
- `${input.startDate} ${String(input.startHour).padStart(2, "0")}:00`
1766
- ),
1767
- field("note", "textarea", "Notes", input.notes ?? "")
1768
- ]
1769
- },
1768
+ form: { id: formSubmit.formId, action: "/tracking/bookings", fields: [...fields, ...extra] },
1770
1769
  page: { path: typeof window === "undefined" ? "/" : window.location.pathname }
1771
1770
  };
1772
1771
  }
@@ -1854,7 +1853,7 @@ function createSalesBookingsClient(config, firing) {
1854
1853
  return failedBeforeSend(input);
1855
1854
  }
1856
1855
  return {
1857
- async submit(input, { attemptKey, formSubmit, simulate }) {
1856
+ async submit(input, { attemptKey, formSubmit, simulate, onPending }) {
1858
1857
  registerCapability("booking_integration");
1859
1858
  const runtime = runtimeOf(firing);
1860
1859
  warnOnSetupMismatch(runtime);
@@ -1865,10 +1864,7 @@ function createSalesBookingsClient(config, firing) {
1865
1864
  if (formSubmit && !submittedForms.has(attemptKey)) {
1866
1865
  submittedForms.add(attemptKey);
1867
1866
  const labels = new Map(booking.options.map((option) => [option.key, option.label]));
1868
- formSubmit.tracking.trackEvent(
1869
- "form_submit",
1870
- formSubmitPayload(input, formSubmit.formId, labels)
1871
- );
1867
+ formSubmit.tracking.trackEvent("form_submit", formSubmitPayload(input, formSubmit, labels));
1872
1868
  }
1873
1869
  const body = {
1874
1870
  idempotency_key: attemptKey,
@@ -1902,10 +1898,9 @@ function createSalesBookingsClient(config, firing) {
1902
1898
  return rejected(error, input, attemptKey, runtime);
1903
1899
  }
1904
1900
  const outcome = outcomeOf(response);
1905
- return withHandoff(
1906
- outcome.status === "pending" ? await poll(outcome.id, outcome.mode) : outcome,
1907
- input
1908
- );
1901
+ if (outcome.status !== "pending") return withHandoff(outcome, input);
1902
+ onPending?.(outcome);
1903
+ return withHandoff(await poll(outcome.id, outcome.mode), input);
1909
1904
  },
1910
1905
  async status(id) {
1911
1906
  return outcomeOf(
@@ -2214,7 +2209,14 @@ var zSmsWithheldReason = z2.enum([
2214
2209
  "a2p_registration_required",
2215
2210
  "alert_recipient_cannot_receive_sms",
2216
2211
  "line_type_unresolved",
2217
- "sale_source_sends_own_messages"
2212
+ "sale_source_sends_own_messages",
2213
+ "form_lead_disabled",
2214
+ "source_not_enabled",
2215
+ "confirmed_by_integration",
2216
+ "test_or_bot_session",
2217
+ "invalid_phone",
2218
+ "quiet_hours",
2219
+ "recently_texted"
2218
2220
  ]);
2219
2221
  var zSaleSmsStatusSchema = z2.object({
2220
2222
  can_send_now: z2._default(z2.boolean(), false),