PageSourceSearch

https://netpeak.bg/assets/js/page-data-layer.js

js netpeak.bg collected 2026-10-09 17:11:25 UTC 3,574 bytes, 150 lines download raw bytes

1const SENT_SUCCESS = 'Form_Sent_Successfully';
2const SENT_ERROR = 'Form_Sent_Error';
3const HEADER_LINK = 'Header_Menu_Interaction';
4const FOOTER_LINK = 'Footer_Menu_Interaction';
5
6/**
7 * @return {string}
8 */
9const getFormType = function () {
10    let form = window.formData.currentForm;
11    return form.attr('data-form-type') || '';
12}
13
14/**
15 * @return {string}
16 */
17const getFormLocation = function () {
18    let form = window.formData.currentForm;
19    return form.attr('data-form-location') || '';
20}
21
22/**
23 * @return {string}
24 */
25const getDeviceID = function () {
26    let deviceId = getCookie('_ga') || '';
27    let gaBlock = new RegExp('^GA[0-9]\.[0-9]\.', 'g');
28
29    return deviceId.replace(gaBlock, '');
30}
31
32/**
33 * @param key
34 * @return {null|string}
35 */
36const getCookie = function (key) {
37    const cookies = document.cookie.split(';');
38    for (const cookie of cookies) {
39        const [cookieKey, cookieValue] = cookie.trim().split('=');
40        if (cookieKey === key) {
41            return decodeURIComponent(cookieValue);
42        }
43    }
44    return null;
45}
46
47/**
48 * @param formSentResult {boolean}
49 * @param error {string}
50 */
51const setFormEventDataLayer = function (
52    formSentResult,
53    error = 'Something went wrong while submitting the form.'
54) {
55    if (typeof error !== 'string') {
56        error = JSON.stringify(error);
57    };
58
59    let eventData = {
60        event: formSentResult ? SENT_SUCCESS : SENT_ERROR,
61        deviceID: getDeviceID(),
62        formType: getFormType(),
63        FormLocation: getFormLocation()
64    };
65
66    if (!formSentResult) {
67        eventData.errorText = error;
68    }
69
70    window.dataLayer.push(eventData);
71}
72
73/**
74 * @param linkType {string} select from [HEADER_LINK, FOOTER_LINK]
75 * @param linkText {string}
76 */
77const setLinkEventData = function (linkType, linkText) {
78    let eventData = {
79        event: linkType,
80        clickedItem: linkText
81    };
82    window.dataLayer.push(eventData);
83}
84
85/**
86 * @param event
87 */
88const headerLinkHandle = function (event) {
89    if (event.originalEvent.button === 2) {
90        return;
91    }
92
93    let linkText = this.innerText;
94    if (linkText === '' && this.firstElementChild.tagName === 'IMG') {
95        linkText = this.firstElementChild.alt;
96    }
97
98    setLinkEventData(HEADER_LINK, linkText);
99}
100
101/**
102 * @param event
103 */
104const footerLinkHandle = function (event) {
105    if (event.originalEvent.button === 2) {
106        return;
107    }
108
109    let linkText = this.innerText;
110    if (linkText === '' && this.firstElementChild.tagName === 'IMG') {
111        linkText = this.firstElementChild.alt;
112    }
113
114    setLinkEventData(FOOTER_LINK, linkText);
115}
116
117/**
118 * @param form
119 * @return {string}
120 */
121const validateForm = function (form) {
122    for (let index in form) {
123        let input = form[index];
124        if (!input || !input.validity || input.validity.valid) {
125            continue;
126        }
127
128        return  input.validationMessage + ' - ' + input.name;
129    }
130
131    return 'errorMessage';
132}
133
134/**
135 * @param event
136 */
137const submitClickFormSentError = function (event) {
138    let form = event.currentTarget.form;
139    window.formData = {currentForm: $(form)};
140    let  errorMessage = validateForm(form);
141    setFormEventDataLayer(false, errorMessage);
142}
143
144$(() => {
145    $('.navbar-desktop-netpeak-site.w-nav a').mousedown(headerLinkHandle);
146    $('.navbar_desktop_netpeak-site.w-nav a').mousedown(headerLinkHandle);
147    $('.navbar_mobile_netpeak-site.w-nav a').mousedown(headerLinkHandle);
148    $('.navbar-mobile-netpeak-site.w-nav a').mousedown(headerLinkHandle);
149    $('footer a').mousedown(footerLinkHandle);
150});

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.