bhl-forms 0.0.65 → 0.0.68

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.
@@ -11038,6 +11038,22 @@ function rollbar(type, msg) {
11038
11038
  }
11039
11039
  }
11040
11040
  }
11041
+ function analyticsEvent(event, body) {
11042
+ try {
11043
+ dbg(body);
11044
+ window._analytics.track(event, body, {
11045
+ plugins: {
11046
+ "google-tag-manager": false
11047
+ }
11048
+ });
11049
+ return true;
11050
+ } catch (err) {
11051
+ const msg = "failed to fire event: " + err.toString();
11052
+ console.warn(msg);
11053
+ rollbar("warning", msg);
11054
+ }
11055
+ return false;
11056
+ }
11041
11057
  function cookie(name, value, ttl, path, samesite, secure, domain) {
11042
11058
  name = name.replace(/\s/g, "_");
11043
11059
  var isSet2 = arguments.length > 1;
@@ -11079,7 +11095,8 @@ function schemaFromUrl(url3) {
11079
11095
  });
11080
11096
  }
11081
11097
  const getBaseDomain = () => {
11082
- var parts = window.location.host.split(".");
11098
+ const host = window.location.host.replace("webflow.io", "com");
11099
+ const parts = host.split(".");
11083
11100
  return parts.slice(-2).join(".");
11084
11101
  };
11085
11102
  const flattenObj = (obj) => {
@@ -11176,27 +11193,38 @@ const fireStepEvent = (formNode) => (stepResult, stepHistory2, stepQueue2) => {
11176
11193
  console.warn(msg);
11177
11194
  rollbar("warning", msg);
11178
11195
  }
11179
- if (typeof window._analytics !== "undefined") {
11180
- try {
11181
- const form_id = formNode.attrs.formId || window.location.hostname + "-" + formNode.id;
11182
- var body = {
11183
- "form_source": "formkit",
11184
- "form_id": form_id,
11185
- "step_count": stepHistory2.value.length,
11186
- "step_name": stepHistory2.value[stepHistory2.value.length - 1],
11187
- "step_values": step_values
11188
- };
11189
- dbg(body);
11190
- window._analytics.track("form-step", body, {
11191
- plugins: {
11192
- "google-tag-manager": false
11193
- }
11194
- });
11195
- } catch (err) {
11196
- const msg = "failed to fire step event: " + err.toString();
11197
- console.warn(msg);
11198
- rollbar("warning", msg);
11199
- }
11196
+ try {
11197
+ const form_id = formNode.attrs.formId || window.location.hostname + "-" + formNode.id;
11198
+ var body = {
11199
+ "form_source": "formkit",
11200
+ "form_id": form_id,
11201
+ "step_count": stepHistory2.value.length,
11202
+ "step_name": stepHistory2.value[stepHistory2.value.length - 1],
11203
+ "step_values": step_values
11204
+ };
11205
+ analyticsEvent("form-step", body);
11206
+ } catch (err) {
11207
+ const msg = "failed to fire step event: " + err.toString();
11208
+ console.warn(msg);
11209
+ rollbar("warning", msg);
11210
+ }
11211
+ };
11212
+ const experimentCallback = (form2, variant, fromCache) => {
11213
+ dbg("default experimentCallback", form2, variant, fromCache);
11214
+ try {
11215
+ var body = {
11216
+ "experiment": form2.experiment.name,
11217
+ "branch": variant.name,
11218
+ "schema": variant.schema,
11219
+ "no_cache": form2.noCache,
11220
+ "from_cache": fromCache
11221
+ };
11222
+ const res = analyticsEvent("form-experiment", body);
11223
+ dbg("experimentCallback event", res);
11224
+ } catch (err) {
11225
+ const msg = "failed to fire experiment callback: " + err.toString();
11226
+ console.warn(msg);
11227
+ rollbar("warning", msg);
11200
11228
  }
11201
11229
  };
11202
11230
  const handleRedirect = (formData, node) => {
@@ -15582,6 +15610,7 @@ const _sfc_main = {
15582
15610
  };
15583
15611
  const apps = {};
15584
15612
  const defaultSubmitUrl = "https://webhooks." + getBaseDomain() + "/api/v1/form_leads_ext";
15613
+ dbg("defaultSubmitUrl:", defaultSubmitUrl);
15585
15614
  const init = () => {
15586
15615
  const classes = generateClasses(theme);
15587
15616
  const forms = window.bhlFormDefs || [];
@@ -15598,7 +15627,12 @@ const init = () => {
15598
15627
  const res = chooseVariant(form2.experiment);
15599
15628
  schema = res.variant.schema;
15600
15629
  if (form2.experimentCallback) {
15601
- experimentCallback(form2, res.variant, res.fromCache);
15630
+ dbg("form.experimentCallback", form2.experimentCallback);
15631
+ if (form2.experimentCallback === true) {
15632
+ experimentCallback(form2, res.variant, res.fromCache);
15633
+ } else {
15634
+ form2.experimentCallback(form2, res.variant, res.fromCache);
15635
+ }
15602
15636
  }
15603
15637
  }
15604
15638
  let schemaObj = schema;