Clearing keywords with the «Low search volume» status using the script

The popularity of key phrases may decrease, and in this case, previously added phrases get the status «Low search volume». Here Google writes about this in more detail — https://support.google.com/google-ads/answer/2616014.

In order not to be distracted by their maintenance, you need to delete them. I wrote a script that does this automatically:

function main() {
    var key_ids_arr = [];
    // Select keywords with the status "Low search volume", active, in active groups
    // in active campaigns, with 0 impressions in the last 30 days
    var search = 'SELECT ad_group_criterion.criterion_id, ad_group.id ' +
        'FROM keyword_view ' +
        'WHERE ad_group_criterion.system_serving_status = "RARELY_SERVED" ' +
        'AND ad_group_criterion.approval_status = "APPROVED" ' +
        'AND ad_group_criterion.status = "ENABLED" ' +
        'AND ad_group.status = "ENABLED" ' +
        'AND campaign.status = "ENABLED" ' +
        'AND metrics.impressions = 0 ' +
        'AND segments.date ' +
        'DURING LAST_30_DAYS LIMIT 50000';
    var report = AdsApp.search(search, {
        apiVersion: 'v8'
    });
    while (report.hasNext()) {
        var row = report.next();
        var key_id = row.adGroupCriterion.criterionId,
            ad_group_id = row.adGroup.id;
        // collecting their IDs
        key_ids_arr.push([
            ad_group_id,
            key_id
        ]);
    }
    if (key_ids_arr.length > +0) {
        var keywordsIterator = AdsApp.keywords()
            .withIds(key_ids_arr)
            .get();
        while (keywordsIterator.hasNext()) {
            var keyword = keywordsIterator.next();
            // delete
            keyword.remove();
        }
    }
}

Добавить комментарий