0
Google 애드워즈 캠페인의 경우 제품 재고가 있는지 확인하는 스크립트를 사용합니다. 제품 재고가 없으면 캠핑이 일시 중지됩니다. te 스크립트를 실행 한 후 다음 오류가 발생합니다.Google 애드워즈 재고 없음 스크립트
다음 오류가 발생합니다. TypeError : null의 "indexOf"메서드를 호출 할 수 없습니다. (라인 54).
오류의 일부는 다음과 같습니다
if(STRIP_QUERY_STRING) {
if(url.indexOf('?')>=0) {
url = url.split('?')[0];
}
}
if(url.indexOf('{') >= 0) {
//Let's remove the value track parameters
url = url.replace(/\{[0-9a-zA-Z]+\}/g,'');
}
return url;
}
전체 스크립트입니다 :
/************************************
Script aan/uit advertenties
***********************************/
var URL_LEVEL = 'Ad'; // or Keyword
var ONLY_ACTIVE = false; // set to false for all ads or keywords
var CAMPAIGN_LABEL = 'automatisch'; // set this if you want to only check campaigns with this label
var STRIP_QUERY_STRING = true; // set this to false if the stuff that comes after the question mark is important
var WRAPPED_URLS = false; // set this to true if you use a 3rd party like Marin or Kenshoo for managing you account
// This is the specific text to search for
// on the page that indicates the item
// is out of stock.
var OUT_OF_STOCK_TEXT = 'adwords-niet-op-voorraad';
function main() {
var alreadyCheckedUrls = {};
var iter = buildSelector().get();
while(iter.hasNext()) {
var entity = iter.next();
var url = cleanUrl(entity.getDestinationUrl());
if(alreadyCheckedUrls[url]) {
if(alreadyCheckedUrls[url] === 'out of stock') {
entity.pause();
} else {
entity.enable();
}
} else {
var htmlCode;
try {
htmlCode = UrlFetchApp.fetch(url).getContentText();
} catch(e) {
Logger.log('There was an issue checking:'+url+', Skipping.');
continue;
}
if(htmlCode.indexOf(OUT_OF_STOCK_TEXT) >= 0) {
alreadyCheckedUrls[url] = 'out of stock';
entity.pause();
} else {
alreadyCheckedUrls[url] = 'in stock';
entity.enable();
}
}
Logger.log('Url: '+url+' is '+alreadyCheckedUrls[url]);
}
}
function cleanUrl(url) {
if(WRAPPED_URLS) {
url = url.substr(url.lastIndexOf('https'));
if(decodeURIComponent(url) !== url) {
url = decodeURIComponent(url);
}
}
if(STRIP_QUERY_STRING) {
if(url.indexOf('?')>=0) {
url = url.split('?')[0];
}
}
if(url.indexOf('{') >= 0) {
//Let's remove the value track parameters
url = url.replace(/\{[0-9a-zA-Z]+\}/g,'');
}
return url;
}
function buildSelector() {
var selector = (URL_LEVEL === 'Ad') ? AdWordsApp.ads() : AdWordsApp.keywords();
selector = selector.withCondition('CampaignStatus != DELETED').withCondition('AdGroupStatus != DELETED');
if(ONLY_ACTIVE) {
selector = selector.withCondition('CampaignStatus = ENABLED').withCondition('Status = ENABLED');
if(URL_LEVEL !== 'Ad') {
selector = selector.withCondition('AdGroupStatus = ENABLED');
}
}
if(CAMPAIGN_LABEL) {
var label = AdWordsApp.labels().withCondition("Name = '"+CAMPAIGN_LABEL+"'").get().next();
var campIter = label.campaigns().get();
var campaignNames = [];
while(campIter.hasNext()) {
campaignNames.push(campIter.next().getName());
}
selector = selector.withCondition("CampaignName IN ['"+campaignNames.join("','")+"']");
}
return selector;
}
이 솔루션에 대해 많은 감사를드립니다. 약 1 년 후 사용되지 않습니까? 그게 내가 좀 바보 같다고 느끼게 해. 운 좋게도 나는 어제 이것을 들여다 보도록 요청 받았다. 어쨌든, 고마워. 이 기능과 관련하여 Google 도서관에 대한 링크가 있습니까? 나는 좋은 것을 못 찾는다. – Tristan
예, 원본 도착 URL이 2015 년 7 월 또는 그 이전에 최종 도착 URL로 이전 된 것 같습니다. 문서는 https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_ad에서 시작하는 것이 좋습니다. – dorian