Product SCHEMA – Using javascript to collect required information then sent to JSON
First you need to find the information and store it. The Required information for product SCHEMA includes:
- Page URL
- Product title
- Product Image
- Product Description
- Brand of Prodcut
- MPN
- SKU
- Aggregate rating
- Aggregate count
- Product rating
- PRoduct review
var productURL = window.location.href;
var productTitle = document.querySelector("#ProductSection > div > div > div.grid.product-single > div.grid__item.product-single__meta--wrapper.large--three-fifths > div.product-single__meta.grid__item.five-eighths > div:nth-child(1) > h1").innerText;
var productImage = document.querySelector("#ProductPhotoImg").src;
var productDescription = document.querySelector("#ProductSection > div > div > div.grid.product-single > div.grid__item.product-single__meta--wrapper.large--three-fifths > div.product-single__meta.grid__item.five-eighths > div:nth-child(2) > form > div.product-single__description").innerText;
var productBrand = document.querySelector("#vendor-id").innerText;
var mpn = document.querySelector("#mpn-sku").innerText;
var reviewName = document.querySelector("#reviewAuthor").innerText;
var productPrice = document.querySelector("#ProductPrice").innerText.slice(1);
var productReviewRating = document.getElementsByClassName("spr-starratings spr-review-header-starratings").getAttribute('arial-label').slice(0, 1);
var productAggregateRating = document.querySelector("#spr_badge_196544528397").getAttribute('data-rating');
var productAggregateCount = document.querySelector("#spr_badge_196544528397 > span.spr-badge-caption").innerText.split(' ')[0];
var SendJSON = {
'Product Url': productURL,
'Product Title': productTitle,
'Product Image': productImage,
'Product Description': productDescription,
'Product Brand': productBrand,
'MPN': mpn,
'Review Name': reviewName,
'Product Price': productPrice,
'Product Review Rating': productReviewRating,
'Product Aggregate Rating': productAggregateRating,
'Product Aggregate Count': productAggregateCount
};
var myJSON = JSON.stringify(SendJSON);
document.getElementById("tabs-information").innerHTML = myJSON;