1let method_customData = "undefined" !== typeof customData ? customData["method-ga-gtag"] : "gtag"; 2 3function ga4EventAction(category, action) { 4 let event_name = category; 5 if ("podcasts-eng" === category) { 6 event_label = action; 7 label = action; 8 event_name = "podcasts_eng"; 9 } else { 10 if ("" !== action) { 11 event_name = category + "_" + action; 12 } 13 event_name = event_name.trimStart().trimEnd().toLowerCase().substring(0, 40); 14 event_name = ga4Replace(event_name); 15 } 16 event_name = event_name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); 17 18 return ga4Replace(event_name); 19} 20 21function ga4Replace(name){ 22 return name.replaceAll(" ", "_").replaceAll(" - ", "_").replaceAll("-", "_").replaceAll("__", "_").replaceAll("___", "_"); 23} 24 25function validObjValue(value, defaultValue) { 26 if (value !== undefined) { 27 return value; 28 } 29 return defaultValue; 30} 31 32function gaUserProperties(customData){ 33 gtag("set", "user_properties", customData); 34} 35 36function gaSendEvent(...args) { 37 dataObj = {}; 38 let notObj = false; 39 if (typeof args[0] === "string") { 40 dataObj["metric"] = args[0]; 41 dataObj["category"] = args[1]; 42 dataObj["action"] = args[2]; 43 dataObj["label"] = args[3]; 44 dataObj["noninteraction"] = validObjValue(args[5], true); 45 46 notObj = true; 47 } else { 48 dataObj = args[0]; 49 } 50 let brand = validObjValue(dataObj["brand"], ""); 51 let category = validObjValue(dataObj["category"], ""); 52 let action = validObjValue(dataObj["action"], ""); 53 let label = validObjValue(dataObj["label"], ""); 54 let metric = validObjValue(dataObj["metric"], ""); 55 let noninteraction = validObjValue(dataObj["noninteraction"], true); 56 let send = validObjValue(dataObj["send"], "send"); 57 let hit_type = validObjValue(dataObj["hit_type"], "event"); 58 let event_value = validObjValue(dataObj["event_value"], ""); 59 let cookie_ua = validObjValue(customData["cookie-ua"], ""); 60 let dimensionsGA4 = validObjValue(dataObj["dimensionsGA4"], {}); 61 let ga_free = validObjValue(dataObj["ga_free"], false); 62 63 if (typeof customData["method-gtag"] !== "undefined") { 64 if (customData["method-gtag"] !== "") { 65 if (typeof gtag !== "undefined" && typeof category !== undefined) { 66 let event_name = ga4EventAction(category, action); 67 let ga4custom = { 68 event_label: label, 69 value: event_value, 70 non_interaction: noninteraction, 71 }; 72 73 ga4custom["event_category"] = category; 74 ga4custom["event_label"] = label; 75 76 if (dimensionsGA4 !== undefined) { 77 Object.keys(dimensionsGA4).forEach((key) => { 78 ga4custom[key] = dimensionsGA4[key]; 79 }); 80 } 81 82 ga4custom["send_to"] = customData["id_ga4"]; 83 if(ga_free){ 84 console.log("==== Evento ga Free"); 85 if( 86 typeof customData["id_ga4_free"] !== "undefined" && 87 customData["id_ga4_free"] !== "" && 88 customData["id_ga4_free"] != null 89 ){ 90 ga4custom["send_to"] = customData["id_ga4_free"]; 91 console.log("==== Evento ga Free - disparar"); 92 }else{ 93 console.log("==== Evento ga Free - Não disparar"); 94 return; 95 } 96 } 97 98 gtag("event", event_name, ga4custom); 99 console.log(` 100 Tipo: 'gtag', 101 Nome: ${event_name}, 102 Metrica: ${metric}, 103 Categoria: ${category}, 104 Ação do evento: ${action}, 105 Value: ${event_value}, 106 Rótulo do evento: ${label}, 107 Não interação: ${noninteraction}, 108 GA Free: ${ga_free}, 109 `); 110 } 111 } 112 } 113} 114 115function gaAddToCart(product, id, price, brand, category) { 116 if (typeof customData["method-gtag"] !== "undefined") { 117 if (customData["method-gtag"] !== "") { 118 if (typeof gtag !== "undefined") { 119 gtag("event", "add_to_cart", { 120 send_to: customData["id_ga4"], 121 currency: "BRL", 122 value: price, 123 items: [ 124 { 125 item_id: id, 126 item_name: product, 127 affiliation: "Abril", 128 index: 0, 129 item_brand: brand, 130 item_category: category, 131 price: price, 132 quantity: 1, 133 }, 134 ], 135 }); 136 137 console.log(` 138 Tipo: 'gtag', 139 Event: add_to_cart, 140 product: ${product}, 141 id: ${id}, 142 price: ${price}, 143 brand: ${brand}, 144 category: ${category}, 145 `); 146 } 147 } 148 } 149} 150 151function gaCheckoutOption(checkoutOption) { 152 if (typeof customData["method-gtag"] !== "undefined") { 153 if (customData["method-gtag"] !== "") { 154 if (typeof gtag !== "undefined") { 155 gtag("event", "set_checkout_option", { 156 send_to: customData["id_ga4"], 157 checkout_step: 1, 158 checkout_option: "payment_method", 159 value: checkoutOption, 160 }); 161 162 console.log(` 163 Tipo: 'gtag', 164 Event: gaCheckoutOption, 165 checkoutOption: ${checkoutOption} 166 `); 167 } 168 } 169 } 170} 171 172function gaPurchase(transactionId, transactionTotal, sku, name, brand, category, pID, tipopag, dimensionsGA4 = {}) { 173 if (typeof customData["method-gtag"] !== "undefined") { 174 if (customData["method-gtag"] !== "") { 175 if (typeof gtag !== "undefined") { 176 let ga4custom = { 177 transaction_id: transactionId, 178 value: transactionTotal, 179 tax: 0, 180 shipping: 0, 181 currency: "BRL", 182 coupon: "", 183 items: [ 184 { 185 item_id: sku, 186 item_name: name, 187 item_category: category, 188 affiliation: "Abril", 189 coupon: "", 190 discount: 0, 191 item_brand: brand, 192 price: transactionTotal, 193 quantity: 1, 194 }, 195 ], 196 }; 197
198 if (dimensionsGA4 !== undefined) { 199 Object.keys(dimensionsGA4).forEach((key) => { 200 ga4custom[key] = dimensionsGA4[key]; 201 }); 202 } 203 ga4custom["send_to"] = customData["id_ga4"]; 204 gtag("event", "purchase", ga4custom); 205 206 console.log(` 207 Tipo: 'gtag', 208 Event: 'Purchase', 209 transactionId: ${transactionId}, 210 transactionTotal: ${transactionTotal}, 211 sku: ${sku}, 212 name: ${name}, 213 brand: ${brand}, 214 category: ${category}, 215 pID: ${pID}, 216 tipo pag: ${tipopag}, 217 `); 218 } 219 } 220 } 221 222 postPurchaseBigQuery(transactionId, transactionTotal, sku, name, brand, category, pID, tipopag); 223 postConversaoAssinaturaBigQuery(transactionId, transactionTotal, sku, brand, category, tipopag); 224} 225// sku, preco, produto, brand, marca, categoria 226function gaProductView() { 227 if (typeof customData["method-gtag"] !== "undefined") { 228 if (customData["method-gtag"] !== "") { 229 if (typeof gtag !== "undefined") { 230 let total = 0; 231 let itens = {}; 232 $( ".new-paywall-promotion-container" ).each(function( index ) { 233 let oferta = $( this ).find(".view_item").data("produto"); 234 let originString = window.location.href; 235 if( (originString.indexOf("/ofertas/") >= 0 || originString.indexOf("/ofertas") >= 0)){ 236 oferta = $( this ).find("h2").text(); 237 } 238 if(oferta){ 239 let preco = parseFloat($( this ).find(".view_item").data("preco")); 240 let produto = { 241 item_id: $( this ).find(".view_item").data("codprojeto"), 242 item_name: $( this ).find(".view_item").data("produto"), 243 price: preco, 244 index: index, 245 quantity: 1 246 } 247 total = total + preco; 248 itens[index] = produto; 249 } 250 }); 251 252 // nova tela de oferta 253 $( ".oferta-content.active .oferta-prod" ).each(function( index ) { 254 if ($( this ).data('sku_id') !== undefined) { 255 oferta = $( this ).data("sku_oferta"); 256 if(oferta.length > 3){ 257 let originString = window.location.href; 258 if( (originString.indexOf("/ofertas/") >= 0 || originString.indexOf("/ofertas") >= 0)){ 259 oferta = $( this ).find("h3").text(); 260 } 261 let preco = parseFloat($( this ).data("sku_preco")); 262 let produto = { 263 item_id: $( this ).data("sku_cod_projeto"), 264 item_name: $( this ).data("sku_oferta"), 265 price: preco, 266 index: index, 267 tipo_contrato_pedido: $('.tabs div.active').text(), 268 quantity: 1 269 } 270 total = total + preco; 271 itens[index] = produto; 272 } 273 } 274 }); 275 276 const view_item = { 277 currency: "BRL", 278 value: total, 279 items: itens, 280 send_to: customData["id_ga4"] 281 }; 282 gtag("event", "view_item", view_item); 283 console.log(` 284 Tipo: 'gtag', 285 Event: 'View_Item' 286 `); 287 console.log(view_item); 288 } 289 } 290 } 291} 292let originString = window.location.href; 293if( (originString.indexOf("/ofertas/") >= 0 || originString.indexOf("/ofertas") >= 0)){ 294 if(typeof new_checkout === "undefined"){ 295 gaProductView(); 296 } 297} 298 299function gaBeginCheckout(sku, preco, produto, brand, marca, categoria) { 300 if (typeof customData["method-gtag"] !== "undefined") { 301 if (customData["method-gtag"] !== "") { 302 if (typeof gtag !== "undefined") { 303 gtag("event", "begin_checkout", { 304 send_to: customData["id_ga4"], 305 currency: "BRL", 306 value: preco, 307 items: [ 308 { 309 item_id: sku, 310 item_name: produto, 311 affiliation: "Abril", 312 index: 0, 313 item_brand: marca, 314 item_category: categoria, 315 price: preco, 316 quantity: 1 317 } 318 ] 319 }); 320 321 console.log(` 322 Tipo: 'gtag', 323 Event: 'gaBeginCheckout', 324 item_category: ${categoria}, 325 item_name: ${produto}, 326 preco: ${preco}, 327 item_id: ${sku}, 328 item_brand: ${marca}, 329 brand: ${brand} 330 `); 331 } 332 } 333 } 334} 335 336function postPurchaseBigQuery(transactionId, transactionTotal, sku, name, brand, category, pID, tipopag) { 337 let userID = gaGlobal.vid; 338 if (AbrilCustomDimension.checkUnicIdGlobal() ) { 339 userID = AbrilCustomDimension.getUnicIdGlobal(); 340 } 341 342 let postUrl = "https://us-central1-abril-id-testes-1528223718961.cloudfunctions.net/navigationData/dados-conversao"; 343 if ("undefined" !== typeof assine_environment) { 344 if (assine_environment[0] == "sandbox") { 345 postUrl = "https://us-central1-abril-id-homolog.cloudfunctions.net/navigationData/dados-conversao"; 346 } 347 } 348 349 if (pID == "") { 350 pID = 0; 351 } 352 $.ajax({ 353 url: postUrl, 354 type: "post", 355 dataType: "json", 356 data: { 357 produto: `${name}`, 358 sku: `${sku}`, 359 categoria: `${category}`, 360 marca: `${brand}`, 361 valor: `${parseFloat(transactionTotal).toFixed(2)}`, 362 tipo_pagamento: `${tipopag}`, 363 user_id: `${userID}`, 364 post_id: pID, 365 transacao_id: `${transactionId}`, 366 }, 367 async: true, 368 success: function (data) {
369 console.log("Purchase adicionou ao bigQuery"); 370 }, 371 }); 372} 373 374function postConversaoAssinaturaBigQuery(transactionId, transactionTotal, sku, brand, category, tipopag) { 375 let userID = gaGlobal.vid; 376 if (AbrilCustomDimension.checkUnicIdGlobal() ) { 377 userID = AbrilCustomDimension.getUnicIdGlobal(); 378 } 379 380 381 let postUrl = "https://us-central1-abril-id-testes-1528223718961.cloudfunctions.net/navigationData/dados-conversao-assinatura"; 382 if ("undefined" !== typeof assine_environment) { 383 if (assine_environment[0] == "sandbox") { 384 postUrl = "https://us-central1-abril-id-homolog.cloudfunctions.net/navigationData/dados-conversao-assinatura"; 385 } 386 } 387 var oferta = $("body").attr("data-oferta"); 388 var parcelas = $(".optsel").attr("data-numparcelas"); 389 let quebra = category.split("/"); 390 var tipo_assinatura = quebra[1]; 391 var tipo_plano = quebra[0]; 392 393 if ($('#checkout_ticket').val() !== ''){ 394 if($('.optsel').attr('data-voucher') > 0){ 395 oferta = $(".optsel").data("voucher_codcampanha"); 396 }else{ 397 oferta = $('#dataVoucher').attr('data-dscoferta'); 398 parcelas = 0; 399 } 400 } 401 402 if(tipopag === 'Google Swg'){ 403 parcelas = 1; 404 sku = $(".btn-offer-google").data("swgSku"); 405 oferta = $(".btn-offer-google").data("swgSku"); 406 } 407 if(tipopag === 'PayPal'){ 408 let formDataPaypal = JSON.parse(localStorage.getItem('abril_data_sel')); 409 oferta = formDataPaypal["data-ofertaafiliado"]; 410 sku = formDataPaypal["data-planoafiliado"]; 411 if(formDataPaypal["data-voucher"] > 0){ 412 oferta = formDataPaypal["data-voucher_codcampanha"]; 413 sku = formDataPaypal["data-voucher_codplano"]; 414 } 415 416 } 417 if(tipopag === 'Voucher 100%'){ 418 oferta = $("#dataVoucher").data("dscoferta"); 419 sku = $("#dataVoucher").data("codplano"); 420 tipo_plano = $("#dataVoucher").data("contrato"); 421 parcelas = 0; 422 } 423 424 let postData = { 425 user_id : `${userID}`, 426 pedido : `${transactionId}`, 427 oferta : `${oferta}`, 428 meio_pagamento : `${tipopag}`, 429 tipo_assinatura : `${tipo_assinatura}`, 430 tipo_plano : `${tipo_plano}`, 431 valor : `${transactionTotal}`, 432 parcelamento : `${parcelas}`, 433 marca : `${brand}`, 434 plano : `${sku}` 435 } 436 437 $.ajax({ 438 url: postUrl, 439 type: "post", 440 dataType: "json", 441 data: postData, 442 async: true, 443 success: function (data) { 444 console.log("Conversão Assinatura adicionou ao bigQuery"); 445 }, 446 }); 447} 448 449function gaEventDatalayer(event) { 450 if (typeof customData["method-gtag"] !== "undefined") { 451 if (customData["method-gtag"] !== "") { 452 if (typeof gtag !== "undefined") { 453 window.dataLayer = window.dataLayer || []; 454 dataLayer.push(event); 455 console.log(` 456 Tipo: 'gtag', 457 Event: gaCheckoutOption, 458 event: ${event} 459 `); 460 } 461 } 462 } 463} 464 465// Função que substitui a validação 466// if (typeof ga === 'undefined' || typeof compareMethod === 'undefined' ) 467// sendo o parâmetro compareMethod opcional e pegando o parâmetro de method dinamicamente 468function typeOfMethodCompare(compareMethod, method = method_customData) { 469 if (typeof compareMethod !== "undefined") { 470 if (typeof customData["method-gtag"] === "undefined" || typeof compareMethod === "undefined") { 471 return "undefined"; 472 } 473 } else { 474 if (typeof customData["method-gtag"] === "undefined") { 475 return "undefined"; 476 } 477 } 478} 479 480// Função que substitui a criação estática de instância por dinâmica, geralmente precedida pelo método typeOfMethodCompare 481function methodTagConfig(id_gaGtag, cookie_pref, cookie_dom) { 482 if (typeof customData["method-gtag"] !== "undefined" && customData["method-gtag"] !=='') { 483 gtag("config", id_gaGtag, { 484 cookie_prefix: cookie_pref, 485 cookie_domain: cookie_dom, 486 }); 487 } 488} 489 490/* HELPER */ 491function isInViewport(el) { 492 let isInViewport = 493 el.top >= 0 && 494 el.left >= 0 && 495 el.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 496 el.right <= (window.innerWidth || document.documentElement.clientWidth); 497 return isInViewport; 498}
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.