var mensagemSucesso = document.querySelector('.DialogMessage.MessagePositiveResult');
var confirmacaoCompra = document.querySelector('h1');
if (confirmacaoCompra && confirmacaoCompra.innerText.includes('Confirma')) {
gtagEcommercePurchase();
}
// Comércio Eletrônico
function gtagEcommercePurchase(){
var transaction_id = document.querySelector("body > div > div.Middle > div > div > div > div > div.InPrintViewNotVisible > p:nth-child(4)").textContent.trim().replace("O número da sua encomenda é: ", "").replace(/(\r\n|\n|\r\ \t)/gm, "").replace(/\s/g, "").replace("Imprimir", "");
var order_total = parseFloat(document.querySelector(".Total .Total").textContent.replace("€","").replace(",","."));
var items = [];
var htmlItems = document.querySelectorAll(".productBasketImage");
for (var i = 0; i < htmlItems.length; i++) {
let htmlProduct = htmlItems[i].parentNode.parentNode;
let item = { }
let produto = htmlProduct;
item.id = /[^/]*$/.exec(htmlProduct.querySelector("a").href)[0];
item.name = htmlProduct.querySelector("a").textContent;
item.quantity = parseFloat(htmlProduct.querySelector('td[data-th="Quantidade"]').textContent.split(' ')[0]);
item.price = parseFloat(htmlProduct.querySelector('td[data-th="Preço total"]').textContent.replace(",",'.').replace("€",""));
items.push(item);
}
}