1/*! 2 * Implementação do acompanhamento de conversão do Google Adwords 3 */ 4var GoogleAdwordsConversao = (function () { 5 6 'use strict'; 7 8 // Default settings 9 var defaults = { 10 app_data: {}, 11 google_tag: 'https://www.googletagmanager.com/gtag/js?id=AW-', 12 send_to: '', 13 gtag: null, 14 currency: 'BRL', 15 defaultConversionOptions: { 16 17 } 18 }, 19 settings = {}; 20 21 /** 22 * Create the Constructor object 23 */ 24 var Constructor = function (options) { 25 settings = Object.assign({}, defaults, options); 26 27 this.init(); 28 }; 29 30 /** 31 * Set Up 32 */ 33 Constructor.prototype.init = function () { 34 35 // Concat conversion id on google tag 36 settings.google_tag += settings.app_data.google_conversion_id; 37 38 var script = document.createElement('script'); 39 script.setAttribute('async', true); 40 script.setAttribute('src', settings.google_tag); 41 document.head.appendChild(script); 42 43 window.dataLayer = window.dataLayer || []; 44 settings.gtag = function() { 45 dataLayer.push(arguments); 46 } 47 48 settings.gtag('js', new Date()); 49 settings.gtag('config', 'AW-' + settings.app_data.google_conversion_id); 50 }; 51 52 /** 53 * Set Up 54 */ 55 Constructor.prototype.getSendTo = function (convertion_id, convertion_label) { 56 return 'AW-' + convertion_id + '/' + convertion_label; 57 }; 58 59 /** 60 * Set Up 61 */ 62 Constructor.prototype.formatCurrency = function (value) { 63 value = value.replace(".",""); 64 value = value.replace(",","."); 65 return parseFloat(value); 66 }; 67 68 /** 69 * Evento de Adicionar ao Carrinho 70 */ 71 Constructor.prototype.AddCarrinho = function (options) { 72 options = Object.assign({}, settings.defaultConversionOptions, options); 73 74 var sendTo = this.getSendTo( 75 settings.app_data.google_conversion_id, 76 settings.app_data.google_conversion_label_adicionar_carrinho 77 ); 78 79 settings.gtag('event', 'conversion', { 80 'send_to': sendTo, 81 'value': this.formatCurrency(options.value), 82 'currency': settings.currency 83 }); 84 }; 85 86 /** 87 * Evento de Iniciar processo de finalização de compra 88 */ 89 Constructor.prototype.checkout = function (options) { 90 options = Object.assign({}, settings.defaultConversionOptions, options); 91 92 var sendTo = this.getSendTo( 93 settings.app_data.google_conversion_id, 94 settings.app_data.google_conversion_label_finalizacao_compra 95 ); 96 97 settings.gtag('event', 'conversion', { 98 'send_to': sendTo, 99 'value': this.formatCurrency(options.value), 100 'currency': settings.currency 101 }); 102 }; 103 104 /** 105 * Evento de COMPRA 106 */ 107 Constructor.prototype.compra = function (options) { 108 options = Object.assign({}, settings.defaultConversionOptions, options); 109 110 var sendTo = this.getSendTo( 111 settings.app_data.google_conversion_id, 112 settings.app_data.google_conversion_label_compra 113 ); 114 115 settings.gtag('event', 'conversion', { 116 'send_to': sendTo, 117 'value': options.value, 118 'currency': settings.currency, 119 'transaction_id': options.transaction_id 120 }); 121 }; 122 123 /** 124 * Return the constructor 125 */ 126 return Constructor; 127})();
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.