প্রচারণা

সমস্ত প্রচারাভিযান পান

function getAllCampaigns() {
  // AdsApp.campaigns() will return all campaigns that are not removed by
  // default.
  const campaignIterator = AdsApp.campaigns().get();
  console.log(`Total campaigns found : ${campaignIterator.totalNumEntities()}`);
  return campaignIterator;
}

নাম দ্বারা একটি প্রচারাভিযান পান

function getCampaignByName(name) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${name}"`)
      .get();
  if (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();
    console.log(`Campaign Name: ${campaign.getName()}`);
    console.log(`Enabled: ${campaign.isEnabled()}`);
    console.log(`Bidding strategy: ${campaign.getBiddingStrategyType()}`);
    console.log(`Ad rotation: ${campaign.getAdRotationType()}`);
    console.log(`Start date: ${formatDate(campaign.getStartDate())}`);
    console.log(`End date: ${formatDate(campaign.getEndDate())}`);
    return campaign;
  } else {
    throw new Error(`No campaign named "${name}" found`);
  }
}
function formatDate(date) {
  function zeroPad(number) { return Utilities.formatString('%02d', number); }
  return (date == null) ? 'None' : zeroPad(date.year) + zeroPad(date.month) +
      zeroPad(date.day);
}

প্রচারাভিযানের পরিসংখ্যান পান

function getCampaignStats(name) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${name}"`)
      .get();
  if (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();
    // You can also request reports for pre-defined date ranges. See
    // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_campaign#getStatsFor_1,
    // DateRangeLiteral section for possible values.
    const stats = campaign.getStatsFor('LAST_MONTH');
    console.log(`${campaign.getName()}: ${stats.getClicks()} clicks, ${stats.getImpressions()} impressions`);
    return stats;
  } else {
    throw new Error(`No campaign named "${name}" found`);
  }
}

একটি প্রচারাভিযান থামান

function pauseCampaign(name) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${name}"`)
      .get();
  if (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();
    campaign.pause();
  } else {
    throw new Error(`No campaign named "${name}" found`);
  }
}

একটি প্রচারাভিযানের ডিভাইস বিড মডিফায়ার পান

function getCampaignBidModifiers(name) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${name}"`)
      .get();
  if (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();
    console.log('Campaign name: ' + campaign.getName());

    const platforms = {};
    for (const platform of campaign.targeting().platforms()) {
      console.log(`${platform.getName()} bid modifier: ${platform.getBidModifier()}`);
      platforms[platform.getName()] = platform.getBidModifier();
    }
    return platforms;
  } else {
    throw new Error(`No campaign named "${name}" found`);
  }
}