0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AdWords Scripts - Spreadsheetと連携し、AdParam設定をKWレベルで広告グループ毎に発行するスクリプト

Last updated at Posted at 2015-03-25

商品の値付けが変動するようなものに対して、予めセットしておいた商品値付け一覧が登録されているSpreadsheetを自動参照し、AdParamを発行する。
多少の変更は必要だけど、基本Spreadsheetのリンクと対象キャンペーンさえ変えれば動作OK。
※以下のサイトを参考にしたが、対象キャンペーンを絞るのは大規模アカウントの場合、パフォーマンス面で差が出ることがわかったため
http://www.freeadwordsscripts.com/2013/01/update-ad-params-from-google-spreadsheet.html

var SPREADSHEET_URL = "https://docs.google.com/spreadsheet/ccc?key=hoge";
var SET_PARAM1 = true;
var DATA_RANGE = 'A:D'; // A - IDなど, B - CampaignName, C - AdGroupName, D - Param1
function main() {
    var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
    var allSheets = spreadsheet.getSheets();
    var allData = [];
    for (var i in allSheets) {
        var sheet = allSheets[i];
        var data = sheet.getRange(DATA_RANGE).getValues();
        data.shift();
        allData = allData.concat(data);
    }
    var allDataHash = {};
    for (var i in allData) {
        var row = allData[i];
        if (row[0] === '') {
            continue;
        }
        var rowKey = [row[1], row[2]].join('~~!~~');
        allDataHash[rowKey] = {
            param1: row[3]
        };
    }
    var kwIter = AdWordsApp.keywords().withCondition(
            "CampaignName = 'fuga'")
        //.withCondition('CampaignStatus = ENABLED')
        //.withCondition('AdGroupStatus = ENABLED')
        //.withCondition('Status = ENABLED')
        .get();
    while (kwIter.hasNext()) {
        var kw = kwIter.next();
        var campName = kw.getCampaign().getName();
        var adGroupName = kw.getAdGroup().getName();
        var rowKey = [campName, adGroupName].join('~~!~~');
        if (allDataHash[rowKey]) {
            if (SET_PARAM1) {
                kw.setAdParam(1, allDataHash[rowKey].param1);
            }
        }
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?