PageSourceSearch

https://www.incharge.org/wp-content/themes/bb-theme-child/js/form-tracking-storage.js

js incharge.org collected 2026-09-24 09:22:36 UTC 4,552 bytes, 168 lines download raw bytes

1(function () {
2  "use strict";
3
4  function getParameterByName(name, defaultValue) {
5    var fallback = typeof defaultValue === "undefined" ? "" : defaultValue;
6    var urlParams = new URLSearchParams(window.location.search);
7
8    if (!urlParams.has(name)) {
9      return fallback;
10    }
11
12    return decodeURIComponent(urlParams.get(name));
13  }
14
15  function setFieldValue(field, value) {
16    if (!field) {
17      return;
18    }
19
20    field.value = value;
21    field.setAttribute("value", value);
22
23    if (field.dataset) {
24      field.dataset.frmval = value;
25    }
26
27    field.dispatchEvent(new Event("input", { bubbles: true }));
28    field.dispatchEvent(new Event("change", { bubbles: true }));
29  }
30
31  function handleStorage(paramName, fieldId) {
32    var paramValue = getParameterByName(paramName);
33
34    // If the value exists in the URL, always save/update localStorage
35    if (paramValue) {
36      localStorage.setItem(paramName, paramValue);
37      console.log("Stored " + paramName + ":", paramValue);
38    }
39
40    var storedValue = localStorage.getItem(paramName);
41
42    if (!storedValue) {
43      console.log("No stored value for " + paramName);
44      return;
45    }
46
47    try {
48      var parsed = JSON.parse(storedValue);
49      if (
50        parsed &&
51        typeof parsed === "object" &&
52        Object.prototype.hasOwnProperty.call(parsed, "value")
53      ) {
54        storedValue = parsed.value;
55        console.log("Parsed JSON from " + paramName + ":", storedValue);
56      }
57    } catch (e) {
58      // leave storedValue as-is
59    }
60
61    var field =
62      document.getElementById(fieldId) ||
63      document.querySelector('input[id^="' + fieldId + '"]');
64
65    if (field) {
66      setFieldValue(field, storedValue);
67      console.log("Injected into " + fieldId + ":", storedValue);
68    } else {
69      console.log("Field not found for " + fieldId);
70    }
71  }
72
73  function setDefaultLeadOrigin() {
74    if (localStorage.getItem("leadOrigin")) {
75      return;
76    }
77
78    var field = document.getElementById("field_leadorigin");
79    if (field) {
80      setFieldValue(field, "inchargeorg");
81    }
82
83    console.log("leadOrigin not found, setting default: inchargeorg");
84  }
85
86  function setLandingPage() {
87    var landingPage =
88      window.location.protocol +
89      "//" +
90      window.location.host +
91      window.location.pathname +
92      window.location.search;
93
94    if (!localStorage.getItem("LandingPage")) {
95      localStorage.setItem("LandingPage", landingPage);
96      console.log("LandingPage set:", landingPage);
97    }
98
99    var landingField =
100      document.getElementById("field_landingpage") ||
101      document.querySelector('input[id^="field_landingpage"]');
102
103    if (landingField) {
104      setFieldValue(landingField, localStorage.getItem("LandingPage"));
105      console.log("Injected LandingPage:", localStorage.getItem("LandingPage"));
106    } else {
107      console.log("LandingPage field not found");
108    }
109  }
110
111  function getClientId() {
112    if (typeof ga !== "function") {
113      return;
114    }
115
116    var trackers = ga.getAll();
117    if (!trackers.length) {
118      return;
119    }
120
121    var gaClientId = trackers[0].get("clientId");
122    document.cookie = "gaClientId=" + gaClientId + "; path=/";
123
124    var clientField = document.getElementById("field_clientid");
125    if (clientField) {
126      setFieldValue(clientField, gaClientId);
127    }
128
129    console.log("GA Client ID:", gaClientId);
130  }
131
132  function initFormTrackingStorage() {
133    handleStorage("vdn", "field_vdn");
134    handleStorage("keyword", "field_8nkgs");
135
136    handleStorage("utm_source", "field_utm_source");
137    handleStorage("utm_medium", "field_utm_medium");
138    handleStorage("utm_campaign", "field_utm_campaign");
139    handleStorage("utm_content", "field_utm_content");
140    handleStorage("utm_term", "field_utm_term");
141
142    handleStorage("gclid", "field_gclid");
143    handleStorage("fbclid", "field_fbclid");
144    handleStorage("msclkid", "field_msclkid");
145    handleStorage("leadOrigin", "field_leadorigin");
146    handleStorage("userfield1", "field_userfield1");
147    handleStorage("_ga", "field_ga");
148
149    setDefaultLeadOrigin();
150    setLandingPage();
151    getClientId();
152  }
153
154  if (document.readyState === "loading") {
155    document.addEventListener("DOMContentLoaded", initFormTrackingStorage);
156  } else {
157    initFormTrackingStorage();
158  }
159
160  window.addEventListener("load", function () {
161    initFormTrackingStorage();
162    getClientId();
163  });
164
165  window.setTimeout(initFormTrackingStorage, 500);
166  window.setTimeout(initFormTrackingStorage, 1200);
167  window.setTimeout(initFormTrackingStorage, 2500);
168})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.