Creates a dynamic remarketing campaign.

  Args:
    client: an AdWordsClient instance.
    campaign_id: an int campaign ID.

  Returns:
    The ad group that was successfully created.
188729
def CreateAdGroup(client, campaign_id):
  
  ad_group_service = client.GetService('AdGroupService', 'v201809')

  ad_group = {
      'name': 'Dynamic remarketing ad group',
      'campaignId': campaign_id,
      'status': 'ENABLED'
  }

  operations = [{
      'operator': 'ADD',
      'operand': ad_group
  }]

  return ad_group_service.mutate(operations)['value'][0]
1331480
def new_email_marketing_campaign(self, name, email_content, from_email,
                                     from_name, reply_to_email, subject,
                                     text_content, address,
                                     is_view_as_webpage_enabled=False,
                                     view_as_web_page_link_text='',
                                     view_as_web_page_text='',
                                     is_permission_reminder_enabled=False,
                                     permission_reminder_text=''):
        
        url = self.api.join(self.EMAIL_MARKETING_CAMPAIGN_URL)

        inlined_email_content = self.inline_css(email_content)
        minified_email_content = html_minify(inlined_email_content)
        worked_around_email_content = work_around(minified_email_content)

        data = {
            'name': name,
            'subject': subject,
            'from_name': from_name,
            'from_email': from_email,
            'reply_to_email': reply_to_email,
            'email_content': worked_around_email_content,
            'email_content_format': 'HTML',
            'text_content': text_content,
            'message_footer': {
                'organization_name': address['organization_name'],
                'address_line_1': address['address_line_1'],
                'address_line_2': address['address_line_2'],
                'address_line_3': address['address_line_3'],
                'city': address['city'],
                'state': address['state'],
                'international_state': address['international_state'],
                'postal_code': address['postal_code'],
                'country': address['country']
            },
            'is_view_as_webpage_enabled': is_view_as_webpage_enabled,
            'view_as_web_page_link_text': view_as_web_page_link_text,
            'view_as_web_page_text': view_as_web_page_text,
            'is_permission_reminder_enabled': is_permission_reminder_enabled,
            'permission_reminder_text': permission_reminder_text
        }

        response = url.post(data=json.dumps(data),
                            headers={'content-type': 'application/json'})

        self.handle_response_status(response)

        return EmailMarketingCampaign.objects.create(data=response.json())
1264662
private static AdGroupAd createShowcaseAd(
      AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup)
      throws IOException {
    // Create the Showcase ad.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);
    ShowcaseAd showcaseAd = new ShowcaseAd();
    showcaseAd.setName("Showcase ad #" + System.currentTimeMillis());
    showcaseAd.setFinalUrls(new String[] {"http://example.com/showcase"});
    showcaseAd.setDisplayUrl("example.com");

    // Required: Set the ad's expanded image.
    Image expandedImage = new Image();
    expandedImage.setMediaId(uploadImage(adWordsServices, session, "https://goo.gl/IfVlpF"));
    showcaseAd.setExpandedImage(expandedImage);

    // Optional: Set the collapsed image.
    Image collapsedImage = new Image();
    collapsedImage.setMediaId(uploadImage(adWordsServices, session, "https://goo.gl/NqTxAE"));
    showcaseAd.setCollapsedImage(collapsedImage);

    // Create ad group ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroup.getId());
    adGroupAd.setAd(showcaseAd);

    // Create operation.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
    adGroupAdOperation.setOperand(adGroupAd);
    adGroupAdOperation.setOperator(Operator.ADD);

    // Make the mutate request.
    AdGroupAdReturnValue adGroupAdAddResult =
        adGroupAdService.mutate(new AdGroupAdOperation[] {adGroupAdOperation});

    return adGroupAdAddResult.getValue(0);
  }
