PageSourceSearch

https://chateaubeeselection.com/wp-content/themes/bricks-child/ass…/cbs-omnisend-attribution.js?ver=1789544744

js chateaubeeselection.com collected 2026-10-04 06:44:30 UTC 2,896 bytes, 105 lines download raw bytes

1/**
2 * File: cbs-omnisend-attribution.js
3 * Description: Persists UTM attribution in a first-party cookie so it survives the
4 *              visitor browsing between the marketing landing page and the page where
5 *              they eventually submit a venue enquiry.
6 *
7 *              Latest-touch model: any new UTM-tagged visit replaces the stored values
8 *              and restarts the 30-day window.
9 *
10 *              The cookie is read server-side at submit time by cbs-omnisend-events.php,
11 *              so no hidden form fields are involved.
12 *
13 * Author: Indulge Digital
14 * Version: 1.0.0
15 */
16
17(function () {
18  'use strict';
19
20  var COOKIE_NAME  = 'cbs_attr';
21  var TTL_SECONDS  = 2592000; // 30 days
22  var MAX_LENGTH   = 150;     // per-parameter cap, guards against oversized query strings
23  var UTM_KEYS     = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content'];
24
25  /**
26   * Read the four UTM parameters from the current URL.
27   *
28   * @return {Object|null} Map of the parameters that are present, or null if none are.
29   */
30  function readUtmParams() {
31    if (typeof URLSearchParams === 'undefined') {
32      return null;
33    }
34
35    var params = new URLSearchParams(window.location.search);
36    var found  = {};
37    var hasAny = false;
38
39    UTM_KEYS.forEach(function (key) {
40      var value = params.get(key);
41
42      if (value === null) {
43        return;
44      }
45
46      value = value.trim().slice(0, MAX_LENGTH);
47
48      if (value !== '') {
49        found[key] = value;
50        hasAny = true;
51      }
52    });
53
54    return hasAny ? found : null;
55  }
56
57  /**
58   * Write the attribution cookie, restarting the 30-day window.
59   *
60   * @param {Object} utm Map of UTM parameters to store.
61   */
62  function storeAttribution(utm) {
63    var payload = {
64      utm_source:   utm.utm_source   || '',
65      utm_medium:   utm.utm_medium   || '',
66      utm_campaign: utm.utm_campaign || '',
67      utm_content:  utm.utm_content  || '',
68      ts:           Math.floor(Date.now() / 1000)
69    };
70
71    var cookie = COOKIE_NAME + '=' + encodeURIComponent(JSON.stringify(payload)) +
72                 '; path=/' +
73                 '; max-age=' + TTL_SECONDS +
74                 '; SameSite=Lax';
75
76    if (window.location.protocol === 'https:') {
77      cookie += '; Secure';
78    }
79
80    document.cookie = cookie;
81  }
82
83  /**
84   * Capture attribution for this page view.
85   *
86   * No UTM parameters means this is not a qualifying marketing visit, so any
87   * previously stored attribution is deliberately left untouched.
88   */
89  function capture() {
90    try {
91      var utm = readUtmParams();
92
93      if (utm) {
94        storeAttribution(utm);
95      }
96    } catch (error) {
97      // Attribution is best-effort and must never break the page.
98      if (window.console && window.console.debug) {
99        window.console.debug('[cbs-attribution] capture failed', error);
100      }
101    }
102  }
103
104  capture();
105})();

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.