@aranova/tracking-next 0.17.0 → 0.17.1

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
@@ -702,8 +702,8 @@ function thresholdMet(goal, eventType, metadata) {
702
702
  return typeof metadata.page_name === "string" && metadata.page_name === t.page_name;
703
703
  case "page_view":
704
704
  case "form_start":
705
+ case "phone_click":
705
706
  return true;
706
- // no threshold — fire whenever the detector emits
707
707
  default:
708
708
  return false;
709
709
  }
@@ -1324,7 +1324,11 @@ var phoneClickMetadataSchema = z8.object({
1324
1324
  }).strict(),
1325
1325
  section: z8.string().nullable().optional()
1326
1326
  }).strict();
1327
- var phoneClickConfigSchema = z8.object({}).strict();
1327
+ var phoneClickConfigSchema = z8.object({
1328
+ autoCapture: z8.object({
1329
+ selector: z8.string().optional()
1330
+ }).strict().optional()
1331
+ }).strict();
1328
1332
 
1329
1333
  // ../tracking-core/src/events/scroll-depth.ts
1330
1334
  import { z as z9 } from "zod";
@@ -1825,6 +1829,99 @@ function attachCtaClickCapture(client, config) {
1825
1829
  };
1826
1830
  }
1827
1831
 
1832
+ // ../tracking-core/src/phone.ts
1833
+ import { AsYouType, parsePhoneNumberFromString } from "libphonenumber-js";
1834
+ var DEFAULT_PHONE_COUNTRY = "CA";
1835
+ function parsePhone(raw, country) {
1836
+ const region = country ?? DEFAULT_PHONE_COUNTRY;
1837
+ const parsed = parsePhoneNumberFromString(raw ?? "", region);
1838
+ if (!parsed) {
1839
+ return { e164: null, national: "", international: "", country: region, isValid: false };
1840
+ }
1841
+ const isValid = parsed.isValid();
1842
+ return {
1843
+ // E.164 is only surfaced for a *valid* number — a possible-but-invalid input
1844
+ // (e.g. too few digits) still parses but must not be transmitted.
1845
+ e164: isValid ? parsed.number : null,
1846
+ national: parsed.formatNational(),
1847
+ international: parsed.formatInternational(),
1848
+ country: parsed.country ?? region,
1849
+ isValid
1850
+ };
1851
+ }
1852
+ function toE164(raw, country) {
1853
+ return parsePhone(raw, country).e164;
1854
+ }
1855
+ function formatPhone(value, format = "national", country) {
1856
+ const parsed = parsePhone(value, country);
1857
+ if (typeof format === "function") return format(parsed);
1858
+ switch (format) {
1859
+ case "international":
1860
+ return parsed.international || value;
1861
+ case "e164":
1862
+ return parsed.e164 ?? value;
1863
+ case "national":
1864
+ default:
1865
+ return parsed.national || value;
1866
+ }
1867
+ }
1868
+ function formatPhoneAsTyped(raw, country) {
1869
+ return new AsYouType(country ?? DEFAULT_PHONE_COUNTRY).input(raw ?? "");
1870
+ }
1871
+
1872
+ // ../tracking-core/src/triggers/phone-click-capture.ts
1873
+ var DEFAULT_TEL_SELECTOR = 'a[href^="tel:"]';
1874
+ function safeDecodeURIComponent(value) {
1875
+ try {
1876
+ return decodeURIComponent(value);
1877
+ } catch {
1878
+ return value;
1879
+ }
1880
+ }
1881
+ function resolvePhoneNumber(el) {
1882
+ const href = el instanceof HTMLAnchorElement ? el.href : el.getAttribute("href") ?? "";
1883
+ const raw = safeDecodeURIComponent(href.replace(/^tel:/i, "").split(";")[0]).trim();
1884
+ return toE164(raw) ?? raw;
1885
+ }
1886
+ function attachPhoneClickCapture(client, config) {
1887
+ if (typeof window === "undefined" || typeof document === "undefined") {
1888
+ return () => {
1889
+ };
1890
+ }
1891
+ const autoCapture = config.autoCapture;
1892
+ if (!autoCapture) {
1893
+ return () => {
1894
+ };
1895
+ }
1896
+ const selector = autoCapture.selector ?? DEFAULT_TEL_SELECTOR;
1897
+ function onClick(event) {
1898
+ const target = event.target;
1899
+ if (!(target instanceof Element)) return;
1900
+ let matched = null;
1901
+ try {
1902
+ matched = target.closest(selector);
1903
+ } catch {
1904
+ return;
1905
+ }
1906
+ if (matched === null) return;
1907
+ const metadata = {
1908
+ phone_number: resolvePhoneNumber(matched),
1909
+ page: { path: window.location.pathname },
1910
+ section: matched.getAttribute("data-aranova-section")
1911
+ };
1912
+ client.trackEvent({
1913
+ eventType: "phone_click",
1914
+ metadata,
1915
+ pageUrl: window.location.href,
1916
+ occurredAt: null
1917
+ });
1918
+ }
1919
+ document.addEventListener("click", onClick, true);
1920
+ return () => {
1921
+ document.removeEventListener("click", onClick, true);
1922
+ };
1923
+ }
1924
+
1828
1925
  // ../tracking-core/src/resources/sales/errors.ts
