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.