var products = ShoppingContent.Productstatuses.list(merchantId, {
pageToken: pageToken,
maxResults: maxResults
});
if(products.resources){
for(var i = 0; i < products.resources.length; i++){
if(products.resources[i].itemLevelIssues){
++issuesData.numberOfIssues
var theIssue = products.resources[i].itemLevelIssues[0].description;
if(!issuesData[theIssue]){
issuesData[theIssue] = 1;
}else{
++issuesData[theIssue];
}
}
}
}
pageToken = products.nextPageToken;
pageNum++;
}while(pageToken);
return issuesData;
}
functionvalidateEmail(email){
var key = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(key.test(email) === false){
thrownewError('You must eneter a valid email address to run the script.');
}
}
functionvalidateMerchantID(theID){
if(isNaN(theID)){
thrownewError('You must eneter a valid Merchant Center ID to run the script.');
}
}
functionsendEmails(data, numberOfIssues){
if(data[0]){
MailApp.sendEmail(EMAIL.join(','), 'Total number of issues in your Merchant Center account: ' + numberOfIssues,
'Hi, \n\nPlease, see the list of issues: \n\n' + data.join("\n"));
}
}
/*
Copyright 2020 Krzysztof Bycina, www.LiveAds.pl
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// --------------------------------------- Configuration:
var EMAIL = ['ENTER YOUR EMAIL ID HERE'];
var MERCHANT_ID = 'ENTER YOUR MERCHANT ID HERE';
// --------------------------------------- End of the configuration
function main() {
validateEmail(EMAIL);
validateMerchantID(MERCHANT_ID);
var emailData = [];
var allIssues = countIssues(MERCHANT_ID);
Logger.log("Total issues found: " + allIssues.numberOfIssues);
//Move the data to an array:
for (var key in allIssues) {
if (key !== "numberOfIssues") {
Logger.log(key + ": " + allIssues[key]);
emailData.push([key + ":", allIssues[key]]);
}
}
//Sort in descending Order
emailData.sort(function(a, b) {
return b[1] - a[1];
});
//Prepare the data for the email
emailData.forEach(function(issue, index){
emailData[index] = issue.join(" ");
});
sendEmails(emailData, allIssues.numberOfIssues);
}
function countIssues(merchantId) {
var issuesData = {
numberOfIssues: 0
};
var pageToken;
var pageNum = 1;
var maxResults = 250;
do {
var products = ShoppingContent.Productstatuses.list(merchantId, {
pageToken: pageToken,
maxResults: maxResults
});
if (products.resources) {
for (var i = 0; i < products.resources.length; i++) {
if (products.resources[i].itemLevelIssues) {
++issuesData.numberOfIssues
var theIssue = products.resources[i].itemLevelIssues[0].description;
if (!issuesData[theIssue]) {
issuesData[theIssue] = 1;
} else {
++issuesData[theIssue];
}
}
}
}
pageToken = products.nextPageToken;
pageNum++;
} while (pageToken);
return issuesData;
}
function validateEmail(email) {
var key = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (key.test(email) === false) {
throw new Error('You must eneter a valid email address to run the script.');
}
}
function validateMerchantID(theID) {
if (isNaN(theID)) {
throw new Error('You must eneter a valid Merchant Center ID to run the script.');
}
}
function sendEmails(data, numberOfIssues) {
if (data[0]) {
MailApp.sendEmail(EMAIL.join(','), 'Total number of issues in your Merchant Center account: ' + numberOfIssues,
'Hi, \n\nPlease, see the list of issues: \n\n' + data.join("\n"));
}
}
/*
Copyright 2020 Krzysztof Bycina, www.LiveAds.pl
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// --------------------------------------- Configuration:
var EMAIL = ['ENTER YOUR EMAIL ID HERE'];
var MERCHANT_ID = 'ENTER YOUR MERCHANT ID HERE';
// --------------------------------------- End of the configuration
function main() {
validateEmail(EMAIL);
validateMerchantID(MERCHANT_ID);
var emailData = [];
var allIssues = countIssues(MERCHANT_ID);
Logger.log("Total issues found: " + allIssues.numberOfIssues);
//Move the data to an array:
for (var key in allIssues) {
if (key !== "numberOfIssues") {
Logger.log(key + ": " + allIssues[key]);
emailData.push([key + ":", allIssues[key]]);
}
}
//Sort in descending Order
emailData.sort(function(a, b) {
return b[1] - a[1];
});
//Prepare the data for the email
emailData.forEach(function(issue, index){
emailData[index] = issue.join(" ");
});
sendEmails(emailData, allIssues.numberOfIssues);
}
function countIssues(merchantId) {
var issuesData = {
numberOfIssues: 0
};
var pageToken;
var pageNum = 1;
var maxResults = 250;
do {
var products = ShoppingContent.Productstatuses.list(merchantId, {
pageToken: pageToken,
maxResults: maxResults
});
if (products.resources) {
for (var i = 0; i < products.resources.length; i++) {
if (products.resources[i].itemLevelIssues) {
++issuesData.numberOfIssues
var theIssue = products.resources[i].itemLevelIssues[0].description;
if (!issuesData[theIssue]) {
issuesData[theIssue] = 1;
} else {
++issuesData[theIssue];
}
}
}
}
pageToken = products.nextPageToken;
pageNum++;
} while (pageToken);
return issuesData;
}
function validateEmail(email) {
var key = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (key.test(email) === false) {
throw new Error('You must eneter a valid email address to run the script.');
}
}
function validateMerchantID(theID) {
if (isNaN(theID)) {
throw new Error('You must eneter a valid Merchant Center ID to run the script.');
}
}
function sendEmails(data, numberOfIssues) {
if (data[0]) {
MailApp.sendEmail(EMAIL.join(','), 'Total number of issues in your Merchant Center account: ' + numberOfIssues,
'Hi, \n\nPlease, see the list of issues: \n\n' + data.join("\n"));
}
}
Bardzo przydatny wpis. Przetestujemy na naszych e-commerce.
Również na pewno będę chciał to przetestować dla e-commerce które prowadzę. Wpis naprawdę bardzo przydatny.