Skip to content

Instantly share code, notes, and snippets.

@Webmasterei
Last active June 13, 2023 17:34
Show Gist options
  • Select an option

  • Save Webmasterei/5927a93cc1b4827d4e63e465f8bc46a6 to your computer and use it in GitHub Desktop.

Select an option

Save Webmasterei/5927a93cc1b4827d4e63e465f8bc46a6 to your computer and use it in GitHub Desktop.
// Hourly Updates for Google Merchant Center Main Feeds
// Fill the arrray with merchant center ids
// Set the script to "hourly"
var MCIDS = [
"123456", // mein-shop.de
];
function main() {
MCIDS.forEach(function(MCID){
var fetchedFeeds = fetchEnabledProductFeeds(MCID);
Logger.log(fetchedFeeds)
});
}
function fetchEnabledProductFeeds(merchantId) {
var fetchedFeeds = [];
var date = new Date();
var now = Utilities.formatDate(date, AdsApp.currentAccount().getTimeZone(), "yyyy MMM dd HH:mm");
try {
var productFeeds = ShoppingContent.Datafeeds.list(merchantId);
} catch(e) {
Logger.log("### ERROR Fecthing data from merchant: '"+merchantId+"' --> "+e);
fetchedFeeds.push([now, merchantId, , , "### ERROR Fecthing datafeed: "+e]);
return fetchedFeeds;
}
if (productFeeds.resources) {
for (var i = 0; i < productFeeds.resources.length; i++) {
try {
var dataFeedId = productFeeds.resources[i].id;
var response = ShoppingContent.Datafeeds.fetchnow(merchantId, dataFeedId);
fetchedFeeds.push([now, merchantId, productFeeds.resources[i].name, dataFeedId, "Fetch OK"]);
} catch(e) {
fetchedFeeds.push([now, merchantId, productFeeds.resources[i].name, dataFeedId, "### ERROR Fecthing datafeed: "+e]);
}
}
}
return fetchedFeeds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment