Bid Adjustment Rule

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
3
Indexable
Never
// Define variables (replace with your desired values)
var CAMPAIGN_NAME_CONTAINS = ""; // Target campaigns containing this name (optional)
var CAMPAIGN_NAME_DOES_NOT_CONTAIN = ""; // Exclude campaigns containing this name (optional)

var DO_DEVICES = true; // Enable device bid adjustments
var DO_LOCATIONS = false; // Enable location bid adjustments (set to true if needed)
var DO_IN_MARKET_AUDIENCES = false; // Enable in-market audience bid adjustments (set to true if needed)
var DO_OTHER_AUDENCES = false; // Enable other audience bid adjustments (set to true if needed)

var DATE_RANGE = "LAST_7_DAYS"; // Look at data for the last 7 days (change if needed)

var MINIMUM_IMPRESSIONS = 50; // Minimum impressions for a campaign/ad group to be considered
var MINIMUM_CONVERSIONS = 1; // Minimum conversions for a campaign/ad group to be considered
var MINIMUM_COST = $10; // Minimum cost for a campaign/ad group to be considered

var MIN_BID_MODIFIER = -30; // Minimum percentage for bid adjustments (negative decreases bids)
var MAX_BID_MODIFIER = 300; // Maximum percentage for bid adjustments (positive increases bids)

// Function to get campaign object based on name
function getCampaignByName(name) {
  var campaigns = AdsApp.campaigns().withCondition('Name CONTAINS "' + name + '"').findAll();
  if (campaigns.hasNext()) {
    return campaigns.next();
  }
  return null;
}

// Function to adjust bids based on performance metrics
function adjustBids(campaign) {
  var stats = campaign.getStatsFor(DATE_RANGE);
  var impressions = stats.impressions();
  var conversions = stats.conversions();
  var cost = stats.cost();
  
  if (impressions < MINIMUM_IMPRESSIONS || conversions < MINIMUM_CONVERSIONS || cost < MINIMUM_COST) {
    return;
  }
  
  var conversionRate = conversions / impressions;
  
  // Implement your logic for bid adjustments based on conversion rate and other factors (gender, age, income, etc.)
  // Here's a basic example for mobile devices with low conversion rate
  if (DO_DEVICES && conversionRate < 0.01 && campaign.bidding().getDeviceAdjustments()[CampaignDevice.MOBILE] === 1.0) {
    campaign.bidding().setDeviceAdjustments([CampaignDevice.MOBILE], (100 + MIN_BID_MODIFIER) / 100);
  }
  
  // Add logic for other targeting options (locations, audiences) with similar structure
}

// Main function
function main() {
  var campaigns = AdsApp.campaigns()
      .withCondition(CAMPAIGN_NAME_CONTAINS !== "" ? 'Name CONTAINS "' + CAMPAIGN_NAME_CONTAINS + '"' : null)
      .withCondition(CAMPAIGN_NAME_DOES_NOT_CONTAIN !== "" ? 'Name NOT_CONTAINS "' + CAMPAIGN_NAME_DOES_NOT_CONTAIN + '"' : null)
      .findAll();
  
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    adjustBids(campaign);
  }
}

// Run the script
main();
Leave a Comment