1829
1926
  var AranovaApiError = class extends Error {
1830
1927
  constructor(message, options) {
@@ -2152,46 +2249,6 @@ async function fetchServices(config) {
2152
2249
  return salesRequest(config, "GET", "/services");
2153
2250
  }
2154
2251
 
2155
- // ../tracking-core/src/phone.ts
2156
- import { AsYouType, parsePhoneNumberFromString } from "libphonenumber-js";
2157
- var DEFAULT_PHONE_COUNTRY = "CA";
2158
- function parsePhone(raw, country) {
2159
- const region = country ?? DEFAULT_PHONE_COUNTRY;
2160
- const parsed = parsePhoneNumberFromString(raw ?? "", region);
2161
- if (!parsed) {
2162
- return { e164: null, national: "", international: "", country: region, isValid: false };
2163
- }
2164
- const isValid = parsed.isValid();
2165
- return {
2166
- // E.164 is only surfaced for a *valid* number — a possible-but-invalid input
2167
- // (e.g. too few digits) still parses but must not be transmitted.
2168
- e164: isValid ? parsed.number : null,
2169
- national: parsed.formatNational(),
2170
- international: parsed.formatInternational(),
2171
- country: parsed.country ?? region,
2172
- isValid
2173
- };
2174
- }
2175
- function toE164(raw, country) {
2176
- return parsePhone(raw, country).e164;
2177
- }
2178
- function formatPhone(value, format = "national", country) {
2179
- const parsed = parsePhone(value, country);
2180
- if (typeof format === "function") return format(parsed);
2181
- switch (format) {
2182
- case "international":
2183
- return parsed.international || value;
2184
- case "e164":
2185
- return parsed.e164 ?? value;
2186
- case "national":
2187
- default:
2188
- return parsed.national || value;
2189
- }
2190
- }
2191
- function formatPhoneAsTyped(raw, country) {
2192
- return new AsYouType(country ?? DEFAULT_PHONE_COUNTRY).input(raw ?? "");
2193
- }
2194
-
2195
2252
  // ../tracking-core/src/phone-field.ts
2196
2253
  function phoneField(name, raw, country) {
2197
2254
  return { name, type: "phone", value: toE164(raw, country) };
@@ -2528,7 +2585,7 @@ function GoogleAdsTracking(props) {
2528
2585
  import { usePathname, useSearchParams } from "next/navigation";
2529
2586
 
2530
2587
  // package.json
2531
- var version = "0.17.0";
2588
+ var version = "0.17.1";
2532
2589
 
2533
2590
  // src/factory.tsx
2534
2591
  import {
@@ -2844,6 +2901,10 @@ function createTracking(options) {
2844
2901
  if (ctaClick) {
2845
2902
  detachers.push(attachCtaClickCapture(detectorClient, ctaClick));
2846
2903
  }
2904
+ const phoneClick = triggers.manual?.phone_click;
2905
+ if (phoneClick) {
2906
+ detachers.push(attachPhoneClickCapture(detectorClient, phoneClick));
2907
+ }
2847
2908
  return () => {
2848
2909
  for (let i = detachers.length - 1; i >= 0; i--) {
2849
2910
  detachers[i]();