@ai4b-team/fsaos-gateway-sdk 3.26.1 → 3.26.2

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.js CHANGED
@@ -655,6 +655,15 @@ function trackAction(actionId, properties = {}, options = {}) {
655
655
  const adapterProperties = adapter.id_property ? { [adapter.id_property]: actionId } : {};
656
656
  return trackEvent(adapter.observation, { ...properties, ...adapterProperties }, { ...options, source: source.id });
657
657
  }
658
+ function formAttribution() {
659
+ try {
660
+ const source = publicSource();
661
+ adapterFor("form_receipt", source);
662
+ return { visitor_id: visitorId(source), session_id: sessionId(source), source: source.id };
663
+ } catch {
664
+ return void 0;
665
+ }
666
+ }
658
667
  function trackFormReceipt(properties, options = {}) {
659
668
  const source = publicSource(options.source);
660
669
  const adapter = adapterFor("form_receipt", source);
@@ -983,6 +992,8 @@ async function submitForm(capabilityId, fields, options = {}) {
983
992
  throw new TypeError("pageUrl is required outside a browser");
984
993
  }
985
994
  const endpoint = `${GATEWAY_URL.replace(/\/+$/, "")}/d/${encodeURIComponent(hostname)}/actions/${encodeURIComponent(capabilityId)}`;
995
+ const identity = formAttribution();
996
+ const attribution = identity ? { visitor_id: identity.visitor_id, session_id: identity.session_id } : void 0;
986
997
  let response;
987
998
  try {
988
999
  response = await fetch(endpoint, {
@@ -991,7 +1002,7 @@ async function submitForm(capabilityId, fields, options = {}) {
991
1002
  "Content-Type": "application/json",
992
1003
  "Accept": "application/json"
993
1004
  },
994
- body: JSON.stringify({ fill_id: fillId, page_url: pageUrl, fields }),
1005
+ body: JSON.stringify({ fill_id: fillId, page_url: pageUrl, fields, ...attribution ? { attribution } : {} }),
995
1006
  signal: options.signal,
996
1007
  credentials: "omit"
997
1008
  });
@@ -1022,7 +1033,7 @@ async function submitForm(capabilityId, fields, options = {}) {
1022
1033
  fill_id: fillId,
1023
1034
  action_id: capabilityId,
1024
1035
  release_id: payload.release_id
1025
- }, { eventId: fillId, pageUrl, signal: options.signal, keepalive: true });
1036
+ }, { eventId: fillId, pageUrl, signal: options.signal, keepalive: true, ...identity ? { source: identity.source, visitorId: identity.visitor_id, sessionId: identity.session_id } : {} });
1026
1037
  } catch {
1027
1038
  }
1028
1039
  return payload;