PageSourceSearch

https://www.bamboohr.com/scripts/cheq.js

js bamboohr.com collected 2026-09-24 06:57:53 UTC 4,714 bytes, 145 lines download raw bytes

1// eslint-disable-next-line no-unused-vars
2function onCheqResponse(encryptedMessage, requestID){
3  if (!window.cheqConsentAllowed) return;
4
5  window.top.document.cheqRequestId = requestID;
6
7  window.dataLayer = window.dataLayer || [];
8
9  window.dataLayer.push({
10    event: 'cheqResponseReceived',
11    cheq_request_id: requestID
12  });
13
14  try {
15    sessionStorage.setItem('cheq_request_id', requestID);
16  } catch (e) {
17    // Storage may be unavailable (private browsing, quota)
18  }
19
20  cacheCheqDataWhenReady(); // eslint-disable-line no-use-before-define
21}
22
23/**
24 * Polls the dataLayer for the CHEQ external script's threat-classification
25 * push, then persists all fields to sessionStorage so subsequent page views
26 * can restore them without re-fetching.
27 */
28function cacheCheqDataWhenReady() {
29  let attempts = 0;
30  const interval = setInterval(() => {
31    attempts += 1;
32    const data = getCheqDataFromDataLayer(); // eslint-disable-line no-use-before-define
33    if (data) {
34      clearInterval(interval);
35      try {
36        sessionStorage.setItem('cheq_data', JSON.stringify(data));
37        sessionStorage.setItem('cheq_session_done', '1');
38      } catch (e) { /* storage unavailable */ }
39      return;
40    }
41    if (attempts >= 50) {
42      clearInterval(interval);
43      try { sessionStorage.setItem('cheq_session_done', '1'); } catch (e) { /* */ }
44    }
45  }, 200);
46}
47
48/**
49 * Restores cached CHEQ data from a previous page view in the same session.
50 * Re-populates window.top.document.cheqRequestId for forms, and replays
51 * the classification data into the dataLayer so getCheqDataFromDataLayer()
52 * returns the same result as the original page view.
53 */
54function restoreCheqData() {
55  try {
56    const id = sessionStorage.getItem('cheq_request_id');
57    if (id) {
58      window.top.document.cheqRequestId = id;
59    }
60
61    const raw = sessionStorage.getItem('cheq_data');
62    if (raw) {
63      const cached = JSON.parse(raw);
64      window.dataLayer = window.dataLayer || [];
65      const entry = { event: 'cheq_response' };
66      if (cached.threatType !== undefined)    entry.cheq_threat_type = cached.threatType;
67      if (cached.threatGroup !== undefined)   entry.cheq_threat_group = cached.threatGroup;
68      if (cached.aiTrafficType !== undefined) entry.cheq_ai_traffic_type = cached.aiTrafficType;
69      if (cached.entityVendor !== undefined)  entry.cheq_entity_vendor = cached.entityVendor;
70      if (cached.entityClient !== undefined)  entry.cheq_entity_client = cached.entityClient;
71      if (cached.cheqAction !== undefined)    entry.cheq_action = cached.cheqAction;
72      window.dataLayer.push(entry);
73    }
74  } catch (e) {
75    // Storage or JSON parse error
76  }
77}
78
79/**
80 * Retrieves CHEQ bot detection data from dataLayer.
81 * @returns {object|null} CHEQ data or null if not available
82 */
83function getCheqDataFromDataLayer() {
84  if (!window.dataLayer) return null;
85
86  const cheqData = {};
87  let foundData = false;
88
89  for (let i = window.dataLayer.length - 1; i >= 0; i -= 1) {
90    const item = window.dataLayer[i];
91
92    if (item.event === 'cheq_response' || item.cheq_threat_type !== undefined) {
93      if (item.cheq_threat_type !== undefined) {
94        cheqData.threatType = item.cheq_threat_type;
95        foundData = true;
96      }
97      if (item.cheq_threat_group !== undefined) {
98        cheqData.threatGroup = item.cheq_threat_group;
99        foundData = true;
100      }
101      if (item.cheq_ai_traffic_type !== undefined) {
102        cheqData.aiTrafficType = item.cheq_ai_traffic_type;
103        foundData = true;
104      }
105      if (item.cheq_entity_vendor !== undefined) {
106        cheqData.entityVendor = item.cheq_entity_vendor;
107        foundData = true;
108      }
109      if (item.cheq_entity_client !== undefined) {
110        cheqData.entityClient = item.cheq_entity_client;
111        foundData = true;
112      }
113      if (item.cheq_action !== undefined) {
114        cheqData.cheqAction = item.cheq_action;
115        foundData = true;
116      }
117
118      if (foundData) break;
119    }
120
121    if (item.cheq_request_id && !cheqData.cheqAction) {
122      cheqData.cheqRequestId = item.cheq_request_id;
123    }
124  }
125
126  // Add concatenated tracking string for easy single-eVar tracking
127  // Format: threatType|threatGroup|aiTrafficType|entityVendor|entityClient|cheqAction
128  if (foundData) {
129    cheqData.cheqTracking = [
130      cheqData.threatType || '',
131      cheqData.threatGroup || '',
132      cheqData.aiTrafficType || '',
133      cheqData.entityVendor || '',
134      cheqData.entityClient || '',
135      cheqData.cheqAction || ''
136    ].join('|');
137  }
138
139  return foundData ? cheqData : null;
140}
141
142if (typeof window !== 'undefined') {
143  window.getCheqDataFromDataLayer = getCheqDataFromDataLayer;
144  window.restoreCheqData = restoreCheqData;
145}

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.