JSFiddle - React, Tailwind, and code Playground
by Luis Martin
JavaScript
$('.payment-options a')
.mousedown(
function() {
let payment_option = $('.payment-options span').find('input:checked').parent().text().trim();
let total_price = $('table.total-result').find('td').last().match(/\d+/)[0];
let num_products = $('tbody:first').find('.cart_quantity_delete').length;
let items = [];
for (let i = 0; i < num_products; i++) {
let item = {
"id": $('tbody:first').find('.cart_description p').eq(i).html().match(/\d+/)[0],
"name": $('tbody:first').find('.cart_description h4').eq(i).text(),
"brand": "E-Shopper",
"category": "Apparel/T-Shirts",
"variant": "Black",
"quantity": $('tbody:first').find('.cart_quantity input').eq(i).val(),
"price": $('tbody:first').find('.cart_total').eq(i).text().match(/\d+/)[0]
};
items.push(item)
}
console.log(items)
gtag('event', 'purchase', {
"transaction_id": "24.031608523954162",
"affiliation": "Google online store",
"value": 23.07,
"currency": "USD",
"tax": 1.24,
"shipping": 0,
"items": items
});
});