Last active
February 1, 2021 19:40
-
-
Save limata3/8e0c75f59fb087911f2edde5874f951e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def change_draft_target_cpa(original_campaign_tcpa, original_campaign_name, draft_campaign_id): | |
| # Create Portfolio for new campaign | |
| draft_target_cpa = round(original_campaign_tcpa * (1-0.30), 2) | |
| draft_portfolio_name = '{0}-Test_XYZ_Draft_Portfolio'.format(original_campaign_name) | |
| adwords_client = connect_to_adwords_api() | |
| bidding_strategy_service = adwords_client.GetService('BiddingStrategyService', version='v201809') | |
| portfolio_config = { | |
| 'name': draft_portfolio_name, | |
| 'biddingScheme': { | |
| 'xsi_type': 'TargetCpaBiddingScheme', | |
| 'targetCpa': {'microAmount': int(round(draft_target_cpa * 1000000))} | |
| } | |
| } | |
| portfolio_operator = 'ADD' | |
| portfolio = bidding_strategy_service.mutate([{ | |
| 'operator': portfolio_operator, | |
| 'operand': portfolio_config | |
| }]) | |
| portfolio_id = int(portfolio['value'][0]['id']) | |
| # Assign Portfolio to Draft | |
| campaign_service = adwords_client.GetService('CampaignService', version='v201809') | |
| campaign = { | |
| 'id': draft_campaign_id, | |
| 'biddingStrategyConfiguration': { | |
| 'biddingStrategyId': portfolio_id | |
| } | |
| } | |
| campaign_service.mutate([{ | |
| 'operator': 'SET', | |
| 'operand': campaign | |
| }]) | |
| return None | |
| # Note: draft_campaign_id was returned when running the function that creates a draft | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment