左侧的分配无效。 (第1行)

时间:2014-01-31 15:05:42

标签: javascript google-adwords

我正在制作一个AdWords脚本(它使用javascript)并且给了我这个错误:"Invalid assignment left-hand side. (line 1)"。我找不到错误。请帮忙?感谢

function main() {
    var todayDate = getDateString(new Date(),'H');
    Logger.log('Son las '+todayDate+' horas');
    if (todayDate = 11) {
        var spreadsheet = SpreadsheetApp.create("CPC Log "+getDateString(new Date(), 'dd-MM-yy'));
        var sheet = spreadsheet.getActiveSheet();
        var report = AdWordsApp.report("SELECT CampaignName, AdGroupName, KeywordMaxCpc FROM ADGROUP_PERFORMANCE_REPORT DURING TODAY");
        report.exportToSheet(sheet);
        var expectedRatio = 30;
        var CpcMultiplier = 1.2;
        CPCmodifier(expectedRatio,sheet,CpcMultiplier);
    }
}

如果有人需要查看它,我会添加完整的代码:

function main() {
    var todayDate = getDateString(new Date(), 'H');
    Logger.log('Son las ' + todayDate + ' horas');
    if (todayDate == 11) {
        var spreadsheet = SpreadsheetApp.create("CPC Log " + getDateString(new Date(), 'dd-MM-yy'));
        var sheet = spreadsheet.getActiveSheet();
        var report = AdWordsApp.report("SELECT CampaignName, AdGroupName, KeywordMaxCpc FROM ADGROUP_PERFORMANCE_REPORT DURING TODAY");
        report.exportToSheet(sheet);
        var expectedRatio = 30;
        var CpcMultiplier = 1.2;
        CPCmodifier(expectedRatio, sheet, CpcMultiplier);
    }
}

function getDateString(date, format) {
    return Utilities.formatDate(new Date(date), AdWordsApp.currentAccount().getTimeZone(), format);
}

function CPCmodifier(ratio, sheet, CpcMultiplier) {
    var CampaignIterator = AdWordsApp.campaigns().withCondition("Status = PAUSED").get();
    while (CampaignIterator.hasNext()) {
        var campaign = CampaignIterator.next();
        var campaignName = campaign.getName();
        var campaignBudget = campaign.getBudget();
        var campaignSpent = campaign.getStatsFor("TODAY").getCost();
        var campaignSpentRatio = (campaignSpent / campaignBudget) * 100;
        Logger.log("La campaña " + campaignName + " lleva gastados $" + campaignSpent + " sobre un presupuesto de $" + campaignBudget + ". Esto representa el " + campaignSpentRatio + "%.");
        if (campaignSpentRatio < ratio) {
            var adGroupIterator = AdWordsApp.adGroups().withCondition("Status = ENABLED").withCondition("CampaignName = '" + campaignName + "'").get();
            while (adGroupIterator.hasNext()) {
                var adGroup = adGroupIterator.next();
                var adGroupName = adGroup.getName();
                for (var row = 2; row > 1; row++) {
                    var cName = sheet.getRange("A" + row).getValue();
                    var agName = sheet.getRange("B" + row).getValue();
                    if (cName == '') break;
                    if (cName == campaignName && agName = adGroupName) {
                        var agMaxCpc = sheet.getRange("C" + row).getValue();
                        if (agMaxCpc == '--') {
                            Logger.log("El grupo de anuncios " + adGroupName + "(campaña " + campaignName + ") no tiene CPC definido. No se aplicarán modificaciones.");
                            break;
                        } else {
                            var agNewCpc = agMaxCpc * CpcMultiplier;
                            Logger.log("El CPC Máximo predeterminado del grupo de anuncios " + adGroupName + "(campaña " + campaignName + ") es de " + agMaxCpc + ". Cambiándolo a " + agNewCpc);
                            break;
                        }
                    }
                }
                adGroup.setKeywordMaxCpc(agNewCpc);
            }
        }
    }
}

解决:

我发现了这个:

 if (cName == campaignName && agName **=** adGroupName) {

应该是:

 if (cName == campaignName && agName == adGroupName) {

1 个答案:

答案 0 :(得分:2)

错字:

替换:

if (todayDate = 11) {  // That's an assignment

使用:

if (todayDate == 11) { // That's an "equals" operator