PageSourceSearch

https://www.whatis6g.com/dist/front/static/new_default_theme/addons-google.js?v=641

js whatis6g.com collected 2026-10-04 11:05:00 UTC 21,544 bytes, 510 lines download raw bytes

1if (!customElements.get('addons-google')) {
2    class AddonsGoogle extends HTMLElement {
3        connectedCallback() {
4            this.googleConversion = this.dataset.googleConversion
5            if (this.googleConversion) {
6                try {
7                    this.googleConversion = SetToArr(JSON.parse(this.googleConversion))
8                } catch (e) {
9                    $log('AddonsGoogle-JSON解析失败:', e);
10                    this.googleConversion = []
11                }
12            }
13            // $log('googleConversion', this.googleConversion)
14            this.advCart = $getAdvCart(this.googleConversion) //购物车事件
15            this.advCheckout = $getAdvCheckout(this.googleConversion)//结账页事件
16            this.advPurchase = $getAdvPurchase(this.googleConversion)//
17            this.advEmail = $getAdvEmail(this.googleConversion)
18            this.advWhatsapp = $getAdvWhatsapp(this.googleConversion)
19            this.advPhone = $getAdvPhone(this.googleConversion)
20            this.advPerson = $getAdvPerson(this.googleConversion)
21            this.advInquiry = $getAdvInquiry(this.googleConversion)
22            if (window.baseData.page_type === 'product') {//商品详情页发送打点事件
23                setTimeout(() => {
24                    this.sendGoogleSelectItem()
25                }, 20)
26            }
27
28            setTimeout(() => {
29                if (window.baseData.page_type === 'collection') {
30                    this.sendGoogleViewItemList()//只有在商品专辑页 才发送打点列表
31
32                }
33            }, 20)
34        }
35
36        // 商品页 非侧栏购物车和购物车页的加入购物车事件
37        addToCartProductGoogleAnalysis(item, qty) {
38            try {
39                $log('addToCartGoogleAnalysis', item)
40                let gclid = Cookies.get('gg_gclid') || null
41                let sendGclid = {}
42                if (gclid) {
43                    sendGclid = {
44                        'gclid': gclid
45                    }
46                }
47                gtag('event', 'add_to_cart', {
48                    ...sendGclid,
49                    "currency": window.baseData.currency_code || '',
50                    "value": accMul((item.price), qty),
51                    "items": [
52                        {
53                            "item_id": item.product_id,
54                            "item_name": item.f_title ? item.f_title : item.title,
55                            "item_variant": item.title || '',
56                            "quantity": qty,
57                            "price": Number(item.price)
58                        }
59                    ]
60                });
61            } catch (e) {
62                console.error('add_to_cart:001109 ', e)
63            }
64        }
65
66        // 仅限于侧栏购物车 + 购物车页面调用
67        addToCartGoogleAnalysis(item, qty) {
68            try {
69                if (typeof gtag === 'undefined' || !gtag) {
70                    console.warn("gtag is not loaded yet.");
71                    return;
72                }
73                $log('addToCartGoogleAnalysis', item)
74                let gclid = Cookies.get('gg_gclid') || null
75                let sendGclid = {}
76                if (gclid) {
77                    sendGclid = {
78                        'gclid': gclid
79                    }
80                }
81                gtag('event', 'add_to_cart', {
82                    ...sendGclid,
83                    "currency": window.baseData.currency_code || '',
84                    "value": accMul((item.price || item.curr_price), qty),
85                    "items": [
86                        {
87                            "item_id": item.product_id,
88                            "item_name": item.product_f_title ? item.product_f_title : item.product_title,
89                            "item_variant": item.variant_title || '',
90                            "quantity": qty,
91                            "price": Number(item.price || item.curr_price)
92                        }
93                    ]
94                });
95            } catch (e) {
96                console.error('add_to_cart:001109 ', e)
97            }
98            try {
99                $log('addToCartGoogleAnalysis-adv', this.advCart)
100                if (typeof gtag === 'undefined' || !gtag) {
101                    console.warn("gtag is not loaded yet.");
102                    return;
103                }
104                if (this.advCart) {
105                    let formSubmitted = false;
106                    for (let i = 0; i < this.advCart.length; i++) {
107                        try {
108                            gtag('event', 'conversion', {
109                                'send_to': this.advCart[i],
110                                // 'event_callback': this.addToCartSuccess()
111                                'event_callback': ''
112                            });
113                        } catch (e) {
114                            console.error('addToCart:', e)
115                        }
116                    }
117                    return false;
118                }
119            } catch (e) {
120
121            }
122        }
123
124        removeCartGoogleAnalysis(item) {
125            $log('删除商品', item)
126            try {
127                if (typeof gtag === 'undefined' || !gtag) {
128                    console.warn("gtag is not loaded yet.");
129                    return;
130                }
131                gtag('event', 'remove_from_cart', {
132                    "currency": window.baseData.currency_code || '',
133                    "value": accMul(item.price || item.curr_price, item.qty),
134                    "items": [
135                        {
136                            "item_id": item.product_id,
137                            "item_name": item.product_f_title ? product_f_title : item.product_title,
138                            "item_variant": item.variant_title || '',
139                            "quantity": item.qty,
140                            "price": Number(item.price || item.curr_price)
141                        }
142                    ]
143                });
144            } catch (e) {
145                console.error('remove_from_cart:001109 ', e)
146            }
147        }
148
149        sendGoogleViewItemList() {//专辑商品列表打点事件
150            if (typeof gtag === 'undefined' || !gtag) {
151                console.warn("gtag is not loaded yet.");
152                return;
153            }
154            const scriptTag = document.querySelector('script[data-product-list]') || null;
155            if (scriptTag) {
156                let productListJson = JSON.parse(scriptTag.textContent);
157                if (!productListJson.length) return;
158                let ICKS = window.baseData.addons.includes('icks')
159                if (ICKS) return //双库模式不发送打点信息
160                if (window.baseData.page_type !== 'collection') return;//只有专辑页才发送
161                let arr = []
162                let categoryTitle = document.querySelector('collection-init')?.dataset?.name || ''
163                productListJson.forEach((item, index) => {
164                    arr.push({
165                        "item_id": item.id,
166                        "item_name": item.title,
167                        "item_list_name": categoryTitle,//专辑名称
168                        "item_category": categoryTitle,//专辑名称
169                        "quantity": 1,
170                        "price": Number(item.price)
171                    })
172                })
173
174                // console.warn('>>>>>>>>view_item_list>>>>>>>>>',arr)
175
176                gtag('event', 'view_item_list', {
177                    "currency": window.baseData.currency_code || '',
178                    "items": arr
179                });
180
181            }
182        }
183
184        sendGoogleSelectItem() {//从搜索页 或者专辑页跳转过来的
185            if (typeof gtag === 'undefined' || !gtag) {
186                console.warn("gtag is not loaded yet.");
187                return;
188            }
189            let referrer = document.referrer;
190            let ICKS = window.baseData.addons.includes('icks')
191            if (ICKS) return //双库模式不发送打点信息
192
193            let navigationInfo = performance.getEntriesByType("navigation")[0];
194            if (navigationInfo && navigationInfo.type !== "navigate") return;//type == navigated的才能代表是从专辑页或者搜索页点击进入的
195            // if (navigationInfo.type === "reload") {
196            //     $log("页面是通过刷新加载的");
197            // } else if (navigationInfo.type === "navigate") {
198            //     $log("页面是通过点击进入的");
199            // } else if (navigationInfo.type === "back_forward") {
200            //     $log("页面是通过浏览器前进/后退按钮加载的");
201            // }
202            if (referrer) {
203                try {
204                    const scriptEl = document.querySelector('#product-data-json');
205                    if (!scriptEl) {
206                        return;
207                    }
208                    let product = JSON.parse(scriptEl.textContent || {});
209                    if (!product) return;
210                    // 规范化 b 变量,确保只保留域名部分,去除尾部的 '/' 或多语言路径
211                    let baseUrl = new URL(this.dataset.baseUrl).origin; //
212                    let referrerName = ''
213                    // 判断 referrer 来自哪个页面
214                    if (referrer.startsWith(baseUrl)) {
215                        if (referrer.includes('/collections/')) {
216                            // $log('是从 collections 页面过来的');
217                            referrerName = sessionStorage.getItem('collection-name');//商品专辑页的名称
218                        } else if (referrer.includes('/search')) {
219                            // $log('是从 search 页面过来的');
220                            let urlParams = new URLSearchParams(new URL(referrer).search);
221                            referrerName = urlParams.get('q');//搜索的关键词
222                        } else {
223                            // $log('不是从 collections 或 search 页面过来的');
224                        }
225                    }
226                    // $log('referrerName',referrerName,product)
227                    gtag('event', 'select_item', {
228                        "items": [
229                            {
230                                "item_id": product.id,
231                                "item_name": product.title,
232                                "item_list_name": referrerName,
233                                "quantity": 1,
234                                "price": Number(product.price)
235                            }
236                        ],
237                        'event_callback': ''
238                    });
239                } catch (e) {
240                    console.error('google:', e)
241                }
242
243
244            }
245        }
246
247        sendGoogleCheckOut(checkoutInfo) {
248
249            $log('-------------------google_trace----------------', this.advCheckout)
250            if (typeof gtag === 'undefined' || !gtag) {
251                console.warn("gtag is not loaded yet.");
252                return;
253            }
254            if (this.advCheckout) {
255                for (let i = 0; i < this.advCheckout.length; i++) {
256                    try {
257                        gtag('event', 'conversion', {
258                            'send_to': this.advCheckout[i],
259                        });
260                    } catch (e) {
261                        console.error(e)
262                    }
263                }
264            }
265            let list = JSON.parse(JSON.stringify(checkoutInfo.items))
266            list = SetToArr(list)
267            let totalPrice = 0
268            let arr = []
269            list.forEach((item, index) => {
270                totalPrice = accAdd(totalPrice, accMul(item.curr_price, item.qty))
271
272                arr.push({
273                    "item_id": item.product_id,
274                    "item_name": item.product_title,
275                    "item_variant": item.variant_title || '',
276                    "quantity": item.qty,
277                    "price": Number(item.curr_price),
278                    "item_category": item?.collect?.collection?.title || ''
279                })
280            })
281            let gclid = Cookies.get('gg_gclid') || null
282            let sendGclid = {}
283            if (gclid) {
284                sendGclid = {
285                    'gclid': gclid
286                }
287            }
288            gtag('event', 'begin_checkout', {
289                ...sendGclid,
290                "currency": window.baseData.currency_code || '',
291                "value": totalPrice,
292                "items": arr,
293                "coupon": checkoutInfo.coupon_code
294            });
295
296
297        }
298
299        // 结账成功事件
300        sendGoogleCheckOutSuccess(orderInfo) {
301            $log('sendGoogleCheckOutSuccess-结账页成功事件', orderInfo, this.advPurchase)
302            if (typeof gtag === 'undefined' || !gtag) {
303                console.warn("gtag is not loaded yet.");
304                return;
305            }
306            if (this.advPurchase) {
307                for (let i = 0; i < this.advPurchase.length; i++) {
308                    try {
309                        gtag('event', 'conversion', {
310                            'send_to': this.advPurchase[i],
311                            'transaction_id': orderInfo.order_number,
312                            "value": orderInfo.curr_grand_total,//订单金额
313                            "currency": orderInfo.currency_code,//单货币简码
314                        });
315                    } catch (e) {
316                        console.error(e)
317                    }
318                }
319            }
320            let list = orderInfo.items
321            let arr = []
322            let totalPrice = 0
323
324            list.forEach((item, index) => {
325                totalPrice = accAdd(totalPrice, accMul(item.curr_price, item.qty))
326
327                arr.push({
328                    "item_id": item.product_id,
329                    "item_name": item.product_title,
330                    "item_variant": item.variant_title || '',
331                    "quantity": item.qty,
332                    "price": Number(item.curr_price),
333                    "item_category": item?.collect?.collection?.title || ''
334                })
335            })
336            $log(arr, 'arr')
337            $log(totalPrice, 'totalPrice')
338
339            try {
340                let gclid = Cookies.get('gg_gclid') || null
341                let sendGclid = {}
342                if (gclid) {
343                    sendGclid = {
344                        'gclid': gclid
345                    }
346                }
347                gtag('event', 'purchase', {
348                    ...sendGclid,
349                    "transaction_id": orderInfo.order_number,
350                    "value": totalPrice,//商品总额,不是订单总额
351                    "tax": orderInfo.curr_tax,//税
352                    "shipping": orderInfo.curr_shipping_total,//运费
353                    "currency": orderInfo.currency_code,//单货币简码
354                    "coupon": orderInfo.coupon_code,
355                    "items": arr
356                });
357            } catch (e) {
358
359            }
360        }
361
362        //结账页事件类型 add_payment_info  add_shipping_info,
363
364        selectPaymentAnalysis(checkoutInfo, type = 'add_payment_info') {
365            // $log('selectPaymentAnalysis-进来了吗', checkoutInfo.items, type)
366            let arr = []
367            let totalPrice = 0
368            if (typeof gtag === 'undefined' || !gtag) {
369                console.warn("gtag is not loaded yet.");
370                return;
371            }
372            checkoutInfo.items.forEach(el => {
373                totalPrice = accAdd(totalPrice, accMul(el.curr_price, el.qty))
374                arr.push({
375                    "item_id": el.product_id,
376                    "item_name": el.product_title,
377                    "item_variant": el.variant_title || '',
378                    "quantity": el.qty,
379                    "price": Number(el.curr_price),
380                    "item_category": el?.collect?.collection?.title || ''
381                })
382            })
383            // $log('开始发送selectPaymentAnalysis----arr', arr)
384            // $log('开始发送selectPaymentAnalysis----totalPrice', totalPrice)
385
386
387            try {
388                let gclid = Cookies.get('gg_gclid') || null
389                let sendGclid = {}
390                if (gclid) {
391                    sendGclid = {
392                        'gclid': gclid
393                    }
394                }
395                gtag('event', type, {//事件类型 add_payment_info  add_shipping_info,
396                    ...sendGclid,
397                    "currency": window.baseData.currency_code || '',
398                    "value": totalPrice,
399                    "items": arr,
400                    "coupon": checkoutInfo.coupon_code
401                });
402            } catch (e) {
403                console.error('checkout_progress:001109 ', e)
404            }
405
406        }
407
408        sidebarSendTrace(type) {//侧栏联系我们点击事件 由 sidebar-contact-information 标签触发
409            if (typeof gtag === 'undefined' || !gtag) {
410                console.warn("gtag is not loaded yet.");
411                return;
412            }
413            if (type === 'email' && this.advEmail) {//邮件
414                $log('有邮件信息可以发送', this.advEmail)
415                try {
416                    for (let i = 0; i < this.advEmail.length; i++) {
417                        try {
418                            // console.warn('发送打点信息person:',this.advPerson[i])
419
420                            gtag('event', 'conversion', {
421                                'send_to': this.advEmail[i],
422                            });
423                        } catch (e) {
424                            console.error(e)
425                        }
426
427                    }
428                } catch (e) {
429                    console.error('advInquiry 0930 ', e)
430                }
431            } else if (type === 'whatsapp' && this.advWhatsapp) {//whatsapp
432                $log('sendTrace-whatsapp')
433                try {
434                    for (let i = 0; i < this.advWhatsapp.length; i++) {
435                        try {
436                            // console.warn('发送打点信息person:',this.advPerson[i])
437
438                            gtag('event', 'conversion', {
439                                'send_to': this.advWhatsapp[i],
440                            });
441                        } catch (e) {
442                            console.error(e)
443                        }
444
445                    }
446                } catch (e) {
447                    console.error('advInquiry 0930 ', e)
448                }
449            } else if (type === 'phone' && this.advPhone) {//advPhone
450                $log('sendTrace-phone')
451
452                try {
453                    for (let i = 0; i < this.advPhone.length; i++) {
454                        try {
455                            // console.warn('发送打点信息person:',this.advPerson[i])
456                            gtag('event', 'conversion', {
457                                'send_to': this.advPhone[i],
458                            });
459                        } catch (e) {
460                            console.error(e)
461                        }
462
463                    }
464                } catch (e) {
465                    console.error('advInquiry 0930 ', e)
466                }
467            } else if (type === 'inquiry' && this.advInquiry) {//advInquiry
468                $log('sendTrace-inquiry', this.advInquiry)
469                try {
470                    for (let i = 0; i < this.advInquiry.length; i++) {
471                        try {
472                            // console.warn('发送打点信息person:',this.advPerson[i])
473                            gtag('event', 'conversion', {
474                                'send_to': this.advInquiry[i],
475                            });
476                        } catch (e) {
477                            console.error(e)
478                        }
479
480                    }
481                } catch (e) {
482                    console.error('advInquiry 0008 ', e)
483                }
484            } else if (this.advPerson) {//谷歌打点
485                $log('advPerson打点', this.advPerson)
486                try {
487                    for (let i = 0; i < this.advPerson.length; i++) {
488                        try {
489                            // console.warn('发送打点信息person:',this.advPerson[i])
490
491                            gtag('event', 'conversion', {
492                                'send_to': this.advPerson[i],
493                            });
494                        } catch (e) {
495                            console.error(e)
496                        }
497
498                    }
499                } catch (e) {
500                    console.error('advInquiry 0930 ', e)
501                }
502            }
503        }
504
505
506    }
507
508    customElements.define('addons-google', AddonsGoogle)
509
510}

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.