PageSourceSearch

https://sentinelmission.org/wp-content/plugins/amazon-asin-click-queue/assets/js/click-tracker.js?ver=1.2.1

js sentinelmission.org collected 2026-10-02 10:16:58 UTC 5,375 bytes, 204 lines download raw bytes

1(function () {
2  "use strict";
3
4  if (!window.AACQConfig || !window.AACQConfig.restUrl) {
5    return;
6  }
7
8  var domains = Array.isArray(window.AACQConfig.domains) ? window.AACQConfig.domains : [];
9  var componentSelector = '[data-aacq-component="1"]';
10  var componentCache = null;
11  var pageContentTypeCache = null;
12  var trafficContextCache = null;
13
14  function isAmazonHost(hostname) {
15    if (!hostname) {
16      return false;
17    }
18
19    var host = hostname.toLowerCase();
20    return domains.some(function (domain) {
21      return host === String(domain).toLowerCase();
22    });
23  }
24
25  function allowedValue(value, allowed, fallback) {
26    return allowed.indexOf(value) !== -1 ? value : fallback;
27  }
28
29  function normalizeHost(hostname) {
30    return String(hostname || "")
31      .toLowerCase()
32      .replace(/\.$/, "")
33      .replace(/^www\./, "");
34  }
35
36  function getComponents() {
37    if (componentCache === null) {
38      componentCache = Array.prototype.slice.call(document.querySelectorAll(componentSelector));
39    }
40
41    return componentCache;
42  }
43
44  function getPageContentType() {
45    if (pageContentTypeCache !== null) {
46      return pageContentTypeCache;
47    }
48
49    var hasRoundup = false;
50    var hasWidget = false;
51    var hasButton = false;
52
53    getComponents().forEach(function (component) {
54      var placement = component.getAttribute("data-aacq-placement");
55      if (placement === "roundup_box") {
56        hasRoundup = true;
57      } else if (placement === "widget") {
58        hasWidget = true;
59      } else if (placement === "standalone_cta") {
60        hasButton = true;
61      }
62    });
63
64    if (hasRoundup && hasWidget) {
65      pageContentTypeCache = "mixed";
66    } else if (hasRoundup) {
67      pageContentTypeCache = "roundup_only";
68    } else if (hasWidget) {
69      pageContentTypeCache = "widget_only";
70    } else if (hasButton) {
71      pageContentTypeCache = "button_only";
72    } else {
73      pageContentTypeCache = "unknown";
74    }
75
76    return pageContentTypeCache;
77  }
78
79  function getTrafficContext() {
80    if (trafficContextCache !== null) {
81      return trafficContextCache;
82    }
83
84    trafficContextCache = {
85      traffic_source_type: "direct",
86      referrer_host: null
87    };
88
89    if (!document.referrer) {
90      return trafficContextCache;
91    }
92
93    try {
94      var referrerUrl = new URL(document.referrer);
95      var referrerHost = normalizeHost(referrerUrl.hostname);
96      if (!referrerHost) {
97        return trafficContextCache;
98      }
99
100      trafficContextCache.referrer_host = referrerHost;
101      trafficContextCache.traffic_source_type =
102        referrerHost === normalizeHost(window.location.hostname) ? "internal" : "external";
103    } catch (e) {}
104
105    return trafficContextCache;
106  }
107
108  function getClickContext(link) {
109    var component = link.closest ? link.closest(componentSelector) : null;
110    var placementType = "unknown";
111    var renderState = "unknown";
112    var asinPosition = null;
113
114    if (component) {
115      placementType = allowedValue(
116        component.getAttribute("data-aacq-placement"),
117        ["roundup_box", "widget", "standalone_cta"],
118        "unknown"
119      );
120      renderState = allowedValue(
121        component.getAttribute("data-aacq-render-state"),
122        ["full_product", "fallback_button", "intentional_button"],
123        "unknown"
124      );
125
126      var componentIndex = getComponents().indexOf(component);
127      if (componentIndex !== -1) {
128        asinPosition = componentIndex + 1;
129      }
130    }
131
132    return {
133      placement_type: placementType,
134      page_content_type: getPageContentType(),
135      asin_position: asinPosition,
136      render_state: renderState
137    };
138  }
139
140  function sendPayload(payload) {
141    var body = JSON.stringify(payload);
142
143    if (navigator.sendBeacon) {
144      try {
145        var blob = new Blob([body], { type: "application/json" });
146        if (navigator.sendBeacon(window.AACQConfig.restUrl, blob)) {
147          return;
148        }
149      } catch (e) {}
150    }
151
152    fetch(window.AACQConfig.restUrl, {
153      method: "POST",
154      credentials: "same-origin",
155      keepalive: true,
156      headers: {
157        "Content-Type": "application/json",
158        "X-WP-Nonce": window.AACQConfig.nonce || ""
159      },
160      body: body
161    }).catch(function () {});
162  }
163
164  document.addEventListener(
165    "click",
166    function (event) {
167      var link = event.target && event.target.closest ? event.target.closest("a[href]") : null;
168      if (!link || event.defaultPrevented || event.button !== 0) {
169        return;
170      }
171
172      var href = link.getAttribute("href");
173      if (!href) {
174        return;
175      }
176
177      var url;
178      try {
179        url = new URL(href, window.location.href);
180      } catch (e) {
181        return;
182      }
183
184      if (!/^https?:$/i.test(url.protocol) || !isAmazonHost(url.hostname)) {
185        return;
186      }
187
188      var clickContext = getClickContext(link);
189      var trafficContext = getTrafficContext();
190
191      sendPayload({
192        target_url: url.toString(),
193        page_url: window.location.href,
194        traffic_source_type: trafficContext.traffic_source_type,
195        referrer_host: trafficContext.referrer_host,
196        placement_type: clickContext.placement_type,
197        page_content_type: clickContext.page_content_type,
198        asin_position: clickContext.asin_position,
199        render_state: clickContext.render_state
200      });
201    },
202    true
203  );
204})();

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.