717561
def CreateBiddingStrategy(client):
  
  # Initialize appropriate service.
  bidding_strategy_service = client.GetService(
      'BiddingStrategyService', version='v201809')

  # Create a shared bidding strategy.
  shared_bidding_strategy = {
      'name': 'Maximize Clicks %s' % uuid.uuid4(),
      'biddingScheme': {
          'xsi_type': 'TargetSpendBiddingScheme',
          # Optionally set additional bidding scheme parameters.
          'bidCeiling': {
              'microAmount': '2000000'
          }
      }
  }

  # Create operation.
  operation = {
      'operator': 'ADD',
      'operand': shared_bidding_strategy
  }

  response = bidding_strategy_service.mutate([operation])
  new_bidding_strategy = response['value'][0]

  print ('Shared bidding strategy with name "%s" and ID "%s" of type "%s"'
         'was created.' %
         (new_bidding_strategy['name'], new_bidding_strategy['id'],
          new_bidding_strategy['biddingScheme']['BiddingScheme.Type']))

  return new_bidding_strategy
995703
def add(self, campaign_id, item_id, default_price, title, img_url, nick=None):
        ''''''
        request = TOPRequest('xxxxx.xxxxx.adgroup.add')
        request['campaign_id'] = campaign_id
        request['item_id'] = item_id
        request['default_price'] = default_price
        request['title'] = title
        request['img_url'] = img_url
        if nick!=None: request['nick'] = nick
        self.create(self.execute(request), fields=['success','result','success','result_code','result_message'], models={'result':ADGroup})
        return self.result
616875
public function reportBrowserInfo($campaign_id, $by_subscriber=0, $os_name, $browser, $client_type)
		{
			$form_data = array(
				'campaign_id' => $campaign_id,
				'by_subscriber' => $by_subscriber,
				'os_name' => $os_name,
				'browser' => $browser,
				'client_type' => $client_type
			);
			$xml = $this->call('rpt_browser_info', $form_data);

			return $xml;
		}
513576
def get(self, page_size, page_no=1, campaign_id=None, adgroup_ids=None, nick=None):
        ''''''
        request = TOPRequest('xxxxx.xxxxx.adgroups.get')
        request['page_size'] = page_size
        request['page_no'] = page_no
        if campaign_id!=None: request['campaign_id'] = campaign_id
        if adgroup_ids!=None: request['adgroup_ids'] = adgroup_ids
        if nick!=None: request['nick'] = nick
        self.create(self.execute(request), models = {'result':ADGroup})
        return self.result
2314
private static function createAdGroup(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        Campaign $campaign
    ) {
        $adGroupService = $adWordsServices->get($session, AdGroupService::class);

        // Create ad group.
        $adGroup = new AdGroup();
        $adGroup->setCampaignId($campaign->getId());
        $adGroup->setName('Ad Group #' . uniqid());

        // Required: Set the ad group type to SHOPPING_SHOWCASE_ADS.
        $adGroup->setAdGroupType(AdGroupType::SHOPPING_SHOWCASE_ADS);

        // Required: Set the ad group's bidding strategy configuration.
        // Note: Showcase ads require that the campaign has a ManualCpc
        // BiddingStrategyConfiguration.
        $biddingStrategyConfiguration = new BiddingStrategyConfiguration();

        // Optional: Set the bids.
        $bidAmount = new Money();
        $bidAmount->setMicroAmount(100000);
        $cpcBid = new CpcBid();
        $cpcBid->setBid($bidAmount);
        $biddingStrategyConfiguration->setBids([$cpcBid]);

        $adGroup->setBiddingStrategyConfiguration($biddingStrategyConfiguration);

        // Create operation.
        $adGroupOperation = new AdGroupOperation();
        $adGroupOperation->setOperand($adGroup);
        $adGroupOperation->setOperator(Operator::ADD);

        // Make the mutate request.
        $adGroupAddResult = $adGroupService->mutate([$adGroupOperation]);
        $adGroup = $adGroupAddResult->getValue()[0];

        return $adGroup;
    }
505988
def _AddWebPageCriteria(client, ad_group_id):
  
  ad_group_criterion_service = client.GetService('AdGroupCriterionService',
                                                 version='v201809')

  operations = [{
      'operator': 'ADD',
      # Create biddable ad group criterion.
      'operand': {
          'xsi_type': 'BiddableAdGroupCriterion',
          'adGroupId': ad_group_id,
          # Create a webpage criterion for special offers for children.
          'criterion': {
              'xsi_type': 'Webpage',
              'parameter': {
                  'criterionName': 'Special offers for children.',
                  'conditions': [
                      {
                          'operand': 'URL',
                          'argument': '/marscruise/children'
                      },
                      {
                          'operand': 'PAGE_TITLE',
                          'argument': 'Special Offer'
                      }
                  ]
              }
          },
          'userStatus': 'PAUSED',
          # Optional: set a custom bid.
          'biddingStrategyConfiguration': {
              'bids': [{
                  'xsi_type': 'CpcBid',
                  'bid': {
                      'microAmount': 10000000L
                  }
              }]
          }
      }
  }]

  criterion = ad_group_criterion_service.mutate(operations)['value'][0]

  print 'Webpage criterion with ID "%d" was added to ad group ID "%d".' % (
      criterion['criterion']['id'], criterion['adGroupId'])
