PageSourceSearch

https://www.ohca.com/wp-content/plugins/webtoffee-cookie-consent/lite/frontend/js/gcm.js?ver=3.5.3

js ohca.com collected 2026-09-28 13:40:11 UTC 10,812 bytes, 281 lines download raw bytes

1const data = window._wccGCMConfig;
2let setDefaultSetting = true;
3const regionSettings = data._regions || [];
4const waitForTime = data.wait_for_update;
5const wcc_bypass = !!data._wccBypass;
6const wcc_gcm_debug = !!data._debugMode;
7const is_gtm_template = !!data._isGTMTemplate;
8
9window.dataLayer = window.dataLayer || [];
10function gtag() {
11    dataLayer.push(arguments);
12}
13
14function setConsentInitStates(consentData) {
15    if (waitForTime > 0) consentData.wait_for_update = waitForTime;
16    gtag("consent", "default", consentData );
17}
18if (!is_gtm_template) {
19    gtag("set", "developer_id.dZDk4Nz", true);
20}
21
22if('advanced' === data._mode && !is_gtm_template) {
23    gtag("set", "url_passthrough", !!data._urlPassthrough);
24}
25if(!is_gtm_template) {
26    if( regionSettings.length ) {
27        for (let index = 0; index < regionSettings.length; index++) {
28            const regionSetting = regionSettings[index];
29            // Helper function to convert "Allowed" to "granted" and "Denied" to "denied"
30            const convertConsent = (value) => {
31                if ("Allowed" === value || "Granted" === value) {
32                    return "granted";
33                } else if ("Denied" === value) {
34                    return "denied";
35                }
36                return "denied"; // Default value if neither "Allowed" nor "Denied"
37            };
38        
39            // Convert all relevant consent fields to "granted" or "denied"
40            const consentRegionData = {
41                ad_storage: convertConsent(regionSetting.ad_storage),
42                analytics_storage: convertConsent(regionSetting.analytics_storage),
43                functionality_storage: convertConsent(regionSetting.functionality_storage),
44                personalization_storage: convertConsent(regionSetting.personalization_storage),
45                security_storage: convertConsent(regionSetting.security_storage),
46                ad_user_data: convertConsent(regionSetting.ad_user_data),
47                ad_personalization: convertConsent(regionSetting.ad_personalization)
48            };
49        
50            // Check if regionSetting.region is an array
51            let regionsToSetFor = [];
52            if (Array.isArray(regionSetting.region)) {
53                regionsToSetFor = regionSetting.region.map((region) => region.trim());
54            } else if (typeof regionSetting.region === 'string') {
55                regionsToSetFor = regionSetting.region
56                    .split(",")
57                    .map((region) => region.trim())
58                    .filter((region) => region);
59            }
60        
61            if (regionsToSetFor.length > 0 && regionsToSetFor[0].toLowerCase() !== "all") {
62                consentRegionData.region = regionsToSetFor;
63            } else {
64                setDefaultSetting = false;
65                setDefaultConsents();
66            }
67        
68            setConsentInitStates(consentRegionData);
69        }
70    } else {
71        setDefaultConsents();
72    }
73}
74function setDefaultConsents() {
75    if(setDefaultSetting) {
76        setConsentInitStates({
77            ad_storage: "denied",
78            analytics_storage: "denied",
79            functionality_storage: "denied",
80            personalization_storage: "denied",
81            security_storage: "granted",
82            ad_user_data: "denied",
83            ad_personalization: "denied"
84        });
85    }
86}
87document.addEventListener("_wccBannerVisible", function(event) {
88    let is_banner_visible = event.detail.bannerVisibility;
89    let currentLaw = event.detail.currentLaw;
90    // Declare categories variable
91    let categories = {};
92    if (!is_banner_visible || wcc_bypass ) {
93        categories = {
94            "accepted": [
95                "necessary",
96                "functional",
97                "analytics",
98                "performance",
99                "advertisement",
100                "others"
101            ],
102            "rejected": []
103        };
104    } else if (is_banner_visible) {
105        // Initialize accepted and rejected arrays
106        let accepted = ["necessary"];  // Assuming "necessary" is always accepted
107        let rejected = [];
108
109        // Categories to check
110        let categoryList = ["functional", "analytics", "performance", "advertisement", "others"];
111
112        // Check each category's cookie value
113        categoryList.forEach(function(category) {
114            let cookieValue = getCookieValue('wt_consent', category);
115            if (cookieValue === 'yes') {
116                accepted.push(category);
117            } else if (cookieValue === 'no') {
118                rejected.push(category);
119            }
120        });
121
122        // Update the categories object based on cookie values
123        categories = {
124            "accepted": accepted,
125            "rejected": rejected
126        };
127    }
128    // If categories are defined and consent is already given, update the consent status
129    if (categories && (isConsentGiven() || !is_banner_visible || !is_gtm_template) || currentLaw === 'CCPA') {
130        update_consent_status(categories, true);
131    }
132    if(wcc_gcm_debug && !is_gtm_template) {
133        setConsentStatus();
134    }
135});
136
137// Example usage with event listener
138document.addEventListener("wcc_consent_update", function (eventData) {
139    const categories = eventData.detail.categories;
140    //Check whether categories exista nd consent already given
141    if (categories && isConsentGiven()) {
142        update_consent_status(categories);
143        if(wcc_gcm_debug && !is_gtm_template) {
144            setConsentStatus();
145        }
146    }
147});
148
149function update_consent_status(categories, is_refresh = false) {
150    // Define category mappings between category names and storage variables
151    const categoryMap = {
152        'advertisement': 'wcc_ad_storage',
153        'analytics': 'wcc_analytics_storage',
154        'functional': 'wcc_functionality_storage'
155    };
156
157    // Initialize consent statuses to 'denied'
158    Object.keys(categoryMap).forEach(category => {
159        window[categoryMap[category]] = 'denied';  // Use window object to dynamically set variable
160    });
161
162    // Update consent statuses based on accepted categories
163    categories.accepted.forEach(category => {
164        if (categoryMap[category]) {
165            window[categoryMap[category]] = 'granted';
166        }
167    });
168
169    // Optionally check for a bypass (if needed)
170    if (wcc_bypass) {
171        Object.keys(categoryMap).forEach(category => {
172            window[categoryMap[category]] = 'granted';
173        });
174        wcc_waiting_period = 100;
175    }
176    if( !is_refresh || !is_gtm_template ) {
177        // Update consent in gtag
178        gtag('consent', 'update', {
179            'ad_storage': wcc_ad_storage,
180            'ad_user_data': wcc_ad_storage,
181            'ad_personalization': wcc_ad_storage,
182            'analytics_storage': wcc_analytics_storage,
183            'functionality_storage': wcc_functionality_storage,
184            'personalization_storage': wcc_functionality_storage,
185            'security_storage': "granted",
186        });
187    }
188    if('advanced' === data._mode || is_gtm_template) {
189        set_redact_data(wcc_ad_storage);
190    }
191
192    // Dispatch a custom event after consent mode updates are complete
193    const consentUpdateEvent = new CustomEvent('wcc_gcm_updated', {
194        detail: {
195            ad_storage: wcc_ad_storage,
196            analytics_storage: wcc_analytics_storage,
197            functionality_storage: wcc_functionality_storage,
198            personalization_storage: wcc_functionality_storage
199        }
200    });
201    document.dispatchEvent(consentUpdateEvent);
202    // Push consent data to dataLayer after consent mode updates are complete
203    window.dataLayer = window.dataLayer || [];
204    window.dataLayer.push({
205        'event': 'wcc_gcm_consent_update',
206        'ad_storage': wcc_ad_storage,
207        'analytics_storage': wcc_analytics_storage,
208        'functionality_storage': wcc_functionality_storage,
209        'personalization_storage': wcc_functionality_storage
210    });
211}
212function set_redact_data(wcc_ad_storage) {
213    // Set ads redact data
214    if (!!data._redactData) {
215        let redactValue = wcc_ad_storage === 'granted' ? false : true;
216        gtag("set", "ads_data_redaction", redactValue);
217    }
218}
219
220function isConsentGiven() {
221    let wcc_consent_exist = getCookieValue('wt_consent', 'action');
222    // Return true if consent is 'yes' or 'no', otherwise return false
223    return wcc_consent_exist === 'yes' || wcc_consent_exist === 'no';
224}
225function getCookieValue(name, key) {
226    const cookies = document.cookie.split(';');
227    for (const cookie of cookies) {
228        const [cookieName, cookieValue] = cookie.split('=');
229        if (cookieName.trim() === name) {
230            const keyValuePairs = cookieValue.split(',');
231            for (const pair of keyValuePairs) {
232                const [pairKey, pairValue] = pair.split(':');
233                if (pairKey.trim() === key) {
234                    return pairValue.trim();
235                }
236            }
237        }
238    }
239    return false; // Return 'false' if cookie doesn't exist or key is not found
240}
241function setConsentStatus() {
242    function getConsentStatus(status) {
243        if (status === undefined) return "missing";
244        return status ? "granted" : "denied";
245    }
246    try {
247        console.log("Debugging Google Consent Mode:\n");
248        if (
249            !window["google_tag_data"] ||
250            !google_tag_data.ics ||
251            !google_tag_data.ics.entries
252        )
253            return console.log("\n\tNo Consent Mode data found");
254        let messageToPrint = "";
255        const consentModeData = google_tag_data.ics.entries;
256        let defaultMissing = false;
257        for (const consentItem in consentModeData) {
258            const currentItem = consentModeData[consentItem];
259            const defaultValue = getConsentStatus(currentItem["default"]);
260            const updatedValue = getConsentStatus(currentItem["update"]);
261            messageToPrint = `${messageToPrint}\n\t${consentItem}:\n\t\tDefault: ${defaultValue}\n\t\tUpdate: ${updatedValue}\n\n`;
262            if (defaultValue === "missing") defaultMissing = true;
263        }
264        if (defaultMissing) {
265            messageToPrint += "%c\n\tWarning: Some categories are missing a default value.\n";
266        }
267        if (google_tag_data.ics.wasSetLate) {
268            messageToPrint += "%c\n\tWarning: A tag read consent before a default was set.\n";
269        } else {
270            messageToPrint += "%c\n\tConsent mode states were set correctly.";
271        }
272
273        if (defaultMissing || google_tag_data.ics.wasSetLate) {
274            console.log(messageToPrint, "color: #C00");
275        } else {
276            console.log(messageToPrint, "color: #0C0");
277        }
278    } catch (error) {
279        return console.log("\n\nWarning: Error detecting consent mode status");
280    }
281}

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.