I'm trying to scrape information that is within a script tag on a webpage. I've figured out how to get at the information, but I can't figure out how to manipulate it into a data object.
I'm able to get at the information using document.querySelector(x).innerHTML. Here is the innerHTML that appears (the first part doesn't seem to be formatting as code here).
" Y = YUI(YUI_CONFIG).use( 'squarespace-commerce-analytics',
function(Y) {
Y.on('domready', function() {
Y.Squarespace.CommerceAnalytics.checkoutConfirmed({'id':'12345676','orderNumber':'00065','websiteId':'12345678','purchasedCartId':'1234567','testMode':true,'grandTotal':{'currencyCode':'USD','value':3239,'decimalValue':'32.39','fractionalDigits':2},'grandTotalFormatted':'$32.39','subtotal':{'currencyCode':'USD','value':2300,'decimalValue':'23.00','fractionalDigits':2},'subtotalFormatted':'$23.00','taxTotal':{'currencyCode':'USD','value':204,'decimalValue':'2.04','fractionalDigits':2},'taxTotalFormatted':'$2.04','shippingTotal':{'currencyCode':'USD','value':735,'decimalValue':'7.35','fractionalDigits':2},'shippingTotalFormatted':'$7.35','billingDetails':{'customer':{'address':{'city':'New York','region':'NY','country':'United States'}}},'items':[{'sku':'123456','productName':'This is a Product','unitPrice':{'currencyCode':'USD','value':2300,'decimalValue':'23.00','fractionalDigits':2},'quantity':1}]});
});
});
"
This code shows the innerHTML that I'm getting, and I want each of the data items (id, orderNumber, productName etc.) to be formatted into an object so that I can track ecommerce better using GTM. I'm not sure how to manipulate it in a way that I need