google ads script doesn't work

64 views
Skip to first unread message

Olga Z

unread,
Sep 23, 2022, 7:54:39 AM9/23/22
to Google Ads Scripts Forum
Hello
Our developer made me a script which should increase or decrease keywords bids according to given conditions
But the script doesn't work 
Could you please have a look and say what is wrong with it?



// Copyright 2015, Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @name Bid To Impression Share
 *
 * @overview The Bid To Impression Share script adjusts your bids and allows you
 *     to steer ads in an advertiser account into a desired impression share in
 *     the search results. See
 *     https://developers.google.com/google-ads/scripts/docs/solutions/bid-to-impression-share
 *     for more details.
 *
 * @author Google Ads Scripts Team [adwords...@googlegroups.com]
 *
 * @version 2.0.1
 *
 * @changelog
 * - version 2.0.1
 *   - Fixed logic when determining which keywords to raise and lower.
 * - version 2.0.0
 *   - Refactored to target impression share rather than position.
 * - version 1.0.1
 *   - Refactored to improve readability. Added documentation.
 * - version 1.0
 *   - Released initial version.
 */


/**
 * Main function that lowers and raises keywords' CPC to move closer to
 * target impression share.
 */
function main() {
  raiseKeywordBids();
  lowerKeywordBids();
}

/**
 * Increases the CPC of keywords that are below the target impression share.
 */
function raiseKeywordBids() {
  var keywordsToRaise = getKeywordsToRaise();

  while (keywordsToRaise.hasNext()) {
    var keyword = keywordsToRaise.next();
    keyword.bidding().setCpc(getIncreasedCpc(keyword.bidding().getCpc()));
  }
 
  keywordsToRaise = getKeywordsToRaise2();

  while (keywordsToRaise.hasNext()) {
    var keyword = keywordsToRaise.next();
    keyword.bidding().setCpc(getIncreasedCpc(keyword.bidding().getCpc(), 0.2));
  }
}

/**
 * Decreases the CPC of keywords that are above the target impression share.
 */
function lowerKeywordBids() {
  var keywordsToLower = getKeywordsToLower();

  while (keywordsToLower.hasNext()) {
    var keyword = keywordsToLower.next();
    keyword.bidding().setCpc(getDecreasedCpc(keyword.bidding().getCpc()));
  }
 
  keywordsToLower = getKeywordsToLower2();

  while (keywordsToLower.hasNext()) {
    var keyword = keywordsToLower.next();
    keyword.bidding().setCpc(getDecreasedCpc(keyword.bidding().getCpc(), 0.2));
  }
}

/**
 * Increases a given CPC using the bid adjustment coefficient.
 * @param {number} cpc - the CPC to increase
 * @return {number} the new CPC
 */
function getIncreasedCpc(cpc, cf = 0.1) {
  return cpc + cf;
}

/**
 * Decreases a given CPC using the bid adjustment coefficient.
 * @param {number} cpc - the CPC to decrease
 * @return {number} the new CPC
 */
function getDecreasedCpc(cpc, cf = 0.1) {
  return cpc - cf;
}

/**
 * Gets an iterator of the keywords that need to have their CPC raised.
 * @return {Iterator} an iterator of the keywords
 */
function getKeywordsToRaise() {
  // Condition to raise bid: Average impression share is worse (less) than
  // target - tolerance
  return AdsApp.keywords()
      .withCondition('Campaign = FR - Search - Exact - C')
      .withCondition('Cost < 2.91')
      .withCondition('Status = ENABLED')
      .withCondition('SearchImpressionShare > 0.7')
      .withCondition('SearchImpressionShare < 0.9')
      //.orderBy('SearchImpressionShare ASC')
      //.forDateRange('LAST_7_DAYS')
      .get();
}

/**
 * Gets an iterator of the keywords that need to have their CPC raised.
 * @return {Iterator} an iterator of the keywords
 */
function getKeywordsToRaise2() {
  // Condition to raise bid: Average impression share is worse (less) than
  // target - tolerance
  return AdsApp.keywords()
      .withCondition('Campaign = FR - Search - Exact - C')
      .withCondition('Cost < 2.91')
      .withCondition('Status = ENABLED')
      .withCondition('SearchImpressionShare < 0.7')
      //.orderBy('SearchImpressionShare ASC')
      //.forDateRange('LAST_7_DAYS')
      .get();
}

/**
 * Gets an iterator of the keywords that need to have their CPC lowered.
 * @return {Iterator} an iterator of the keywords
 */
function getKeywordsToLower() {
  // Conditions to lower bid: Ctr greater than 1% AND
  // average impression share better (greater) than target + tolerance
  return AdsApp.keywords()
      .withCondition('Campaign = FR - Search - Exact - C')
      .withCondition('Status = ENABLED')
      .withCondition('Cost < 0.91')
      .withCondition('SearchImpressionShare > 0.9')
      .withCondition('SearchAbsoluteTopImpressionShare > 0.5')
      .withCondition('SearchImpressionShare < 0.7')
      .withCondition('SearchTopImpressionShare > 0.9')
      //.orderBy('SearchImpressionShare DESC')
      //.forDateRange('LAST_7_DAYS')
      .get();
}

/**
 * Gets an iterator of the keywords that need to have their CPC lowered.
 * @return {Iterator} an iterator of the keywords
 */
function getKeywordsToLower2() {
  // Conditions to lower bid: Ctr greater than 1% AND
  // average impression share better (greater) than target + tolerance
  return AdsApp.keywords()
      .withCondition('Campaign = FR - Search - Exact - C')
      .withCondition('Status = ENABLED')
      .withCondition('Cost < 0.91')
      .withCondition('SearchImpressionShare > 0.9')
      .withCondition('SearchAbsoluteTopImpressionShare > 0.7')
      .withCondition('SearchTopImpressionShare > 0.9')
      //.orderBy('SearchImpressionShare DESC')
      //.forDateRange('LAST_7_DAYS')
      .get();
}

Google Ads Scripts Forum Advisor

unread,
Sep 23, 2022, 9:38:27 AM9/23/22
to adwords...@googlegroups.com
Hello,

Thanks for reaching out. Can you please privately provide us with your CID and script name in your account? Can you also please elaborate as to how it does not work?

Thanks,

Google Logo
Matt
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2efBXz:ref

Olga Z

unread,
Sep 23, 2022, 9:45:24 AM9/23/22
to Google Ads Scripts Forum on behalf of adsscripts
The google ads CID is 379-951-7339
The script name is Multi Bidder
When I run the script the result is failed

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/SeF5YDL9GvY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/D5ZbV000000000000000000000000000000000000000000000RIO0JW00qcN8r56KR0OJBvkAVg6Blw%40sfdc.net.

Olga Z

unread,
Sep 27, 2022, 3:00:01 AM9/27/22
to Google Ads Scripts Forum
Hello
Have you any updates regarding this case?
Thanks in advance

Best regards,
Olga

Reply all
Reply to author
Forward
0 new messages