106699
def create_ad_product_feed(name:, schedule:)
      query = { name: name, schedule: schedule }
      result = AdProductCatalog.post("/#{id}/product_feeds", query: query)
      AdProductFeed.find(result['id'])
    end
30861
def CreateSmartShoppingAd(client, ad_group_id):
  
  ad_group_ad_service = client.GetService('AdGroupAdService', version='v201809')
  # Create an AdGroup Ad.
  adgroup_ad = {
      'adGroupId': ad_group_id,
      # Create a Smart Shopping ad (Goal-optimized Shopping ad).
      'ad': {
          'xsi_type': 'GoalOptimizedShoppingAd'
      }
  }

  ad_operation = {
      'operator': 'ADD',
      'operand': adgroup_ad
  }

  # Make the mutate request to add the Smart Shopping ad to the AdGroup.
  ad_result = ad_group_ad_service.mutate([ad_operation])

  for adgroup_ad in ad_result['value']:
    print 'Smart Shopping ad with ID "%s" was added.' % adgroup_ad['ad']['id']
400577
def update(self, adgroup_id, default_price, nonsearch_max_price, is_nonsearch_default_price, online_status, campaign_id, nick=None):
        ''''''
        request = TOPRequest('xxxxx.xxxxx.adgroup.update')
        request['adgroup_id'] = adgroup_id
        request['default_price'] = default_price
        request['nonsearch_max_price'] = nonsearch_max_price
        request['is_nonsearch_default_price'] = is_nonsearch_default_price
        request['online_status'] = online_status
        request['campaign_id'] = campaign_id
        if nick!=None: request['nick'] = nick
        self.create(self.execute(request), fields=['success','result','success','result_code','result_message'], models={'result':ADGroup})
        return self.result
874488
def CreateSmartShoppingAdGroup(client, campaign_id):
  
  ad_group_service = client.GetService('AdGroupService', version='v201809')
  # Create the ad group.
  ad_group = {
      'campaignId': campaign_id,
      'name': 'Smart Shopping ad group #%s' % uuid.uuid4(),
      # Set the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
      'adGroupType': 'SHOPPING_GOAL_OPTIMIZED_ADS'
  }

  adgroup_operations = {
      'operator': 'ADD',
      'operand': ad_group
  }

  # Make the mutate request to add the AdGroup to the Smart Shopping campaign.
  ad_group = ad_group_service.mutate(adgroup_operations)['value'][0]
  ad_group_id = ad_group['id']

  print ('AdGroup with name "%s" and ID "%s" was added.'
         % (ad_group['name'], ad_group_id))

  return ad_group_id
625278
private static void createAdsWithCustomizations(AdWordsServicesInterface adWordsServices,
      AdWordsSession session, List<Long> adGroupIds, String feedName) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    ExpandedTextAd textAd = new ExpandedTextAd();
    textAd.setHeadlinePart1(String.format("Luxury Cruise to {=%s.Name}", feedName));
    textAd.setHeadlinePart2(String.format("Only {=%s.Price}", feedName));
    textAd.setDescription(String.format("Offer ends in {=countdown(%s.Date)}!", feedName));
    textAd.setFinalUrls(new String[] {"http://www.example.com"});

    // We add the same ad to both ad groups. When they serve, they will show different values, since
    // they match different feed items.
    List<AdGroupAdOperation> adGroupAdOperations = new ArrayList<>();
    for (Long adGroupId : adGroupIds) {
      AdGroupAd adGroupAd = new AdGroupAd();
      adGroupAd.setAdGroupId(adGroupId);
      adGroupAd.setAd(textAd);

      AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
      adGroupAdOperation.setOperand(adGroupAd);
      adGroupAdOperation.setOperator(Operator.ADD);

      adGroupAdOperations.add(adGroupAdOperation);
    }

    AdGroupAdReturnValue adGroupAdReturnValue = adGroupAdService.mutate(
        adGroupAdOperations.toArray(new AdGroupAdOperation[adGroupAdOperations.size()]));

    for (AdGroupAd addedAd : adGroupAdReturnValue.getValue()) {
      System.out.printf("Created an ad with ID %d, type '%s' and status '%s'.%n",
          addedAd.getAd().getId(), addedAd.getAd().getAdType(), addedAd.getStatus());
    }
  }
