PageSourceSearch

https://www.swarm.work/philippine-ai-report/assets/js/report-analytics.js

js swarm.work collected 2026-09-24 18:26:24 UTC 2,836 bytes, 62 lines download raw bytes

1/* Shared report-form analytics. Never capture field values or error messages. */
2(function () {
3  var assets = {
4    '/philippine-ai-report': ['executive-brief', 'ph-ai-report-executive-2025'],
5    '/philippine-ai-report-full': ['full-report', 'ph-ai-report-full-2025'],
6    '/philippine-ai-report-retail-edition': ['retail-edition', 'ph-ai-report-retail-2025']
7  };
8  var path = location.pathname.replace(/\.html$/, '').replace(/\/$/, '');
9  var asset = assets[path];
10  if (!asset) return;
11  var fields = ['Email', 'name', 'Last-Name', 'Company-Website', 'Company', 'Role', 'Segmentation', 'Possible-Use-Cases', 'Attribution'];
12  var started = false;
13  var completed = false;
14  var errors = new Set();
15  function capture(event, properties) {
16    if (['localhost', '127.0.0.1', '[::1]', '0.0.0.0'].indexOf(location.hostname) !== -1) return;
17    try {
18      if (window.posthog) window.posthog.capture(event, Object.assign({
19        report_slug: asset[0], asset_key: asset[1], report_year: 2025,
20        page_path: path, site_host: location.hostname
21      }, properties || {}), { transport: 'sendBeacon', send_instantly: true });
22    } catch (_) { /* Analytics cannot block report delivery. */ }
23  }
24  function start() {
25    if (started) return;
26    started = true;
27    capture('report_form_started');
28  }
29  document.addEventListener('DOMContentLoaded', function () {
30    document.querySelectorAll('form[data-redirect], form[redirect]').forEach(function (form) {
31      form.addEventListener('input', function (event) {
32        if (fields.indexOf(event.target.name) !== -1) start();
33      });
34      form.addEventListener('change', function (event) {
35        if (fields.indexOf(event.target.name) !== -1) start();
36      });
37      form.addEventListener('invalid', function (event) {
38        var field = event.target;
39        if (fields.indexOf(field.name) === -1) return;
40        start();
41        var category = field.validity.valueMissing ? 'required' : field.validity.typeMismatch ? 'type' : field.validity.patternMismatch ? 'format' : 'invalid';
42        var key = field.name + ':' + category;
43        if (errors.has(key)) return;
44        errors.add(key);
45        capture('report_form_validation_failed', { field_name: field.name, error_category: category });
46      }, true);
47      // Capture phase runs before the existing submit handler stops propagation.
48      form.addEventListener('submit', start, true);
49    });
50  });
51  window.reportFormAnalytics = {
52    completed: function () {
53      if (completed) return;
54      completed = true;
55      start();
56      capture('report_form_completed', { confirmation: 'api_success' });
57    },
58    failed: function (category) {
59      capture('report_form_submission_failed', { error_category: ['server', 'validation', 'network'].indexOf(category) !== -1 ? category : 'network' });
60    }
61  };
62})();

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.