PageSourceSearch

https://cdn.bahroma1.ru/js/ga4.js

js bahroma1.ru collected 2026-09-24 10:48:55 UTC 9,573 bytes, 334 lines download raw bytes

1function uuidv4() {
2    return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
3        (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
4    );
5}
6
7const simpleCartConfig = {
8
9    // Укажите ID плагина который принимает заказы
10    pluginId: 3,
11
12    isOrderCreated: () => {
13        return window.location.search.indexOf(`pl${simpleCartConfig.pluginId}_id`) != -1
14    }
15}
16
17
18const ymECommerce = {
19
20    // Добавить
21    add: (id, name, category, price, quantity) => {
22        window.dataLayerYandex = window.dataLayerYandex || [];
23        window.dataLayerYandex.push({
24            "ecommerce": {
25                "add": {
26                    "actionField": {
27                        "id": uuidv4()
28                    },
29                    "products": [{
30                        'id': id,
31                        'name': name,
32                        'category': category,
33                        'price': price,
34                        'quantity': quantity
35                    }]
36                }
37            }
38        });
39    },
40
41    // Удалить
42    remove: (id, name, category, price, quantity) => {
43        window.dataLayerYandex = window.dataLayerYandex || [];
44        window.dataLayerYandex.push({
45            "ecommerce": {
46                "remove": {
47                    "actionField": {
48                        "id": uuidv4()
49                    },
50                    "products": [{
51                        'id': id,
52                        'name': name,
53                        'category': category,
54                        'price': price,
55                        'quantity': quantity === 0 ? 1 : quantity
56                    }]
57                }
58            }
59        });
60        try {
61            ym(33193178,"reachGoal","remove_from_cart", {
62                currency: "RUB",
63                items: [{
64                    id: id,
65                    name: name,
66                    category: category,
67                    price: price,
68                    quantity: quantity
69                }],
70                value: price,
71            });
72        } catch (error) {
73            console.warn(error);
74        }
75    },
76
77    purchase: (products) => {
78        window.dataLayerYandex = window.dataLayerYandex || [];
79
80        window.dataLayerYandex.push({
81            "ecommerce": {
82                "purchase":
83                {
84                    "actionField": {
85                        "id": uuidv4()
86                    },
87                    "products": products
88                }
89            }
90        });
91    }
92}
93
94const gaECommerce = {
95    add: (id, name, category, price, quantity) => {
96        console.log('ga ecom add f name=', id, name, category, price, quantity, price);
97        try {
98            gtag('event', 'add_to_cart', {
99                currency: "RUB",
100                items: [{
101                    id: id,
102                    name: name,
103                    category: category,
104                    price: price,
105                    quantity: quantity
106                }],
107                value: price,
108            })
109        } catch (error) {
110            console.warn(error);
111        }
112    },
113
114
115    remove: (id, name, category, price, quantity) => {
116        console.log('ga ecom remove f name=', id, name, category, price, quantity, price);
117        try {
118            gtag('event', 'remove_from_cart', {
119                currency: "RUB",
120                items: [{
121                    id: id,
122                    name: name,
123                    category: category,
124                    price: price,
125                    quantity: quantity
126                }],
127                value: price,
128            })
129        } catch (error) {
130            console.warn(error);
131        }
132    },
133
134    purchase: (products) => {
135        console.log('products', products);
136        try {
137            gtag("event", "purchase", {
138                transaction_id: uuidv4(),
139                value: simpleCart.total(),
140                currency: "RUB",
141                items: products,
142            });
143        } catch (error) {
144            console.warn(error);
145        }
146    }
147}
148
149$(function () {
150
151    function getCartItems() {
152	var items = [];
153	simpleCart.each(function (item, x) {
154                items.push({
155                    item_name: item.get('name'), // Name or ID is required.
156                    item_id: item.get('uid'),
157                    price: item.get('price'),
158                    item_category: item.get('basecategory'),
159                    quantity: item.get('quantity')
160                });
161            });
162        return items;
163    
164    }
165
166    simpleCart.bind('load', function (item) {
167	if (document.location.href.match(/cart.html/)) {
168    	    try {
169    		items = getCartItems();
170        	gtag("event", "begin_checkout");
171        	gtag("event", "view_cart", {items: items});
172		console.log("view cart items", getCartItems());
173    	    } catch (error) {
174        	console.warn(error);
175    	    }
176	}
177    })
178
179    if (document.location.href.match(/\/product/)) {
180        name = $("h1 span[itemprop='name']").text();
181        id = $("div[data-type='full']").data('pid');
182        price = $("div[name='item__price-value']").data('baseprice');
183        category = $("a.breadcrumbs__item span[itemprop='name']").last().text();
184        try {
185    	    console.log('view_items', 'name', name, 'id', id, 'price', price);
186            gtag("event", "view_item", {
187                currency: "RUB",
188                items: [{
189                    item_id: id,
190                    item_name: name,
191                    item_category: category
192                }],
193                value: price,
194            });
195        } catch (error) {
196            console.warn(error);
197        }
198    }
199
200    if (document.location.href.match(/spisok-product/)) {
201        item_list_name = $(".title__container").text();
202
203        try {
204            gtag("event", "view_item_list", { item_list_name: item_list_name });
205        } catch (error) {
206            console.warn(error);
207        }
208    }
209
210    $("input#street").change(function () {
211        try {
212            gtag("event", "add_shipping_info");
213        } catch (error) {
214            console.warn(error);
215        }
216    });
217
218    $("div#payments_mode_block input").change(function () {
219        try {
220            gtag("event", "add_payment_info");
221        } catch (error) {
222            console.warn(error);
223        }
224    });
225
226});
227
228
229
230simpleCart.bind('beforeAdd', function (item) {
231    ymECommerce.add(
232        item.get('uid'),
233        item.get('name'),
234        item.get('basecategory'),
235        item.get('price'),
236        item.get('quantity')
237    );
238
239    console.log('start ga ecommerce add');
240    gaECommerce.add(
241        item.get('uid'),
242        item.get('name'),
243        item.get('basecategory'),
244        item.get('price'),
245        item.get('quantity')
246    );
247});
248
249simpleCart.bind('beforeRemove', function (item) {
250    if (simpleCartConfig.isOrderCreated()) {
251        ymECommerce.remove(
252            item.get('uid'),
253            item.get('name'),
254            item.get('basecategory'),
255            item.get('price'),
256            item.get('quantity')
257        );
258    }
259    
260    gaECommerce.remove(
261        item.get('uid'),
262        item.get('name'),
263        item.get('basecategory'),
264        item.get('price'),
265        item.get('quantity')
266    );
267
268    
269});
270
271
272
273document.addEventListener('sendPurchase', () => {
274    console.log('send purchase 1');
275
276    const productsYandex = [];
277    simpleCart.each(item => {
278        productsYandex.push({
279            'id': item.get('uid'),
280            'name': item.get('name'),
281            'category': item.get('basecategory'),
282            'price': item.get('price'),
283            'quantity': item.get('quantity')
284        });
285    });
286
287    const productsGoogle = [];
288    simpleCart.each(item => {
289        productsGoogle.push({
290            item_id: item.get('uid'),
291            item_name: item.get('name'),
292            item_category: item.get('basecategory'),
293            price: item.get('price'),
294            quantity: item.get('quantity')
295        });
296    });
297
298    ymECommerce.purchase(productsYandex);
299    gaECommerce.purchase(productsGoogle);
300
301    try {
302        //gtag('event', 'order');
303    } catch (error) {
304        console.warn(error);
305    }
306});
307
308document.addEventListener('click', (e) => {
309    const target = e.target;
310    const row = target.closest('.itemRow');
311
312    if (row !== null) {
313        const id = row.id.replace('cartItem_', '');
314        const item = simpleCart.find(id);
315
316        if (item.length === 0) {
317            console.error(`item with id ${id} not found`);
318
319            return;
320        }
321
322        if (target.classList.contains('simpleCart_increment')) {
323            ymECommerce.add(item.get('uid'), item.get('name'), item.get('basecategory'), item.get('price'), 1);
324        }
325
326        if (target.classList.contains('simpleCart_decrement')) {
327            ymECommerce.remove(item.get('uid'), item.get('name'), item.get('basecategory'), item.get('price'), 1)
328        }
329
330        if (target.classList.contains('simpleCart_remove')) {
331            ymECommerce.remove(item.get('uid'), item.get('name'), item.get('basecategory'), item.get('price'), item.get('quantity'))
332        }
333    }
334});

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.