1372377
def _AddCampaignsToGroup(client, campaign_group_id, campaign_ids):
  
  # Get the CampaignService.
  campaign_service = client.GetService('CampaignService', version='v201809')

  # Create the operations.
  operations = [{
      'operator': 'SET',
      'operand': {
          'id': campaign_id,
          'campaignGroupId': campaign_group_id
      }
  } for campaign_id in campaign_ids]

  campaign_service.mutate(operations)

  # Display the results.
  print ('The following campaign IDs were added to the campaign group with ID '
         '"%d":\n\t%s' % (campaign_group_id, campaign_ids))
242935
def _CreateFeedItems(client, feed_details, label_name):
  
  # Get the FeedItemService.
  feed_item_service = client.GetService('FeedItemService', version='v201809')

  # For page feed URL recommendations and rules, see:
  # https://support.google.com/adwords/answer/7166527
  urls = ('http://www.example.com/discounts/rental-cars?id={feeditem}',
          'http://www.example.com/discounts/hotel-deals?id={feeditem}',
          'http://www.example.com/discounts/flight-deals?id={feeditem}')

  # Create the operation.
  operations = [{
      # Create the feed item.
      'operand': {
          'feedId': feed_details.feed_id,
          'attributeValues': [
              {
                  'feedAttributeId': feed_details.url_attribute_id,
                  'stringValues': [url]
              },
              {
                  'feedAttributeId': feed_details.label_attribute_id,
                  'stringValues': [label_name]
              }
          ]
      },
      'operator': 'ADD'
  } for url in urls]

  # Add the feed item.
  feed_item_service.mutate(operations)
894901
private static function createCampaign(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        Budget $budget
    ) {
        $campaignService = $adWordsServices->get($session, CampaignService::class);

        // Create campaign with some properties set.
        $campaign = new Campaign();
        $campaign->setName('Interplanetary Cruise #' . uniqid());
        $campaign->setAdvertisingChannelType(AdvertisingChannelType::SEARCH);

        // Recommendation: Set the campaign to PAUSED when creating it to prevent
        // the ads from immediately serving. Set to ENABLED once you've added
        // targeting and the ads are ready to serve.
        $campaign->setStatus(CampaignStatus::PAUSED);

        $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        $biddingStrategyConfiguration->setBiddingStrategyType(
            BiddingStrategyType::MANUAL_CPC
        );
        $campaign->setBiddingStrategyConfiguration($biddingStrategyConfiguration);

        // Only the budgetId should be sent, all other fields will be ignored by
        // CampaignService.
        $campaignBudget = new Budget();
        $campaignBudget->setBudgetId($budget->getBudgetId());
        $campaign->setBudget($campaignBudget);

        // Required: Set the campaign's Dynamic Search Ads settings.
        $dynamicSearchAdsSetting = new DynamicSearchAdsSetting();
        // Required: Set the domain name and language.
        $dynamicSearchAdsSetting->setDomainName('example.com');
        $dynamicSearchAdsSetting->setLanguageCode('en');

        // Set the campaign settings.
        $campaign->setSettings([$dynamicSearchAdsSetting]);

        // Optional: Set the start date.
        $campaign->setStartDate(date('Ymd', strtotime('+1 day')));
        // Optional: Set the end date.
        $campaign->setEndDate(date('Ymd', strtotime('+1 year')));

        // Create a campaign operation.
        $operation = new CampaignOperation();
        $operation->setOperand($campaign);
        $operation->setOperator(Operator::ADD);

        // Create the campaign on the server and print out some information.
        $result = $campaignService->mutate([$operation]);
        $campaign = $result->getValue()[0];
        printf(
            "Campaign with name '%s' and ID %d was added.\n",
            $campaign->getName(),
            $campaign->getId()
        );

        return $campaign;
    }